This repository has been archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boid_test.go
84 lines (76 loc) · 2.02 KB
/
boid_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 (
rtree "github.com/patrick-higgins/rtreego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Boids", func() {
Describe("Boid Initialization", func() {
var (
boid *Boid
)
BeforeEach(func() {
boid = NewBoid(1)
})
It("Should proper dimensions", func() {
Expect(boid.Point).To(HaveLen(3))
})
It("Should have zero'd position", func() {
Expect(boid.Point).To(ConsistOf(rtree.Point{0.0, 0.0, 0.0}))
})
It("Should have zero'd velocity", func() {
Expect(boid.Velocity).To(ConsistOf(rtree.Point{0.0, 0.0, 0.0}))
})
})
Describe("Rule tests", func() {
var (
area *Area
boid1 *Boid
boid2 *Boid
)
JustBeforeEach(func() {
area.AddBoid(boid1)
area.AddBoid(boid2)
})
Context("Single Dimension Tests", func() {
BeforeEach(func() {
xD := NewDimensionValue(0.0, 100.0)
yD := NewDimensionValue(0.0, 0.0)
zD := NewDimensionValue(0.0, 0.0)
area = NewArea(xD, yD, zD)
boid1 = NewBoid(1)
boid1.Point = rtree.Point{45.0, 0.0, 0.0}
boid2 = NewBoid(2)
boid2.Point = rtree.Point{55.0, 0.0, 0.0}
})
It("Should implement rule1", func() {
result := boid1.Rule1(area)
Expect(result).To(ConsistOf(rtree.Point{0.1, 0.0, 0.0}))
})
It("Should implement rule2", func() {
result := boid1.Rule2(area)
Expect(result).To(ConsistOf(rtree.Point{0.0, 0.0, 0.0}))
})
})
Context("Two Dimension Tests", func() {
BeforeEach(func() {
xD := NewDimensionValue(0.0, 100.0)
yD := NewDimensionValue(0.0, 100.0)
zD := NewDimensionValue(0.0, 0.0)
area = NewArea(xD, yD, zD)
boid1 = NewBoid(1)
boid1.Point = rtree.Point{25.0, 50.0, 0.0}
boid2 = NewBoid(2)
boid2.Point = rtree.Point{75.0, 25.0, 0.0}
})
It("Should implement rule1", func() {
result := boid1.Rule1(area)
Expect(result).To(ConsistOf(rtree.Point{0.5, -0.25, 0.0}))
})
It("Should implement rule2", func() {
result := boid1.Rule2(area)
Expect(result).To(ConsistOf(rtree.Point{0.0, 0.0, 0.0}))
})
})
})
})