This repository was archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbigint_test.go
More file actions
74 lines (66 loc) · 1.41 KB
/
bigint_test.go
File metadata and controls
74 lines (66 loc) · 1.41 KB
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
package math
import (
"math/big"
"testing"
)
func i(i int64) *big.Int { return big.NewInt(i) }
var equalBigIntTests = []struct {
a, b *big.Int
want bool
}{
{i(-1), i(-1), true},
{i(-1), i(0), false},
{i(0), i(0), true},
{i(0), i(-1), false},
{i(1), i(-1), false},
{i(-1), i(1), false},
{i(1), i(1), true},
}
func TestEqualBigInt(t *testing.T) {
for i, tt := range equalBigIntTests {
got := EqualBigInt(tt.a, tt.b)
if got != tt.want {
t.Errorf("%d: EqualBigInt(%v, %v) = %v, want %v", i+1, tt.a, tt.b, got, tt.want)
}
}
}
var maxBigIntTests = []struct {
a, b *big.Int
want *big.Int
}{
{i(0), i(0), i(0)},
{i(1), i(1), i(1)},
{i(1), i(2), i(2)},
{i(2), i(1), i(2)},
{i(-2), i(1), i(1)},
{i(-1), i(1), i(1)},
{i(1), i(-1), i(1)},
}
func TestMaxBigInt(t *testing.T) {
for i, tt := range maxBigIntTests {
got := MaxBigInt(tt.a, tt.b)
if !EqualBigInt(tt.want, got) {
t.Errorf("%d: MaxBigInt(%v, %v) = %v, want %v", i+1, tt.a, tt.b, got, tt.want)
}
}
}
var minBigIntTests = []struct {
a, b *big.Int
want *big.Int
}{
{i(0), i(0), i(0)},
{i(1), i(1), i(1)},
{i(1), i(2), i(1)},
{i(2), i(1), i(1)},
{i(-2), i(1), i(-2)},
{i(-1), i(1), i(-1)},
{i(1), i(-1), i(-1)},
}
func TestMinBigInt(t *testing.T) {
for i, tt := range minBigIntTests {
got := MinBigInt(tt.a, tt.b)
if !EqualBigInt(tt.want, got) {
t.Errorf("%d: MinBigInt(%v, %v) = %v, want %v", i+1, tt.a, tt.b, got, tt.want)
}
}
}