-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoints_test.go
More file actions
96 lines (82 loc) · 2.04 KB
/
points_test.go
File metadata and controls
96 lines (82 loc) · 2.04 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
package betterpath
import (
"testing"
)
func TestRemoveOutliers(t *testing.T) {
points := make(Points, 6)
// TEST1: Wrong points at the end
points[0] = Point{1, 1, 1}
points[1] = Point{2, 2, 2}
points[2] = Point{3, 3, 3}
points[3] = Point{4, 4, 4}
points[4] = Point{25, 25, 5}
points[5] = Point{25, 25, 6}
points.RemoveOutliers()
if len(points) != 4 {
t.Error("Test1: All erroneous points were not removed")
} else {
want := [4]int64{1, 2, 3, 4}
for i, got := range points {
if want[i] != got.t {
t.Error("Test1: Wrong points were removed")
}
}
}
points = make(Points, 6)
// TEST2: Wrong point at the middle
points[0] = Point{1, 1, 1}
points[1] = Point{2, 2, 2}
points[2] = Point{25, 25, 3}
points[3] = Point{4, 4, 4}
points[4] = Point{5, 5, 5}
points[5] = Point{6, 6, 6}
points.RemoveOutliers()
if len(points) != 5 {
t.Error("Test2: All erroneous points were not removed")
} else {
want := [5]int64{1, 2, 4, 5, 6}
for i, got := range points {
if want[i] != got.t {
t.Error("Test2: Wrong points were removed")
}
}
}
points = make(Points, 6)
// TEST3: Wrong point at the beginning
points[0] = Point{25, 25, 1}
points[1] = Point{2, 2, 2}
points[2] = Point{3, 3, 3}
points[3] = Point{4, 4, 4}
points[4] = Point{5, 5, 5}
points[5] = Point{6, 6, 6}
points.RemoveOutliers()
if len(points) != 5 {
t.Error("Test3: All erroneous points were not removed")
} else {
want := [5]int64{2, 3, 4, 5, 6}
for i, got := range points {
if want[i] != got.t {
t.Error("Test3: Wrong points were removed")
}
}
}
points = make(Points, 6)
// TEST4: Nothing to remove
points[0] = Point{1, 1, 1}
points[1] = Point{2, 2, 2}
points[2] = Point{3, 3, 3}
points[3] = Point{4, 4, 4}
points[4] = Point{5, 5, 5}
points[5] = Point{6, 6, 6}
points.RemoveOutliers()
if len(points) != 6 {
t.Error("Test4: All erroneous points were not removed")
} else {
want := [6]int64{1, 2, 3, 4, 5, 6}
for i, got := range points {
if want[i] != got.t {
t.Error("Test4: Wrong points were removed")
}
}
}
}