Debian Codegraph @

internal/integration/tests/checkers.go

raw symbols SCIP
1 package testsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/
2
3 import (
4 "encoding/jsonscip-go gomod github.com/golang/go/src go1.14 `encoding/json`/"
5 "fmtscip-go gomod github.com/golang/go/src go1.14 fmt/"
6
7 testscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/ "gopkg.in/check.v1scip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/"
8
9 "gopkg.in/rethinkdb/rethinkdb-go.v6/typesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/"
10 )
11
12 type jsonCheckerscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/jsonChecker# struct {
13 *testscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/.CheckerInfoscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/jsonChecker#CheckerInfo.
14 }
15
16 func (j jsonCheckerscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/jsonChecker#) Checkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/jsonChecker#Check().(params []interface{}, names []string) (result bool, error string) {
17 var jsonParams []interface{}
18 for _, param := range params {
19 jsonParam, err := jsonscip-go gomod github.com/golang/go/src go1.14 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.14 `encoding/json`/Marshal().(param)
20 if err != nil {
21 return false, err.Error()
22 }
23 jsonParams = append(jsonParams, jsonParam)
24 }
25 return testscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/.DeepEqualsscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/DeepEquals..Checkscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/Checker#Check().(jsonParams, names)
26 }
27
28 // JsonEquals compares two interface{} objects by converting them to JSON and
29 // seeing if the strings match
30 var JsonEqualsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/JsonEquals. = &jsonCheckerscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/jsonChecker#{
31 &testscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/.CheckerInfoscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/CheckerInfo#{Namescip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/CheckerInfo#Name.: "JsonEquals", Paramsscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/CheckerInfo#Params.: []string{"obtained", "expected"}},
32 }
33
34 type geometryCheckerscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/geometryChecker# struct {
35 *testscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/.CheckerInfoscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/geometryChecker#CheckerInfo.
36 }
37
38 func (j geometryCheckerscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/geometryChecker#) Checkscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/geometryChecker#Check().(params []interface{}, names []string) (result bool, error string) {
39 obtained, ok := params[0].(typesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/.Geometryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#)
40 if !ok {
41 return false, "obtained must be a Geometry"
42 }
43 expectedType, ok := params[1].(string)
44 if !ok {
45 return false, "expectedType must be a string"
46 }
47
48 switch expectedType {
49 case "Polygon":
50 expectedCoords, ok := params[2].([][][]float64)
51 if !ok {
52 return false, "expectedCoords must be a [][][]float64"
53 }
54
55 return comparePolygonscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/comparePolygon().(expectedCoords, obtained)
56 case "LineString":
57 expectedCoords, ok := params[2].([][]float64)
58 if !ok {
59 return false, "expectedCoords must be a [][]float64"
60 }
61
62 return compareLineStringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/compareLineString().(expectedCoords, obtained)
63 case "Point":
64 expectedCoords, ok := params[2].([]float64)
65 if !ok {
66 return false, "expectedCoords must be a []float64"
67 }
68
69 return comparePointscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/comparePoint().(expectedCoords, obtained)
70 default:
71 return false, "unknown expectedType"
72 }
73 }
74
75 // geometryEquals compares two geometry values, all coordinates are compared with a small amount of tolerance
76 var geometryEqualsscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/geometryEquals. = &geometryCheckerscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/geometryChecker#{
77 &testscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/.CheckerInfoscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/CheckerInfo#{Namescip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/CheckerInfo#Name.: "geometryEquals", Paramsscip-go gomod gopkg.in/check.v1 8fa46927fb4f `gopkg.in/check.v1`/CheckerInfo#Params.: []string{"obtained", "expectedType", "expectedCoords"}},
78 }
79
80 /* BEGIN FLOAT HELPERS */
81
82 // totally ripped off from math/all_test.go
83 // https://github.com/golang/go/blob/master/src/math/all_test.go#L1723-L1749
84 func tolerancescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/tolerance().(a, b, e float64) bool {
85 d := a - b
86 if d < 0 {
87 d = -d
88
89 }
90
91 if a != 0 {
92 e = e * a
93 if e < 0 {
94 e = -e
95
96 }
97
98 }
99 return d < e
100 }
101
102 func mehclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/mehclose().(a, b float64) bool { return tolerancescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/tolerance().(a, b, 1e-2) }
103 func kindaclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/kindaclose().(a, b float64) bool { return tolerancescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/tolerance().(a, b, 1e-8) }
104 func prettyclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/prettyclose().(a, b float64) bool { return tolerancescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/tolerance().(a, b, 1e-14) }
105 func veryclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/veryclose().(a, b float64) bool { return tolerancescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/tolerance().(a, b, 4e-16) }
106 func soclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/soclose().(a, b, e float64) bool { return tolerancescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/tolerance().(a, b, e) }
107
108 func comparePolygonscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/comparePolygon().(expected [][][]float64, obtained typesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/.Geometryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#) (result bool, error string) {
109 if obtained.Typescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Type. != "Polygon" {
110 return false, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("obtained geometry has incorrect type, has %s but expected Polygon", obtained.Typescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Type.)
111 }
112
113 for i, line := range obtained.Linesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Lines. {
114 for j, point := range line {
115 ok, err := assertPointsEqualscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/assertPointsEqual().(
116 expected[i][j][0], point.Lonscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Point#Lon., // Lon
117 expected[i][j][1], point.Latscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Point#Lat., // Lat
118 )
119 if !ok {
120 return false, err
121 }
122 }
123 }
124
125 return true, ""
126 }
127
128 func compareLineStringscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/compareLineString().(expected [][]float64, obtained typesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/.Geometryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#) (result bool, error string) {
129 if obtained.Typescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Type. != "LineString" {
130 return false, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("obtained geometry has incorrect type, has %s but expected LineString", obtained.Typescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Type.)
131 }
132
133 for j, point := range obtained.Linescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Line. {
134 ok, err := assertPointsEqualscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/assertPointsEqual().(
135 expected[j][0], point.Lonscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Point#Lon., // Lon
136 expected[j][1], point.Latscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Point#Lat., // Lat
137 )
138 if !ok {
139 return false, err
140 }
141 }
142
143 return true, ""
144 }
145
146 func comparePointscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/comparePoint().(expected []float64, obtained typesscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/.Geometryscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#) (result bool, error string) {
147 if obtained.Typescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Type. != "Point" {
148 return false, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("obtained geometry has incorrect type, has %s but expected Point", obtained.Typescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Type.)
149 }
150
151 return assertPointsEqualscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/assertPointsEqual().(
152 expected[0], obtained.Pointscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Point..Lonscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Point#Lon., // Lon
153 expected[1], obtained.Pointscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Geometry#Point..Latscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/types`/Point#Lat., // Lat
154 )
155 }
156
157 func assertPointsEqualscip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/assertPointsEqual().(expectedLon, obtainedLon, expectedLat, obtainedLat float64) (result bool, error string) {
158 if !kindaclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/kindaclose().(expectedLon, obtainedLon) {
159 return false, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("the deviation between the compared floats is too great [%v:%v]", expectedLon, obtainedLon)
160 }
161 if !kindaclosescip-go gomod gopkg.in/rethinkdb/rethinkdb-go.v6 . `gopkg.in/rethinkdb/rethinkdb-go.v6/internal/integration/tests`/kindaclose().(expectedLat, obtainedLat) {
162 return false, fmtscip-go gomod github.com/golang/go/src go1.14 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.14 fmt/Sprintf().("the deviation between the compared floats is too great [%v:%v]", expectedLat, obtainedLat)
163 }
164
165 return true, ""
166 }
167
168 /* END FLOAT HELPERS */