-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_test.go
84 lines (72 loc) · 2.01 KB
/
calc_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
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"sort"
"testing"
"github.com/brainsik/bae/plane"
)
func NewPlane(c1, c2 complex128, i int) {
panic("unimplemented")
}
func TestMakePlaneProblemSetMultiplePoints(t *testing.T) {
params := CalcParams{
Plane: plane.NewPlane(complex(0, 0), complex(2, 2), 10),
CalcArea: plane.PlaneView{Min: complex(-1, -1), Max: complex(1, 1)},
RPoints: 3,
IPoints: 3,
}
// Get.
expect := []CalcPoint{
{(-1 + 1i), plane.ImagePoint{X: 0, Y: 0}},
{(-1 + 0i), plane.ImagePoint{X: 0, Y: 5}},
{(-1 - 1i), plane.ImagePoint{X: 0, Y: 10}},
{(0 + 1i), plane.ImagePoint{X: 5, Y: 0}},
{(0 + 0i), plane.ImagePoint{X: 5, Y: 5}},
{(0 - 1i), plane.ImagePoint{X: 5, Y: 10}},
{(1 + 1i), plane.ImagePoint{X: 10, Y: 0}},
{(1 + 0i), plane.ImagePoint{X: 10, Y: 5}},
{(1 - 1i), plane.ImagePoint{X: 10, Y: 10}},
}
result := params.MakePlaneProblemSet()
if len(result) != len(expect) {
t.Fatalf("len(result) = %d; want %d", len(result), len(expect))
}
// Sort.
less := func(cp []CalcPoint, i, j int) bool {
ix := cp[i].XY.X
jx := cp[j].XY.X
switch {
case ix < jx:
return true
case ix == jx:
return cp[i].XY.Y < cp[j].XY.Y
default: // ix > jx
return false
}
}
sort.Slice(result, func(i, j int) bool { return less(result, i, j) })
sort.Slice(expect, func(i, j int) bool { return less(expect, i, j) })
// Compare.
for i := 0; i < len(expect); i++ {
if result[i] != expect[i] {
t.Errorf("Result and expect differed at index %d: %v != %v", i, result[i], expect[i])
}
}
}
func TestMakePlaneProblemSetSinglePoint(t *testing.T) {
params := CalcParams{
Plane: plane.NewPlane(complex(0, 0), complex(2, 2), 10),
CalcArea: plane.PlaneView{Min: complex(-1, -1), Max: complex(-1, -1)},
RPoints: 1,
IPoints: 1,
}
// Get.
expect := []CalcPoint{{(-1 - 1i), plane.ImagePoint{X: 0, Y: 10}}}
result := params.MakePlaneProblemSet()
if len(result) != 1 {
t.Fatalf("len(result) = %d; want 1", len(result))
}
// Compare.
if result[0] != expect[0] {
t.Error(result[0], expect[0])
}
}