lottery_test.gno
0.92 Kb · 49 lines
1package lottery
2
3import (
4 "testing"
5
6 "gno.land/p/nt/uassert/v0"
7)
8
9func TestPickIndex(t *testing.T) {
10 cases := []struct {
11 height int64
12 n int
13 want int
14 }{
15 {0, 3, 0},
16 {1, 3, 1},
17 {2, 3, 2},
18 {3, 3, 0},
19 {10, 4, 2},
20 {100, 7, 2},
21 {5, 1, 0},
22 }
23 for _, tc := range cases {
24 got := pickIndex(tc.height, tc.n)
25 uassert.Equal(t, tc.want, got)
26 if got < 0 || got >= tc.n {
27 t.Errorf("index %d out of range for n=%d", got, tc.n)
28 }
29 }
30}
31
32func TestWinnerKey(t *testing.T) {
33 cases := []struct {
34 round int
35 want string
36 }{
37 {1, "000000001"},
38 {42, "000000042"},
39 {1000, "000001000"},
40 {123456789, "123456789"},
41 }
42 for _, tc := range cases {
43 uassert.Equal(t, tc.want, winnerKey(tc.round))
44 }
45 // Zero-padding must preserve chronological ordering under string compare.
46 uassert.True(t, winnerKey(2) > winnerKey(1))
47 uassert.True(t, winnerKey(10) > winnerKey(9))
48 uassert.True(t, winnerKey(100) > winnerKey(99))
49}