-
Notifications
You must be signed in to change notification settings - Fork 6
/
id_test.go
82 lines (71 loc) · 1.86 KB
/
id_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
package gmaj
import (
"math/big"
"testing"
)
func TestBetween(t *testing.T) {
t.Parallel()
tests := []struct {
x int64
a int64
b int64
exp bool
}{
{x: 20, a: 15, b: 21, exp: true},
{x: 47, a: 93, b: 93, exp: true},
{x: 532, a: 527, b: 789, exp: true},
{x: 169224980, a: 100797713, b: 220867348, exp: true},
{x: 22086, a: 1007, b: 22086, exp: false},
// wrapping around
{x: 20, a: 527, b: 277, exp: true},
{x: 788, a: 527, b: 277, exp: true},
{x: 20, a: 5, b: 2, exp: true},
{x: 1, a: 5, b: 2, exp: true},
{x: 3, a: 5, b: 2, exp: false},
{x: 20, a: 2, b: 5, exp: false},
}
for i, test := range tests {
x := big.NewInt(test.x).Bytes()
a := big.NewInt(test.a).Bytes()
b := big.NewInt(test.b).Bytes()
if want, got := test.exp, between(x, a, b); got != want {
t.Logf("running test [%02d]", i)
t.Fatalf("expected %t for Between(%d, %d, %d), got %t",
want, test.x, test.a, test.b, got,
)
}
}
}
func TestBetweenRightIncl(t *testing.T) {
t.Parallel()
tests := []struct {
x int64
a int64
b int64
exp bool
}{
{x: 788, a: 527, b: 277, exp: true},
{x: 12347, a: 234, b: 93484, exp: true},
{x: 384732, a: 527, b: 384732, exp: true},
{x: 384733, a: 527, b: 384732, exp: false},
{x: 527, a: 527, b: 384732, exp: false},
{x: 128, a: 64, b: 128, exp: true},
// wrapping around
{x: 20, a: 5, b: 2, exp: true},
{x: 1, a: 5, b: 2, exp: true},
{x: 2, a: 5, b: 2, exp: true},
{x: 3, a: 5, b: 2, exp: false},
{x: 20, a: 2, b: 5, exp: false},
}
for i, test := range tests {
x := big.NewInt(test.x).Bytes()
a := big.NewInt(test.a).Bytes()
b := big.NewInt(test.b).Bytes()
if want, got := test.exp, betweenRightIncl(x, a, b); got != want {
t.Logf("running test [%02d]", i)
t.Fatalf("expected %t for BetweenRightIncl(%d, %d, %d), got %t",
want, test.x, test.a, test.b, got,
)
}
}
}