-
Notifications
You must be signed in to change notification settings - Fork 0
/
numbers_test.go
77 lines (68 loc) · 1.45 KB
/
numbers_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
// FILEPATH: /home/aho/git/go_katas/numbers_test.go
package go_kata
import (
"testing"
)
func TestShiftLeft(t *testing.T) {
testCases := []struct {
n int
i uint
expected int
}{
{2, 1, 4},
{3, 1, 6},
{2, 2, 8},
{5, 2, 20},
{10, 3, 80},
{0, 25, 0},
{1024, 1, 2048},
{-5, 1, -10},
}
for _, testCases := range testCases {
result := ShiftLeft(testCases.n, testCases.i)
if result != testCases.expected {
t.Errorf("shiftLeft(%d, %d) = %d, expected %d", testCases.n, testCases.i, result, testCases.expected)
}
}
}
func TestShiftLeftBig(t *testing.T) {
testCases := []struct {
n uint
i uint
expected int
}{
{2, 1, 4},
{3, 1, 6},
{2, 2, 8},
{5, 2, 20},
{10, 3, 80},
{0, 25, 0},
{1024, 1, 2048},
{1, 10, 1024},
}
for _, testCases := range testCases {
result := ShiftLeftBig(testCases.n, testCases.i)
if result.Int64() != int64(testCases.expected) {
t.Errorf("shiftLeftBig(%d, %d) = %d, expected %d", testCases.n, testCases.i, result.Uint64(), testCases.expected)
}
}
}
func TestShiftLeftPow2(t *testing.T) {
testCases := []struct {
n uint
expected int
}{
{2, 4},
{3, 6},
{5, 10},
{10, 20},
{0, 0},
{1024, 2048},
}
for _, testCases := range testCases {
result := ShiftLeftMultBy2(testCases.n)
if result.Int64() != int64(testCases.expected) {
t.Errorf("shiftLeftBig(%d) = %d, expected %d", testCases.n, result.Uint64(), testCases.expected)
}
}
}