-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_encode_test.go
More file actions
49 lines (42 loc) · 1.06 KB
/
decode_encode_test.go
File metadata and controls
49 lines (42 loc) · 1.06 KB
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
package puz_test
import (
"bytes"
puz "github.com/cqb13/puz-parser"
"testing"
)
func TestDecodeAndEncode(t *testing.T) {
testCases := []string{
"All-Sections-Sorted.puz",
"All-Sections-Unsorted.puz",
"Crossword-Blank-Squares.puz",
"Crossword-EXT-Rebus.puz",
"Crossword-PreAndPost-Scrambled.puz",
"Crossword-PreAndPost.puz",
"Crossword-PreAndPost.puz",
"Crossword.puz",
"Crossword-1.2.puz",
"washpost.puz",
"NYT-Locked.puz",
"NYT-Diagramless.puz",
"NYT-Nov2193.puz",
}
for _, name := range testCases {
t.Run(name, func(t *testing.T) {
correctDecodeAndEncode(name, t)
})
}
}
func correctDecodeAndEncode(name string, t *testing.T) {
data := loadFile(t, name)
puzzle, err := puz.DecodePuz(data)
if err != nil {
t.Fatalf("Failed to decode %s: %v", name, err)
}
encoded, err := puz.EncodePuz(puzzle)
if err != nil {
t.Fatalf("Failed to encode %s: %v", name, err)
}
if !bytes.Equal(data, encoded) {
t.Errorf("Encoded bytes do not match original for %s\n\noriginal:\n%s\n\nnew:\n%s", name, buildHex(data), buildHex(encoded))
}
}