-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathline_test.go
61 lines (51 loc) · 1.07 KB
/
line_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
package ddskgen_test
import (
"strings"
"testing"
"github.com/noppikinatta/ddskgen"
)
func TestTryDodosuko3(t *testing.T) {
tests := map[string]struct {
rand ddskgen.Rand
expected string
succeed bool
}{
"succeeded": {
rand: newTestRnd(0, 1, 1, 1),
expected: "ドドスコスコスコ",
succeed: true,
},
"failed": {
rand: newTestRnd(1, 0, 1, 0),
expected: "スコドドスコドド",
succeed: false,
},
}
for name, v := range tests {
f := func(t *testing.T) {
b := strings.Builder{}
l := ddskgen.NewLine(&b, v.rand)
result := l.TryDodosuko3()
if b.String() != v.expected {
t.Errorf("expected outputs '%s', but got '%s'", v.expected, b.String())
}
if result != v.succeed {
t.Errorf("expected returns '%t', but got '%t'", v.succeed, result)
}
}
t.Run(name, f)
}
}
type testRnd struct {
values []int
idx int
}
func newTestRnd(v ...int) ddskgen.Rand {
return &testRnd{values: v}
}
func (r *testRnd) Intn(n int) int {
ret := r.values[r.idx] % n
r.idx++
r.idx %= len(r.values)
return ret
}