forked from mrekucci/epi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnqueens_test.go
50 lines (45 loc) · 1.04 KB
/
nqueens_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
// Copyright (c) 2015, Peter Mrekaj. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.txt file.
package recursion
import (
"reflect"
"testing"
)
func TestNQueens(t *testing.T) {
for _, test := range []struct {
in int
want [][]int
}{
{0, nil},
{1, [][]int{{0}}},
{2, nil},
{3, nil},
{4, [][]int{
{1, 3, 0, 2},
{2, 0, 3, 1}}},
{5, [][]int{
{0, 2, 4, 1, 3},
{0, 3, 1, 4, 2},
{1, 3, 0, 2, 4},
{1, 4, 2, 0, 3},
{2, 0, 3, 1, 4},
{2, 4, 1, 3, 0},
{3, 0, 2, 4, 1},
{3, 1, 4, 2, 0},
{4, 1, 3, 0, 2},
{4, 2, 0, 3, 1}}},
} {
if got := NQueens(test.in); !reflect.DeepEqual(got, test.want) {
t.Errorf("NQueens(%d) = %v; want %v", test.in, got, test.want)
}
}
}
func benchNQueens(b *testing.B, size int) {
for i := 0; i < b.N; i++ {
NQueens(size)
}
}
func BenchmarkNQueens5(b *testing.B) { benchNQueens(b, 5) }
func BenchmarkNQueens7(b *testing.B) { benchNQueens(b, 7) }
func BenchmarkNQueens9(b *testing.B) { benchNQueens(b, 9) }