-
Notifications
You must be signed in to change notification settings - Fork 0
/
score_test.go
86 lines (81 loc) · 1.65 KB
/
score_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
package qordle_test
import (
"encoding/json"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
"github.com/bzimmer/qordle"
)
func TestScore(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name, secret string
guesses, scores []string
err error
}{
{
name: "simple",
secret: "buyer",
guesses: []string{"brain", "beret"},
scores: []string{"B.rain", "Be.rEt"},
},
{
name: "different lengths",
secret: "humph",
guesses: []string{"table", "tables"},
err: qordle.ErrInvalidLength,
},
{
name: "empty",
secret: "empty",
guesses: []string{},
scores: []string{},
},
{
name: "alphanumeric",
secret: "humph",
guesses: []string{"12345"},
scores: []string{"12345"},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
a := assert.New(t)
scores, err := qordle.Score(tt.secret, tt.guesses...)
if tt.err != nil {
a.ErrorIs(err, tt.err)
return
}
a.NoError(err)
a.Equal(tt.scores, scores)
})
}
}
func TestScoreCommand(t *testing.T) {
a := assert.New(t)
for _, tt := range []harness{
{
name: "score",
args: []string{"score", "table", "cable"},
after: func(c *cli.Context) error {
var res []string
dec := json.NewDecoder(c.App.Writer.(io.Reader))
a.NoError(dec.Decode(&res))
a.Equal([]string{"cABLE"}, res)
return nil
},
},
{
name: "score with error",
err: "secret and guess lengths do not match",
args: []string{"score", "tableau", "cable"},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
run(t, &tt, qordle.CommandScore)
})
}
}