@@ -4,170 +4,175 @@ import (
44 "testing"
55
66 "github.com/peterstace/simplefeatures/geom"
7+ "github.com/peterstace/simplefeatures/internal/test"
78)
89
910func TestPointAccessorNonEmpty (t * testing.T ) {
10- xy , ok := geomFromWKT (t , "POINT(1 2)" ).MustAsPoint ().XY ()
11- expectBoolEq (t , ok , true )
12- expectXYEq (t , xy , geom.XY {1 , 2 })
11+ xy , ok := test . FromWKT (t , "POINT(1 2)" ).MustAsPoint ().XY ()
12+ test . Eq (t , ok , true )
13+ test . Eq (t , xy , geom.XY {1 , 2 })
1314}
1415
1516func TestPointAccessorEmpty (t * testing.T ) {
16- _ , ok := geomFromWKT (t , "POINT EMPTY" ).MustAsPoint ().XY ()
17- expectBoolEq (t , ok , false )
17+ _ , ok := test .FromWKT (t , "POINT EMPTY" ).MustAsPoint ().XY ()
18+ test .Eq (t , ok , false )
19+ }
20+
21+ func xyCoords (x , y float64 ) geom.Coordinates {
22+ return geom.Coordinates {XY : geom.XY {x , y }, Type : geom .DimXY }
1823}
1924
2025func TestLineStringAccessor (t * testing.T ) {
21- ls := geomFromWKT (t , "LINESTRING(1 2,3 4,5 6)" ).MustAsLineString ()
26+ ls := test . FromWKT (t , "LINESTRING(1 2,3 4,5 6)" ).MustAsLineString ()
2227 seq := ls .Coordinates ()
2328 pt12 := xyCoords (1 , 2 )
2429 pt34 := xyCoords (3 , 4 )
2530 pt56 := xyCoords (5 , 6 )
2631
2732 t .Run ("start" , func (t * testing.T ) {
2833 want := geom .NewPoint (pt12 )
29- expectGeomEq (t , ls .StartPoint ().AsGeometry (), want .AsGeometry ())
34+ test . ExactEquals (t , ls .StartPoint ().AsGeometry (), want .AsGeometry ())
3035 })
3136 t .Run ("end" , func (t * testing.T ) {
3237 want := geom .NewPoint (pt56 )
33- expectGeomEq (t , ls .EndPoint ().AsGeometry (), want .AsGeometry ())
38+ test . ExactEquals (t , ls .EndPoint ().AsGeometry (), want .AsGeometry ())
3439 })
3540 t .Run ("num points" , func (t * testing.T ) {
36- expectIntEq (t , seq .Length (), 3 )
41+ test . Eq (t , seq .Length (), 3 )
3742 })
3843 t .Run ("point n" , func (t * testing.T ) {
39- expectPanics (t , func () { seq .Get (- 1 ) })
40- expectCoordsEq (t , seq .Get (0 ), pt12 )
41- expectCoordsEq (t , seq .Get (1 ), pt34 )
42- expectCoordsEq (t , seq .Get (2 ), pt56 )
43- expectPanics (t , func () { seq .Get (3 ) })
44+ test . Panics (t , func () { seq .Get (- 1 ) })
45+ test . Eq (t , seq .Get (0 ), pt12 )
46+ test . Eq (t , seq .Get (1 ), pt34 )
47+ test . Eq (t , seq .Get (2 ), pt56 )
48+ test . Panics (t , func () { seq .Get (3 ) })
4449 })
4550}
4651
4752func TestLineStringEmptyAccessor (t * testing.T ) {
48- ls := geomFromWKT (t , "LINESTRING EMPTY" ).MustAsLineString ()
53+ ls := test . FromWKT (t , "LINESTRING EMPTY" ).MustAsLineString ()
4954 seq := ls .Coordinates ()
50- emptyPoint := geomFromWKT (t , "POINT EMPTY" )
55+ emptyPoint := test . FromWKT (t , "POINT EMPTY" )
5156
5257 t .Run ("start" , func (t * testing.T ) {
53- expectGeomEq (t , ls .StartPoint ().AsGeometry (), emptyPoint )
58+ test . ExactEquals (t , ls .StartPoint ().AsGeometry (), emptyPoint )
5459 })
5560 t .Run ("end" , func (t * testing.T ) {
56- expectGeomEq (t , ls .EndPoint ().AsGeometry (), emptyPoint )
61+ test . ExactEquals (t , ls .EndPoint ().AsGeometry (), emptyPoint )
5762 })
5863 t .Run ("num points" , func (t * testing.T ) {
59- expectIntEq (t , seq .Length (), 0 )
64+ test . Eq (t , seq .Length (), 0 )
6065 })
6166 t .Run ("point n" , func (t * testing.T ) {
62- expectPanics (t , func () { seq .Get (- 1 ) })
63- expectPanics (t , func () { seq .Get (0 ) })
64- expectPanics (t , func () { seq .Get (1 ) })
67+ test . Panics (t , func () { seq .Get (- 1 ) })
68+ test . Panics (t , func () { seq .Get (0 ) })
69+ test . Panics (t , func () { seq .Get (1 ) })
6570 })
6671}
6772
6873func TestLineStringAccessorWithDuplicates (t * testing.T ) {
69- ls := geomFromWKT (t , "LINESTRING(1 2,3 4,3 4,5 6)" ).MustAsLineString ()
74+ ls := test . FromWKT (t , "LINESTRING(1 2,3 4,3 4,5 6)" ).MustAsLineString ()
7075 seq := ls .Coordinates ()
7176 pt12 := xyCoords (1 , 2 )
7277 pt34 := xyCoords (3 , 4 )
7378 pt56 := xyCoords (5 , 6 )
7479
7580 t .Run ("num points" , func (t * testing.T ) {
76- expectIntEq (t , seq .Length (), 4 )
81+ test . Eq (t , seq .Length (), 4 )
7782 })
7883 t .Run ("point n" , func (t * testing.T ) {
79- expectPanics (t , func () { seq .Get (- 1 ) })
80- expectCoordsEq (t , seq .Get (0 ), pt12 )
81- expectCoordsEq (t , seq .Get (1 ), pt34 )
82- expectCoordsEq (t , seq .Get (2 ), pt34 )
83- expectCoordsEq (t , seq .Get (3 ), pt56 )
84- expectPanics (t , func () { seq .Get (4 ) })
84+ test . Panics (t , func () { seq .Get (- 1 ) })
85+ test . Eq (t , seq .Get (0 ), pt12 )
86+ test . Eq (t , seq .Get (1 ), pt34 )
87+ test . Eq (t , seq .Get (2 ), pt34 )
88+ test . Eq (t , seq .Get (3 ), pt56 )
89+ test . Panics (t , func () { seq .Get (4 ) })
8590 })
8691}
8792
8893func TestLineStringAccessorWithMoreDuplicates (t * testing.T ) {
89- ls := geomFromWKT (t , "LINESTRING(1 2,1 2,3 4,3 4,3 4,5 6,5 6)" ).MustAsLineString ()
94+ ls := test . FromWKT (t , "LINESTRING(1 2,1 2,3 4,3 4,3 4,5 6,5 6)" ).MustAsLineString ()
9095 seq := ls .Coordinates ()
9196 pt12 := xyCoords (1 , 2 )
9297 pt34 := xyCoords (3 , 4 )
9398 pt56 := xyCoords (5 , 6 )
9499
95100 t .Run ("num points" , func (t * testing.T ) {
96- expectIntEq (t , seq .Length (), 7 )
101+ test . Eq (t , seq .Length (), 7 )
97102 })
98103 t .Run ("point n" , func (t * testing.T ) {
99- expectPanics (t , func () { seq .Get (- 1 ) })
100- expectCoordsEq (t , seq .Get (0 ), pt12 )
101- expectCoordsEq (t , seq .Get (1 ), pt12 )
102- expectCoordsEq (t , seq .Get (2 ), pt34 )
103- expectCoordsEq (t , seq .Get (3 ), pt34 )
104- expectCoordsEq (t , seq .Get (4 ), pt34 )
105- expectCoordsEq (t , seq .Get (5 ), pt56 )
106- expectCoordsEq (t , seq .Get (6 ), pt56 )
107- expectPanics (t , func () { seq .Get (7 ) })
104+ test . Panics (t , func () { seq .Get (- 1 ) })
105+ test . Eq (t , seq .Get (0 ), pt12 )
106+ test . Eq (t , seq .Get (1 ), pt12 )
107+ test . Eq (t , seq .Get (2 ), pt34 )
108+ test . Eq (t , seq .Get (3 ), pt34 )
109+ test . Eq (t , seq .Get (4 ), pt34 )
110+ test . Eq (t , seq .Get (5 ), pt56 )
111+ test . Eq (t , seq .Get (6 ), pt56 )
112+ test . Panics (t , func () { seq .Get (7 ) })
108113 })
109114}
110115
111116func TestPolygonAccessor (t * testing.T ) {
112- poly := geomFromWKT (t , "POLYGON((0 0,5 0,5 3,0 3,0 0),(1 1,2 1,2 2,1 2,1 1),(3 1,4 1,4 2,3 2,3 1))" ).MustAsPolygon ()
113- outer := geomFromWKT (t , "LINESTRING(0 0,5 0,5 3,0 3,0 0)" )
114- inner0 := geomFromWKT (t , "LINESTRING(1 1,2 1,2 2,1 2,1 1)" )
115- inner1 := geomFromWKT (t , "LINESTRING(3 1,4 1,4 2,3 2,3 1)" )
116-
117- expectGeomEq (t , poly .ExteriorRing ().AsGeometry (), outer )
118- expectIntEq (t , poly .NumInteriorRings (), 2 )
119- expectPanics (t , func () { poly .InteriorRingN (- 1 ) })
120- expectGeomEq (t , poly .InteriorRingN (0 ).AsGeometry (), inner0 )
121- expectGeomEq (t , poly .InteriorRingN (1 ).AsGeometry (), inner1 )
122- expectPanics (t , func () { poly .InteriorRingN (2 ) })
117+ poly := test . FromWKT (t , "POLYGON((0 0,5 0,5 3,0 3,0 0),(1 1,2 1,2 2,1 2,1 1),(3 1,4 1,4 2,3 2,3 1))" ).MustAsPolygon ()
118+ outer := test . FromWKT (t , "LINESTRING(0 0,5 0,5 3,0 3,0 0)" )
119+ inner0 := test . FromWKT (t , "LINESTRING(1 1,2 1,2 2,1 2,1 1)" )
120+ inner1 := test . FromWKT (t , "LINESTRING(3 1,4 1,4 2,3 2,3 1)" )
121+
122+ test . ExactEquals (t , poly .ExteriorRing ().AsGeometry (), outer )
123+ test . Eq (t , poly .NumInteriorRings (), 2 )
124+ test . Panics (t , func () { poly .InteriorRingN (- 1 ) })
125+ test . ExactEquals (t , poly .InteriorRingN (0 ).AsGeometry (), inner0 )
126+ test . ExactEquals (t , poly .InteriorRingN (1 ).AsGeometry (), inner1 )
127+ test . Panics (t , func () { poly .InteriorRingN (2 ) })
123128}
124129
125130func TestMultiPointAccessor (t * testing.T ) {
126- mp := geomFromWKT (t , "MULTIPOINT((4 5),(2 3),(8 7))" ).MustAsMultiPoint ()
127- pt0 := geomFromWKT (t , "POINT(4 5)" )
128- pt1 := geomFromWKT (t , "POINT(2 3)" )
129- pt2 := geomFromWKT (t , "POINT(8 7)" )
130-
131- expectIntEq (t , mp .NumPoints (), 3 )
132- expectPanics (t , func () { mp .PointN (- 1 ) })
133- expectGeomEq (t , mp .PointN (0 ).AsGeometry (), pt0 )
134- expectGeomEq (t , mp .PointN (1 ).AsGeometry (), pt1 )
135- expectGeomEq (t , mp .PointN (2 ).AsGeometry (), pt2 )
136- expectPanics (t , func () { mp .PointN (3 ) })
131+ mp := test . FromWKT (t , "MULTIPOINT((4 5),(2 3),(8 7))" ).MustAsMultiPoint ()
132+ pt0 := test . FromWKT (t , "POINT(4 5)" )
133+ pt1 := test . FromWKT (t , "POINT(2 3)" )
134+ pt2 := test . FromWKT (t , "POINT(8 7)" )
135+
136+ test . Eq (t , mp .NumPoints (), 3 )
137+ test . Panics (t , func () { mp .PointN (- 1 ) })
138+ test . ExactEquals (t , mp .PointN (0 ).AsGeometry (), pt0 )
139+ test . ExactEquals (t , mp .PointN (1 ).AsGeometry (), pt1 )
140+ test . ExactEquals (t , mp .PointN (2 ).AsGeometry (), pt2 )
141+ test . Panics (t , func () { mp .PointN (3 ) })
137142}
138143
139144func TestMultiLineStringAccessors (t * testing.T ) {
140- mls := geomFromWKT (t , "MULTILINESTRING((1 2,3 4,5 6),(7 8,9 10,11 12))" ).MustAsMultiLineString ()
141- ls0 := geomFromWKT (t , "LINESTRING(1 2,3 4,5 6)" )
142- ls1 := geomFromWKT (t , "LINESTRING(7 8,9 10,11 12)" )
143-
144- expectIntEq (t , mls .NumLineStrings (), 2 )
145- expectPanics (t , func () { mls .LineStringN (- 1 ) })
146- expectGeomEq (t , mls .LineStringN (0 ).AsGeometry (), ls0 )
147- expectGeomEq (t , mls .LineStringN (1 ).AsGeometry (), ls1 )
148- expectPanics (t , func () { mls .LineStringN (2 ) })
145+ mls := test . FromWKT (t , "MULTILINESTRING((1 2,3 4,5 6),(7 8,9 10,11 12))" ).MustAsMultiLineString ()
146+ ls0 := test . FromWKT (t , "LINESTRING(1 2,3 4,5 6)" )
147+ ls1 := test . FromWKT (t , "LINESTRING(7 8,9 10,11 12)" )
148+
149+ test . Eq (t , mls .NumLineStrings (), 2 )
150+ test . Panics (t , func () { mls .LineStringN (- 1 ) })
151+ test . ExactEquals (t , mls .LineStringN (0 ).AsGeometry (), ls0 )
152+ test . ExactEquals (t , mls .LineStringN (1 ).AsGeometry (), ls1 )
153+ test . Panics (t , func () { mls .LineStringN (2 ) })
149154}
150155
151156func TestMultiPolygonAccessors (t * testing.T ) {
152- polys := geomFromWKT (t , "MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((2 0,2 1,3 0,2 0)))" ).MustAsMultiPolygon ()
153- poly0 := geomFromWKT (t , "POLYGON((0 0,0 1,1 0,0 0))" )
154- poly1 := geomFromWKT (t , "POLYGON((2 0,2 1,3 0,2 0))" )
155-
156- expectIntEq (t , polys .NumPolygons (), 2 )
157- expectPanics (t , func () { polys .PolygonN (- 1 ) })
158- expectGeomEq (t , polys .PolygonN (0 ).AsGeometry (), poly0 )
159- expectGeomEq (t , polys .PolygonN (1 ).AsGeometry (), poly1 )
160- expectPanics (t , func () { polys .PolygonN (2 ) })
157+ polys := test . FromWKT (t , "MULTIPOLYGON(((0 0,0 1,1 0,0 0)),((2 0,2 1,3 0,2 0)))" ).MustAsMultiPolygon ()
158+ poly0 := test . FromWKT (t , "POLYGON((0 0,0 1,1 0,0 0))" )
159+ poly1 := test . FromWKT (t , "POLYGON((2 0,2 1,3 0,2 0))" )
160+
161+ test . Eq (t , polys .NumPolygons (), 2 )
162+ test . Panics (t , func () { polys .PolygonN (- 1 ) })
163+ test . ExactEquals (t , polys .PolygonN (0 ).AsGeometry (), poly0 )
164+ test . ExactEquals (t , polys .PolygonN (1 ).AsGeometry (), poly1 )
165+ test . Panics (t , func () { polys .PolygonN (2 ) })
161166}
162167
163168func TestGeometryCollectionAccessors (t * testing.T ) {
164- geoms := geomFromWKT (t , "GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 0,0 0)),POLYGON((2 0,2 1,3 0,2 0)))" ).MustAsGeometryCollection ()
165- geom0 := geomFromWKT (t , "POLYGON((0 0,0 1,1 0,0 0))" )
166- geom1 := geomFromWKT (t , "POLYGON((2 0,2 1,3 0,2 0))" )
167-
168- expectIntEq (t , geoms .NumGeometries (), 2 )
169- expectPanics (t , func () { geoms .GeometryN (- 1 ) })
170- expectGeomEq (t , geoms .GeometryN (0 ), geom0 )
171- expectGeomEq (t , geoms .GeometryN (1 ), geom1 )
172- expectPanics (t , func () { geoms .GeometryN (2 ) })
169+ geoms := test . FromWKT (t , "GEOMETRYCOLLECTION(POLYGON((0 0,0 1,1 0,0 0)),POLYGON((2 0,2 1,3 0,2 0)))" ).MustAsGeometryCollection ()
170+ geom0 := test . FromWKT (t , "POLYGON((0 0,0 1,1 0,0 0))" )
171+ geom1 := test . FromWKT (t , "POLYGON((2 0,2 1,3 0,2 0))" )
172+
173+ test . Eq (t , geoms .NumGeometries (), 2 )
174+ test . Panics (t , func () { geoms .GeometryN (- 1 ) })
175+ test . ExactEquals (t , geoms .GeometryN (0 ), geom0 )
176+ test . ExactEquals (t , geoms .GeometryN (1 ), geom1 )
177+ test . Panics (t , func () { geoms .GeometryN (2 ) })
173178}
0 commit comments