-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlfs_test.go
150 lines (144 loc) · 2.58 KB
/
lfs_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package lfs
import (
"math/big"
"reflect"
"testing"
)
var (
big2Pow20 big.Int
big2Pow32 big.Int
)
func setup() {
var ok bool
if _, ok = big2Pow20.SetString("1048576", 10); !ok {
panic("failed to set big2Pow20")
}
if _, ok = big2Pow32.SetString("4294967296", 10); !ok {
panic("failed to set big2Pow32")
}
}
func Test_precompute(t *testing.T) {
type args struct {
n *big.Int
}
tests := []struct {
name string
args args
want *big.Int
}{
{
name: "test_2^20",
args: args{
n: &big2Pow20,
},
want: big.NewInt(9699690),
},
{
name: "test_2^32",
args: args{
n: &big2Pow32,
},
want: big.NewInt(200560490130),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
setup()
if got := precompute(tt.args.n); !reflect.DeepEqual(got, tt.want) {
t.Errorf("precompute() got = %v, want %v", got, tt.want)
}
})
}
}
func TestVerify(t *testing.T) {
type args struct {
target *big.Int
w1 *big.Int
w2 *big.Int
w3 *big.Int
w4 *big.Int
}
tests := []struct {
name string
args args
want bool
}{
{
name: "test_verify_success_4",
args: args{
target: big.NewInt(4),
w1: big.NewInt(2),
w2: big.NewInt(0),
w3: big.NewInt(0),
w4: big.NewInt(0),
},
want: true,
},
{
name: "test_verify_success_35955023",
args: args{
target: big.NewInt(35955023),
w1: big.NewInt(2323),
w2: big.NewInt(5454),
w3: big.NewInt(893),
w4: big.NewInt(123),
},
want: true,
},
{
name: "test_verify_fail_35955024",
args: args{
target: big.NewInt(35955024),
w1: big.NewInt(2323),
w2: big.NewInt(5454),
w3: big.NewInt(893),
w4: big.NewInt(123),
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
fs := [4]*big.Int{
tt.args.w1,
tt.args.w2,
tt.args.w3,
tt.args.w4,
}
if got := Verify(tt.args.target, fs); got != tt.want {
t.Errorf("Verify() = %v, want %v", got, tt.want)
}
})
}
}
func TestSolve(t *testing.T) {
type args struct {
n *big.Int
numRoutine int
}
tests := []struct {
name string
args args
}{
{
name: "test_4",
args: args{
n: big.NewInt(4),
numRoutine: 4,
},
},
{
name: "test_35955023",
args: args{
n: big.NewInt(35955023),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Solve(tt.args.n, tt.args.numRoutine); !Verify(tt.args.n, got) {
t.Errorf("Solve() verify failed, got: %v != %v", got, tt.args.n)
}
})
}
}