-
Notifications
You must be signed in to change notification settings - Fork 2
/
lordeckoder_test.go
61 lines (53 loc) · 1.17 KB
/
lordeckoder_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 lordeckoder
import (
"bufio"
"fmt"
"github.com/stretchr/testify/suite"
"log"
"os"
"testing"
)
type decodeTest struct {
deckCode string
expected []string
}
type DecodeSuite struct {
suite.Suite
TestCases []decodeTest
}
func (s *DecodeSuite) SetupSuite() {
file, err := os.Open("./test/DeckCodesTestData.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
test := decodeTest{deckCode: scanner.Text(), expected: []string{}}
for scanner.Scan() {
line := scanner.Text()
if line == "" {
break
}
test.expected = append(test.expected, line)
}
s.TestCases = append(s.TestCases, test)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
func (s *DecodeSuite) TestDecode() {
for _, test := range s.TestCases {
var cards []string
deck, err := Decode(test.deckCode)
for _, card := range deck.Cards {
cards = append(cards, fmt.Sprintf("%d:%s", card.Count, card.Card))
}
s.NoError(err, "error decoding a deck code")
s.ElementsMatch(cards, test.expected, "decks are not matching")
}
}
func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(DecodeSuite))
}