github.com/seeker-insurance/kit@v0.0.13/geojson/polygon_test.go (about) 1 package geojson 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 ) 8 9 var poly = Polygon{ 10 {-1, -1}, {-1, 1}, {1, 1}, {-1, -1}, 11 } 12 13 func TestPolygon_GeoJSON(t *testing.T) { 14 tests := []struct { 15 name string 16 poly Polygon 17 want []byte 18 }{ 19 {"trivialPolygon", poly, []byte(fmt.Sprintf(`{"type": %s, "coordinates": %s}`, poly.Type(), wantCoords))}, 20 } 21 for _, tt := range tests { 22 t.Run(tt.name, func(t *testing.T) { 23 if got := tt.poly.GeoJSON(); !reflect.DeepEqual(got, tt.want) { 24 t.Errorf("Polygon.GeoJSON() = %s, want %s", got, tt.want) 25 } 26 }) 27 } 28 } 29 30 var wantCoords = `[[-1.000000, -1.000000], [1.000000, -1.000000], [1.000000, 1.000000], [-1.000000, -1.000000]]` 31 32 func TestPolygon_Coordinates(t *testing.T) { 33 tests := []struct { 34 name string 35 poly Polygon 36 want string 37 }{ 38 {"trivial", poly, wantCoords}, 39 } 40 for _, tt := range tests { 41 t.Run(tt.name, func(t *testing.T) { 42 if got := tt.poly.Coordinates(); got != tt.want { 43 t.Errorf("Polygon.Coordinates() = \n%v, want \n%v", got, tt.want) 44 } 45 }) 46 } 47 } 48 49 func TestPolygon_GetBSON(t *testing.T) { 50 tests := []struct { 51 name string 52 poly Polygon 53 want interface{} 54 }{ 55 // TODO: Add test cases. 56 } 57 for _, tt := range tests { 58 t.Run(tt.name, func(t *testing.T) { 59 if got, _ := tt.poly.GetBSON(); !reflect.DeepEqual(got, tt.want) { 60 t.Errorf("Polygon.GetBSON() = %v, want %v", got, tt.want) 61 } 62 }) 63 } 64 }