forked from linhbkhn95/int256
-
Notifications
You must be signed in to change notification settings - Fork 0
/
big_int_test.go
97 lines (93 loc) · 1.75 KB
/
big_int_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package int256
import (
"math/big"
"reflect"
"testing"
"github.com/holiman/uint256"
)
func TestInt_ToBig(t *testing.T) {
type fields struct {
abs *uint256.Int
neg bool
}
tests := []struct {
name string
fields fields
want *big.Int
}{
// TODO: Add test cases.
{
name: "Should return correct value when parsing positive number",
fields: fields{
abs: uint256.NewInt(10),
neg: false,
},
want: big.NewInt(10),
},
{
name: "Should return correct value when parsing negative number",
fields: fields{
abs: uint256.NewInt(10),
neg: true,
},
want: big.NewInt(-10),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
z := &Int{
abs: tt.fields.abs,
neg: tt.fields.neg,
}
if got := z.ToBig(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Int.ToBig() = %v, want %v", got, tt.want)
}
})
}
}
func TestFromBig(t *testing.T) {
type args struct {
x *big.Int
}
tests := []struct {
name string
args args
want *Int
want1 bool
}{
// TODO: Add test cases.
{
name: "Should return correct value when parsing positive number",
args: args{
x: big.NewInt(10),
},
want: &Int{
abs: uint256.NewInt(10),
neg: false,
},
want1: false,
},
{
name: "Should return correct value when parsing negative number",
args: args{
x: big.NewInt(-10),
},
want: &Int{
abs: uint256.NewInt(10),
neg: true,
},
want1: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1 := FromBig(tt.args.x)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("FromBig() got = %v, want %v", got, tt.want)
}
if got1 != tt.want1 {
t.Errorf("FromBig() got1 = %v, want %v", got1, tt.want1)
}
})
}
}