forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabs_test.go
More file actions
37 lines (34 loc) · 713 Bytes
/
Copy pathabs_test.go
File metadata and controls
37 lines (34 loc) · 713 Bytes
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
package binary
import "testing"
func TestAbs(t *testing.T) {
tests := getAbsTests()
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := Abs(test.base, test.n); got != test.want {
t.Errorf("Abs() = %v, want %v", got, test.want)
}
})
}
}
func getAbsTests() []struct {
name string
base int
n int
want int
} {
tests := []struct {
name string
base int
n int
want int
}{
{"-1 = |1| ", 32, -1, 1},
{"-255 = |255| ", 32, -255, 255},
{"0 = |0| ", 64, 0, 0},
{"5 = |5| ", 16, 5, 5},
{"-5 = |5| ", 32, -5, 5},
{"-98368972 = |98368972| ", 64, -98368972, 98368972},
{"-110298368972 = |110298368972| ", 64, -98368972, 98368972},
}
return tests
}