forked from spring1843/go-dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n_queens_test.go
34 lines (29 loc) · 1011 Bytes
/
n_queens_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
package backtracking
import (
"reflect"
"testing"
)
/*
TestNQueens tests solution(s) with the following signature and problem description:
func NQueens(n int) []Chessboard
Given an integer n representing an n by n chessboard, return all possible
arrangements of placing n queens on the chessboard such that the queens do not
attack each other.
*/
func TestNQueens(t *testing.T) {
tests := []struct {
n int
solutions []Chessboard
}{
{0, []Chessboard{}},
{1, []Chessboard{{{queen}}}},
{2, []Chessboard{}},
{3, []Chessboard{}},
{4, []Chessboard{{{empty, queen, empty, empty}, {empty, empty, empty, queen}, {queen, empty, empty, empty}, {empty, empty, queen, empty}}, {{empty, empty, queen, empty}, {queen, empty, empty, empty}, {empty, empty, empty, queen}, {empty, queen, empty, empty}}}},
}
for i, test := range tests {
if got := NQueens(test.n); !reflect.DeepEqual(test.solutions, got) {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.solutions, got)
}
}
}