-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvex_hull_test.go
More file actions
41 lines (35 loc) · 1.44 KB
/
Copy pathconvex_hull_test.go
File metadata and controls
41 lines (35 loc) · 1.44 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
package robust
import (
"github.com/franela/goblin"
"math/rand"
"testing"
"time"
)
func TestConvexHull(t *testing.T) {
g := goblin.Goblin(t)
g.Describe("ConvexHull2D", func() {
g.It("test convex hull 2d", func() {
var seed = rand.NewSource(time.Now().UnixNano())
var random = rand.New(seed)
var coords = [][]float64{{0, 0}, {1, 1}, {1, 0}, {0.5, 0.5}, {0.7, 0.1}}
g.Assert(ConvexHull2D(coords)).Eql([][]float64{{0, 0}, {1, 0}, {1, 1}})
coords = [][]float64{{0, 0}, {1, 0}, {1, 1}, {0, 1}}
g.Assert(ConvexHull2D(coords)).Eql([][]float64{{0, 0}, {1, 0}, {1, 1}, {0, 1}})
coords = [][]float64{{0, 0}, {1, 1}, {1, 0}, {0, 1}}
g.Assert(ConvexHull2D(coords)).Eql([][]float64{{0, 0}, {1, 0}, {1, 1}, {0, 1}})
for i := 0; i < 1000; i++ {
coords = append(coords, af(random.Float64(), random.Float64()))
coords = append(coords, af(0, random.Float64()))
coords = append(coords, af(random.Float64(), 0))
coords = append(coords, af(random.Float64(), 1))
coords = append(coords, af(1, random.Float64()))
}
g.Assert(ConvexHull2D(coords)).Eql([][]float64{{0, 0}, {1, 0}, {1, 1}, {0, 1}})
//Degenerate cases
g.Assert(ConvexHull2D([][]float64{{0, 0}})).Eql([][]float64{{0, 0}})
g.Assert(ConvexHull2D([][]float64{})).Eql([][]float64{})
g.Assert(ConvexHull2D([][]float64{{0, 0}, {1, 1}})).Eql([][]float64{{0, 0}, {1, 1}})
g.Assert(ConvexHull2D([][]float64{{0, 0}, {0, 0}})).Eql([][]float64{{0, 0}})
})
})
}