-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueen_attack_test.rb
executable file
·128 lines (114 loc) · 2.89 KB
/
queen_attack_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
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
#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
require 'minitest/autorun'
require_relative 'queen_attack'
class QueensTest < Minitest::Test
def test_default_positions
queens = Queens.new
assert_equal [0, 3], queens.white
assert_equal [7, 3], queens.black
end
def test_specific_placement
skip
queens = Queens.new(white: [3, 7], black: [6, 1])
assert_equal [3, 7], queens.white
assert_equal [6, 1], queens.black
end
def test_multiple_boards_simultaneously
skip
queens1 = Queens.new(white: [3, 7], black: [6, 1])
queens2 = Queens.new(white: [5, 4], black: [7, 7])
assert_equal [3, 7], queens1.white
assert_equal [6, 1], queens1.black
assert_equal [5, 4], queens2.white
assert_equal [7, 7], queens2.black
end
def test_cannot_occupy_same_space
skip
assert_raises ArgumentError do
Queens.new(white: [2, 4], black: [2, 4])
end
end
def test_string_representation # rubocop:disable Metrics/MethodLength
skip
queens = Queens.new(white: [2, 4], black: [6, 6])
board = <<-BOARD.chomp
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ W _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ B _
_ _ _ _ _ _ _ _
BOARD
assert_equal board, queens.to_s
end
def test_another_string_representation # rubocop:disable Metrics/MethodLength
skip
queens = Queens.new(white: [7, 1], black: [0, 0])
board = <<-BOARD.chomp
B _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ W _ _ _ _ _ _
BOARD
assert_equal board, queens.to_s
end
# rubocop:disable Metrics/MethodLength
def test_yet_another_string_representation
skip
queens = Queens.new(white: [4, 3], black: [3, 4])
board = <<-BOARD.chomp
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ B _ _ _
_ _ _ W _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
_ _ _ _ _ _ _ _
BOARD
assert_equal board, queens.to_s
end
def test_cannot_attack
skip
queens = Queens.new(white: [2, 3], black: [4, 7])
assert !queens.attack?
end
# rubocop:enable Metrics/MethodLength
def test_can_attack_on_same_row
skip
queens = Queens.new(white: [2, 4], black: [2, 7])
assert queens.attack?
end
def test_can_attack_on_same_column
skip
queens = Queens.new(white: [5, 4], black: [2, 4])
assert queens.attack?
end
def test_can_attack_on_diagonal
skip
queens = Queens.new(white: [1, 1], black: [6, 6])
assert queens.attack?
end
def test_can_attack_on_other_diagonal
skip
queens = Queens.new(white: [0, 6], black: [1, 7])
assert queens.attack?
end
def test_can_attack_on_yet_another_diagonal
skip
queens = Queens.new(white: [4, 1], black: [6, 3])
assert queens.attack?
end
def test_can_attack_on_a_diagonal_slanted_the_other_way
skip
queens = Queens.new(white: [6, 1], black: [1, 6])
assert queens.attack?
end
end