forked from holiman/uint256
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_test.go
47 lines (42 loc) · 1.09 KB
/
mod_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
// uint256: Fixed size 256-bit math library
// Copyright 2021 uint256 Authors
// SPDX-License-Identifier: BSD-3-Clause
package uint256
import "testing"
func TestLeadingZeros(t *testing.T) {
one := Int{1, 0, 0, 0}
testCases := []Int{
Int{0, 0, 0, 0},
Int{1, 0, 0, 0},
Int{0x7fffffffffffffff, 0, 0, 0},
Int{0x8000000000000000, 0, 0, 0},
Int{0xffffffffffffffff, 0, 0, 0},
Int{0, 1, 0, 0},
Int{0, 0x7fffffffffffffff, 0, 0},
Int{0, 0x8000000000000000, 0, 0},
Int{0, 0xffffffffffffffff, 0, 0},
Int{0, 0, 1, 0},
Int{0, 0, 0x7fffffffffffffff, 0},
Int{0, 0, 0x8000000000000000, 0},
Int{0, 0, 0xffffffffffffffff, 0},
Int{0, 0, 0, 1},
Int{0, 0, 0, 0x7fffffffffffffff},
Int{0, 0, 0, 0x8000000000000000},
Int{0, 0, 0, 0xffffffffffffffff},
}
for _, x := range testCases {
z := leadingZeros(&x)
if z >= 0 && z < 256 {
allZeros := new(Int).Rsh(&x, uint(256-z))
oneBit := new(Int).Rsh(&x, uint(255-z))
if allZeros.IsZero() && oneBit.Eq(&one) {
continue
}
} else if z == 256 {
if x.IsZero() {
continue
}
}
t.Errorf("wrong leading zeros %d of %x", z, x)
}
}