1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package s2
16
17 import (
18 "testing"
19 )
20
21 func TestLaxLoopEmptyLoop(t *testing.T) {
22 shape := Shape(LaxLoopFromLoop(EmptyLoop()))
23
24 if got, want := shape.NumEdges(), 0; got != want {
25 t.Errorf("shape.NumEdges() = %v, want %v", got, want)
26 }
27 if got, want := shape.NumChains(), 0; got != want {
28 t.Errorf("shape.NumChains() = %v, want %v", got, want)
29 }
30 if got, want := shape.Dimension(), 2; got != want {
31 t.Errorf("shape.Dimension() = %v, want %v", got, want)
32 }
33 if !shape.IsEmpty() {
34 t.Errorf("shape.IsEmpty() = false, want true")
35 }
36 if shape.IsFull() {
37 t.Errorf("shape.IsFull() = true, want false")
38 }
39 if shape.ReferencePoint().Contained {
40 t.Errorf("shape.ReferencePoint().Contained should be false")
41 }
42 }
43
44 func TestLaxLoopNonEmptyLoop(t *testing.T) {
45 vertices := parsePoints("0:0, 0:1, 1:1, 1:0")
46 shape := Shape(LaxLoopFromPoints(vertices))
47 if got, want := len(shape.(*LaxLoop).vertices), len(vertices); got != want {
48 t.Errorf("shape.numVertices = %v, want %v", got, want)
49 }
50 if got, want := shape.NumEdges(), len(vertices); got != want {
51 t.Errorf("shape.NumEdges() = %v, want %v", got, want)
52 }
53 if got, want := shape.NumChains(), 1; got != want {
54 t.Errorf("shape.NumChains() = %v, want %v", got, want)
55 }
56 if got, want := shape.Chain(0).Start, 0; got != want {
57 t.Errorf("shape.Chain(0).Start = %v, want %v", got, want)
58 }
59 if got, want := shape.Chain(0).Length, len(vertices); got != want {
60 t.Errorf("shape.Chain(0).Length = %v, want %v", got, want)
61 }
62 for i := 0; i < len(vertices); i++ {
63 if got, want := shape.(*LaxLoop).vertex(i), vertices[i]; got != want {
64 t.Errorf("%d. vertex(%d) = %v, want %v", i, i, got, want)
65 }
66 edge := shape.Edge(i)
67 if vertices[i] != edge.V0 {
68 t.Errorf("%d. edge.V0 = %v, want %v", i, edge.V0, vertices[i])
69 }
70 if got, want := edge.V1, vertices[(i+1)%len(vertices)]; got != want {
71 t.Errorf("%d. edge.V1 = %v, want %v", i, got, want)
72 }
73 }
74 if got, want := shape.Dimension(), 2; got != want {
75 t.Errorf("shape.Dimension() = %v, want %v", got, want)
76 }
77 if shape.IsEmpty() {
78 t.Errorf("shape.IsEmpty() = true, want false")
79 }
80 if shape.IsFull() {
81 t.Errorf("shape.IsFull() = true, want false")
82 }
83 if shape.ReferencePoint().Contained {
84 t.Errorf("shape.ReferencePoint().Contained = true, want false")
85 }
86 }
87
88
89
90
91
92
View as plain text