-
Notifications
You must be signed in to change notification settings - Fork 20
/
body_test.go
52 lines (39 loc) · 844 Bytes
/
body_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
package cp
import (
"testing"
)
func TestBodyMassFromShapes(t *testing.T) {
body := NewBody(0, 0)
circle := NewCircle(body, 5, Vector{0, 0})
circle2 := NewCircle(body, 5, Vector{0, 0})
mass := 10.0
circle.SetMass(mass)
body.AddShape(circle)
if body.Mass() != mass {
t.Fail()
}
circle2.SetMass(mass)
body.AddShape(circle2)
if body.Mass() != mass * 2 {
t.Fail()
}
}
func TestBodyCoGFromShapes(t *testing.T) {
body := NewBody(0, 0)
circle := NewCircle(body, 5, Vector{0, 0})
circle2 := NewCircle(body, 5, Vector{10, 0})
mass := 10.0
circle.SetMass(mass)
body.AddShape(circle)
circle2.SetMass(mass)
body.AddShape(circle2)
cog := body.CenterOfGravity()
if cog.X != 5.0 || cog.Y != 0.0 {
t.Fail()
}
body.RemoveShape(circle)
cog = body.CenterOfGravity()
if cog.X != 10.0 || cog.Y != 0.0 {
t.Fail()
}
}