-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice_test.go
55 lines (50 loc) · 1.39 KB
/
dice_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
package vero
import (
"fmt"
"strconv"
"testing"
"github.com/pastc/vero/v2/internal"
)
func TestDice(t *testing.T) {
tests := []struct {
serverSeed, clientSeed string
nonce int
iteration int
want struct {
value int
}
}{
{"964cd1665174434d3b82b0a7e9dd5b8bbbc58056a4c3d411d89afcdc2141fa81",
"20244eaefdc61956bde0c835b0698d8bf5eeddaa7a27e9fae53db5da5a3a0967", 32139, 0, struct {
value int
}{3750},
},
{"ad0111b329b54e2947d1ee14c7b40242019bae11114775932b7865c227636a3a",
"2cf0c2cb4476cdf70ce68a42bc86b17814dafead8a8c30c128d203dc7270816f", 43289, 0, struct {
value int
}{3561},
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s,%s,%d,%d", tt.serverSeed, tt.clientSeed, tt.nonce, tt.iteration), func(t *testing.T) {
value, err := Dice(tt.serverSeed, tt.clientSeed, tt.nonce, tt.iteration)
if err != nil {
t.Fatalf("got %v", err)
}
if value != tt.want.value {
t.Errorf("got %d, want %d", value, tt.want.value)
}
})
}
}
func FuzzDice(f *testing.F) {
f.Add(0, 1, 0, 0)
f.Fuzz(func(t *testing.T, serverSeedNum int, clientSeedNum int, nonce int, iteration int) {
serverSeed := internal.Hash256(strconv.Itoa(serverSeedNum))
clientSeed := internal.Hash256(strconv.Itoa(clientSeedNum))
_, err := Dice(serverSeed, clientSeed, nonce, iteration)
if err != nil {
t.Fatalf("got %v", err)
}
})
}