7 func Test_read_board_from_strings(t *testing.T) {
8 b, err := read_board_from_strings([]string{"1", "2", "9", "12", "6", "8", "13", "14", "0", "11", "15", "3", "7", "4", "10", "5"})
9 if err != nil || *b != Board([BOARD_SIZE]Space{1, 2, 9, 12, 6, 8, 13, 14, 0, 11, 15, 3, 7, 4, 10, 5}) {
14 b, err = read_board_from_strings([]string{"1", "2", "9", "12", "6", "8", "13", "14", "0", "11", "15", "3", "7", "4", "10"})
20 b, err = read_board_from_strings([]string{"1", "foo", "9", "12", "6", "8", "13", "14", "0", "11", "15", "3", "7", "4", "10", "5"})
26 b, err = read_board_from_strings([]string{"1", "", "9", "12", "6", "8", "13", "14", "0", "11", "15", "3", "7", "4", "10", "5"})
32 // For sorting, for unordered equality testing
35 func (s Spaces) Len() int { return len(s) }
36 func (s Spaces) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
37 func (s Spaces) Less(i, j int) bool { return s[i] < s[j] }
39 func Test_adjacent_spaces(t *testing.T) {
40 type TestCase struct {
46 {1, []Space{0, 2, 5}},
47 {2, []Space{1, 3, 6}},
49 {4, []Space{0, 5, 8}},
50 {5, []Space{1, 4, 6, 9}},
51 {6, []Space{2, 5, 7, 10}},
52 {7, []Space{3, 6, 11}},
53 {8, []Space{4, 9, 12}},
54 {9, []Space{5, 8, 10, 13}},
55 {10, []Space{6, 9, 11, 14}},
56 {11, []Space{7, 10, 15}},
58 {13, []Space{9, 12, 14}},
59 {14, []Space{10, 13, 15}},
60 {15, []Space{11, 14}},
62 for i, c := range cases {
63 var actual Spaces = adjacent_spaces(c.s)
66 if !reflect.DeepEqual(c.expected, actual) {
67 t.Error(i, c.expected, actual)