-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_test.go
85 lines (78 loc) · 1.81 KB
/
math_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
85
// 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 TestSign(t *testing.T) {
tests := []struct {
i int
want int
}{
{i: -1234, want: -1},
{i: -100, want: -1},
{i: -5, want: -1},
{i: -2, want: -1},
{i: -1, want: -1},
{i: 0, want: 0},
{i: 1, want: 1},
{i: 2, want: 1},
{i: 5, want: 1},
{i: 100, want: 1},
{i: 1234, want: 1},
}
for _, tt := range tests {
got := sign(tt.i)
if got != tt.want {
t.Errorf("sign(%d) = %d, want %d", tt.i, got, tt.want)
}
}
}
func TestDeg2rad(t *testing.T) {
tests := []struct {
deg float64
want float64
}{
{deg: 0, want: 0},
{deg: 45, want: 0.7853981633974483},
{deg: 90, want: 1.5707963267948966},
{deg: 135, want: 2.356194490192345},
{deg: 180, want: 3.141592653589793},
{deg: 225, want: 3.9269908169872414},
{deg: 270, want: 4.71238898038469},
{deg: 315, want: 5.497787143782138},
{deg: 360, want: 6.283185307179586},
}
for _, tt := range tests {
got := deg2rad(tt.deg)
if got != tt.want {
t.Errorf("deg2rad(%g) = %g, want %g", tt.deg, got, tt.want)
}
}
}
func TestWrap(t *testing.T) {
tests := []struct {
n float64
max float64
want float64
}{
{n: 0, max: 100, want: 0},
{n: -1, max: 100, want: 99},
{n: 255, max: 250, want: 5},
{n: 300, max: 250, want: 50},
{n: -2.5, max: 250, want: 247.5},
{n: 4, max: 5, want: 4},
{n: 5, max: 5, want: 0},
{n: 6, max: 5, want: 1},
{n: 10, max: 5, want: 0},
{n: -4, max: 5, want: 1},
{n: -5, max: 5, want: 0},
{n: -6, max: 5, want: 4},
{n: -10, max: 5, want: 0},
}
for _, tt := range tests {
got := wrap(tt.n, tt.max)
if got != tt.want {
t.Errorf("wrap(%g, %g) = %g, want %g", tt.n, tt.max, got, tt.want)
}
}
}