-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_test.go
73 lines (62 loc) · 1.79 KB
/
all_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package example
import (
"math/rand"
"os"
"testing"
"github.com/cia-rana/golaunator/fortune"
"github.com/cia-rana/golaunator/iia"
)
const (
vertexDomainMax = 1000
verticesNum = 400
)
var vertices = make([][]float64, 0, verticesNum)
func TestMain(m *testing.M) {
//rand.Seed(time.Now().UnixNano())
rand.Seed(4)
for i := 0; i < verticesNum; i++ {
vertices = append(vertices, []float64{float64(rand.Intn(vertexDomainMax)), float64(rand.Intn(vertexDomainMax))})
}
os.Exit(m.Run())
}
func TestEdgesMatchInAllAlgorithms(t *testing.T) {
verticesForFortune := make([]*fortune.Vertex, 0, len(vertices))
verticesForIaa := make([]*iia.Vertex, 0, len(vertices))
for _, v := range vertices {
verticesForFortune = append(verticesForFortune, &fortune.Vertex{X: v[0], Y: v[1]})
verticesForIaa = append(verticesForIaa, &iia.Vertex{X: v[0], Y: v[1]})
}
triangulatorForFortune := fortune.NewTriangulator(verticesForFortune)
triangulatorForFortune.Triangulate()
triangulatorForIaa := iia.NewTriangulator(verticesForIaa)
triangulatorForIaa.Triangulate()
edgesByFortune := make(map[int]struct{})
edgesByIaa := make(map[int]struct{})
for _, e := range triangulatorForFortune.Edges {
a, b := IntMax(e.Start.Index, e.End.Index)
t.Log(a, b)
edgesByFortune[a*vertexDomainMax+b] = struct{}{}
}
for _, e := range triangulatorForIaa.HalfEdges {
a, b := IntMax(e.Next.Next.End.Index, e.End.Index)
t.Log(a, b)
edgesByIaa[a*vertexDomainMax+b] = struct{}{}
}
/*
if len(edgesByFortune) != len(edgesByIaa) {
t.Fatalf("edgesByFortune: %d, edgesByIaa: %d", len(edgesByFortune), len(edgesByIaa))
}
*/
for key, _ := range edgesByFortune {
if k, ok := edgesByIaa[key]; !ok {
t.Logf("%d, %d", key, k)
}
}
t.Fatalf("")
}
func IntMax(a, b int) (int, int) {
if a > b {
return b, a
}
return a, b
}