-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextra_section_test.go
More file actions
135 lines (103 loc) · 3.03 KB
/
extra_section_test.go
File metadata and controls
135 lines (103 loc) · 3.03 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package puz_test
import (
puz "github.com/cqb13/puz-parser"
"slices"
"testing"
)
func TestGRBSandRTBL(t *testing.T) {
name := "Crossword-EXT-Rebus.puz"
data := loadFile(t, name)
puzzle, err := puz.DecodePuz(data)
if err != nil {
t.Fatalf("Failed to decode %s: %v", name, err)
}
if !puzzle.HasExtraSection(puz.RebusSection) {
t.Errorf("Failed to find expected GRBS section")
}
if !puzzle.HasExtraSection(puz.RebusTableSection) {
t.Errorf("Failed to find expected RTBL section")
}
if puzzle.HasExtraSection(puz.TimerSection) {
t.Errorf("Found unexpected LTIM section")
}
if puzzle.HasExtraSection(puz.MarkupBoardSection) {
t.Errorf("Found unexpected GEXT section")
}
if puzzle.HasExtraSection(puz.UserRebusTableSection) {
t.Errorf("Found unexpected RUSR section")
}
}
func TestAllSections(t *testing.T) {
puzzles := []string{
"All-Sections-Sorted.puz",
"All-Sections-Unsorted.puz",
}
for _, name := range puzzles {
data := loadFile(t, name)
puzzle, err := puz.DecodePuz(data)
if err != nil {
t.Fatalf("Failed to decode %s: %v", name, err)
}
if !puzzle.HasExtraSection(puz.RebusSection) {
t.Errorf("Failed to find expected GRBS section")
}
if !puzzle.HasExtraSection(puz.RebusTableSection) {
t.Errorf("Failed to find expected RTBL section")
}
if !puzzle.HasExtraSection(puz.TimerSection) {
t.Errorf("Failed to find expected LTIM section")
}
if !puzzle.HasExtraSection(puz.MarkupBoardSection) {
t.Errorf("Failed to find expected GEXT section")
}
if !puzzle.HasExtraSection(puz.UserRebusTableSection) {
t.Errorf("Failed to find expected RUSR section")
}
}
}
func TestAddingAndRemoving(t *testing.T) {
name := "Crossword-EXT-Rebus.puz"
data := loadFile(t, name)
puzzle, err := puz.DecodePuz(data)
if err != nil {
t.Fatalf("Failed to decode %s: %v", name, err)
}
if !puzzle.HasExtraSection(puz.RebusSection) {
t.Errorf("Failed to find expected GRBS section")
}
ok := puzzle.RemoveExtraSection(puz.RebusSection)
if !ok {
t.Errorf("Failed to remove GRBS section")
}
if puzzle.HasExtraSection(puz.RebusSection) {
t.Errorf("GRBS section present after removal")
}
ok = puzzle.AddExtraSection(puz.RebusSection)
if !ok {
t.Errorf("Failed to add GRBS section")
}
if !puzzle.HasExtraSection(puz.RebusSection) {
t.Errorf("Failed to find added GRBS section")
}
}
func TestExtraSectionSorting(t *testing.T) {
sortedName := "All-Sections-Sorted.puz"
unsortedName := "All-Sections-Unsorted.puz"
sortedData := loadFile(t, sortedName)
unsortedData := loadFile(t, unsortedName)
if slices.Compare(sortedData, unsortedData) == 0 {
t.Fatalf("Sorted and unsorted section puzzles were the same")
}
puzzle, err := puz.DecodePuz(unsortedData)
if err != nil {
t.Fatalf("Failed to decode %s: %v", unsortedName, err)
}
puzzle.SortExtraSections()
encoded, err := puz.EncodePuz(puzzle)
if err != nil {
t.Fatalf("Failed to encode %s: %v", unsortedName, err)
}
if slices.Compare(sortedData, encoded) != 0 {
t.Fatalf("Sorted section order did not match expected sort")
}
}