(t *testing.T)
| 233 | } |
| 234 | |
| 235 | func TestPolygonShape(t *testing.T) { |
| 236 | const numLoops = 100 |
| 237 | const numVerticesPerLoop = 6 |
| 238 | concentric := concentricLoopsPolygon(PointFromCoords(1, 0, 0), numLoops, numVerticesPerLoop) |
| 239 | |
| 240 | tests := []struct { |
| 241 | p *Polygon |
| 242 | }{ |
| 243 | {near0Polygon}, // one loop polygon |
| 244 | {near0231Polygon}, // several loops polygon |
| 245 | {concentric}, // many loops polygon |
| 246 | } |
| 247 | |
| 248 | for _, test := range tests { |
| 249 | shape := Shape(test.p) |
| 250 | |
| 251 | if got, want := shape.NumEdges(), test.p.numVertices; got != want { |
| 252 | t.Errorf("the number of vertices in a polygon should equal the number of edges. got %v, want %v", got, want) |
| 253 | } |
| 254 | if got, want := shape.NumChains(), test.p.NumLoops(); got != want { |
| 255 | t.Errorf("the number of loops in a polygon should equal the number of chains. got %v, want %v", got, want) |
| 256 | } |
| 257 | |
| 258 | edgeID := 0 |
| 259 | for i, l := range test.p.loops { |
| 260 | if edgeID != shape.Chain(i).Start { |
| 261 | t.Errorf("the edge id of the start of loop(%d) should equal the sum of vertices so far in the polygon. got %d, want %d", i, shape.Chain(i).Start, edgeID) |
| 262 | } |
| 263 | if len(l.vertices) != shape.Chain(i).Length { |
| 264 | t.Errorf("the length of Chain(%d) should equal the length of loop(%d), got %v, want %v", i, i, shape.Chain(i).Length, len(l.vertices)) |
| 265 | } |
| 266 | for j := 0; j < len(l.Vertices()); j++ { |
| 267 | edge := shape.Edge(edgeID) |
| 268 | if l.OrientedVertex(j) != edge.V0 { |
| 269 | t.Errorf("l.Vertex(%d) = %v, want %v", j, l.Vertex(j), edge.V0) |
| 270 | } |
| 271 | if l.OrientedVertex(j+1) != edge.V1 { |
| 272 | t.Errorf("l.Vertex(%d) = %v, want %v", j+1, l.Vertex(j+1), edge.V1) |
| 273 | } |
| 274 | edgeID++ |
| 275 | } |
| 276 | } |
| 277 | if got, want := shape.Dimension(), 2; got != want { |
| 278 | t.Errorf("shape.Dimension() = %v, want %v", got, want) |
| 279 | } |
| 280 | if shape.IsEmpty() { |
| 281 | t.Errorf("shape.IsEmpty() = true, want false") |
| 282 | } |
| 283 | if shape.IsFull() { |
| 284 | t.Errorf("shape.IsFull() = true, want false") |
| 285 | } |
| 286 | |
| 287 | if got, want := test.p.ContainsPoint(OriginPoint()), shape.ReferencePoint().Contained; got != want { |
| 288 | t.Errorf("p.ContainsPoint(OriginPoint()) != shape.ReferencePoint().Contained") |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 |
nothing calls this directly
no test coverage detected
searching dependent graphs…