...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package s2
16
17 import (
18 "testing"
19
20 "github.com/golang/geo/s1"
21 )
22
23 func TestContainsVertexQueryUndetermined(t *testing.T) {
24 q := NewContainsVertexQuery(parsePoint("1:2"))
25 q.AddEdge(parsePoint("3:4"), 1)
26 q.AddEdge(parsePoint("3:4"), -1)
27 if got := q.ContainsVertex(); got != 0 {
28 t.Errorf("ContainsVertex() = %v, want 0 for vertex with undetermined containment", got)
29 }
30 }
31
32 func TestContainsVertexQueryContainedWithDuplicates(t *testing.T) {
33
34
35 q := NewContainsVertexQuery(parsePoint("0:0"))
36 q.AddEdge(parsePoint("3:-3"), -1)
37 q.AddEdge(parsePoint("1:-5"), 1)
38 q.AddEdge(parsePoint("2:-4"), 1)
39 q.AddEdge(parsePoint("1:-5"), -1)
40 if got := q.ContainsVertex(); got != 1 {
41 t.Errorf("ContainsVertex() = %v, want 1 for vertex that is contained", got)
42 }
43 }
44
45 func TestContainsVertexQueryNotContainedWithDuplicates(t *testing.T) {
46
47
48 q := NewContainsVertexQuery(parsePoint("1:1"))
49 q.AddEdge(parsePoint("1:-5"), 1)
50 q.AddEdge(parsePoint("2:-4"), -1)
51 q.AddEdge(parsePoint("3:-3"), 1)
52 q.AddEdge(parsePoint("1:-5"), -1)
53 if got := q.ContainsVertex(); got != -1 {
54 t.Errorf("ContainsVertex() = %v, want -1 for vertex that is not contained", got)
55 }
56 }
57
58 func TestContainsVertexQueryMatchesLoopContainment(t *testing.T) {
59
60 loop := RegularLoop(parsePoint("89:-179"), s1.Angle(10)*s1.Degree, 1000)
61 for i := 1; i <= loop.NumVertices(); i++ {
62 q := NewContainsVertexQuery(loop.Vertex(i))
63 q.AddEdge(loop.Vertex(i-1), -1)
64 q.AddEdge(loop.Vertex(i+1), 1)
65 if got, want := q.ContainsVertex() > 0, loop.ContainsPoint(loop.Vertex(i)); got != want {
66 t.Errorf("ContainsVertex() = %v, loop.ContainsPoint(%v) = %v, should be the same", got, loop.Vertex(i), want)
67 }
68 }
69 }
70
View as plain text