-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle_test.go
30 lines (27 loc) · 1.01 KB
/
particle_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
// Copyright 2021 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pps
import "testing"
func TestParticleDir(t *testing.T) {
tests := []struct {
p Particle
want Vec2
}{
{p: Particle{Angle: 0}, want: Vec2{X: 1, Y: 0}},
{p: Particle{Angle: 45}, want: Vec2{X: 0.70710678118, Y: 0.70710678118}},
{p: Particle{Angle: 90}, want: Vec2{X: 0, Y: 1}},
{p: Particle{Angle: 135}, want: Vec2{X: -0.70710678118, Y: 0.70710678118}},
{p: Particle{Angle: 180}, want: Vec2{X: -1, Y: 0}},
{p: Particle{Angle: -45}, want: Vec2{X: 0.70710678118, Y: -0.70710678118}},
{p: Particle{Angle: -90}, want: Vec2{X: 0, Y: -1}},
{p: Particle{Angle: -135}, want: Vec2{X: -0.70710678118, Y: -0.70710678118}},
{p: Particle{Angle: -180}, want: Vec2{X: -1, Y: 0}},
}
for _, tt := range tests {
got := tt.p.Dir()
if !got.nearEq(tt.want) {
t.Errorf("Particle with angle %g°: Dir() = %v, want: %v", tt.p.Angle, got, tt.want)
}
}
}