-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutil_test.go
71 lines (60 loc) · 1.49 KB
/
util_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
package dht
import (
"math/big"
"testing"
)
func TestGetAddress(t *testing.T) {
address := GetAddress()
if address == "" {
t.Errorf("Expecting an address, got '%v'", address)
}
}
func TestHash(t *testing.T) {
hash := Hash("hello world")
expected, _ := big.NewInt(0).SetString("243667368468580896692010249115860146898325751533", 10)
if hash.Cmp(expected) != 0 {
t.Errorf("Expected: %v\nGot: %v\n", expected, hash)
}
}
type BetweenTestCase struct {
left, id, right *big.Int
out bool
}
func BTC(left, id, right int64, out bool) BetweenTestCase {
return BetweenTestCase{
left: big.NewInt(left),
id: big.NewInt(id),
right: big.NewInt(right),
out: out,
}
}
func TestInclusiveBetween(t *testing.T) {
testCases := []BetweenTestCase{
BTC(15, 500, 834883, true),
BTC(3323, 12, 33299494, false),
BTC(0, 123, 123, true),
BTC(10, 223, 224, true),
BTC(135, 155, 154, false),
}
for _, test := range testCases {
actual := InclusiveBetween(test.left, test.id, test.right)
if actual != test.out {
t.Errorf("Expected %v\nGot %v\n", test.out, actual)
}
}
}
func TestExclusiveBetween(t *testing.T) {
testCases := []BetweenTestCase{
BTC(15, 500, 834883, true),
BTC(3323, 12, 33299494, false),
BTC(0, 123, 123, false),
BTC(10, 223, 224, true),
BTC(135, 155, 154, false),
}
for _, test := range testCases {
actual := ExclusiveBetween(test.left, test.id, test.right)
if actual != test.out {
t.Errorf("Expected %v\nGot %v\n", test.out, actual)
}
}
}