-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_test.rb
85 lines (72 loc) · 1.81 KB
/
board_test.rb
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
require 'minitest/autorun'
require 'set'
require_relative 'board'
class BoardTest < MiniTest::Test
def test_board_setup
board = Board.new.setup
assert_equal 32, board.piece_count
[1,2,7,8].each do |rank|
('a'..'h').each do |file|
square = file + rank.to_s
refute_nil board[square], "#{square} should have a piece"
end
end
end
def test_set_piece
board = Board.empty
board["a1"] = Pawn.white
assert_equal 1, board.piece_count
end
def test_piece_retrieval
board = Board.new.setup
piece = board["a1"]
assert_instance_of Rook, piece
end
def test_empty_board
board = Board.empty
assert_equal 0, board.piece_count
assert_equal 0, board.white_count
assert_equal 0, board.black_count
(1..8).each do |rank|
('a'..'h').each do |file|
square = file + rank.to_s
assert_nil board[square], "#{square} should be empty"
end
end
end
def test_setup_return_self
board = Board.new
assert_equal board, board.setup
end
def test_piece_count
board = Board.empty
assert_equal 0, board.black_count
assert_equal 0, board.white_count
assert_equal 0, board.piece_count
board["a2"] = Pawn.white
board["a7"] = Pawn.black
board["b7"] = Pawn.black
assert_equal 3, board.piece_count
assert_equal 1, board.white_count
assert_equal 2, board.black_count
end
def test_board_hash_setup
board = Board.new({
"a1" => Pawn.white,
"a2" => Pawn.black,
"a3" => Pawn.white })
assert_equal Pawn.white, board["a1"]
assert_equal Pawn.black, board["a2"]
assert_equal Pawn.white, board["a3"]
end
def test_symbol_square
board = Board.new({
"a1" => Pawn.white,
:a2 => Pawn.white })
board[:a3] = Pawn.white
assert_equal Pawn.white, board["a1"]
assert_equal Pawn.white, board["a2"]
assert_equal Pawn.white, board["a3"]
assert_equal Pawn.white, board[:a1]
end
end