This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
forked from tiyd-rails-2015-08/battleship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
battleship_test2.rb
executable file
·126 lines (100 loc) · 2.98 KB
/
battleship_test2.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
require 'minitest/autorun'
require 'minitest/pride'
require './battleship'
$mock_inputs = []
def get_user_input
$mock_inputs.shift
end
def standard_placement
["A1","Down","A3","Down","A5","Down","A7","Down","A9","Down"]
end
def standard_ships
"2, 3, 3, 4, 5"
end
def starting_game_status
%Q{SHOTS TAKEN:
1 2 3 4 5 6 7 8 9 10
-----------------------------------------
A | | | | | | | | | | |
B | | | | | | | | | | |
C | | | | | | | | | | |
D | | | | | | | | | | |
E | | | | | | | | | | |
F | | | | | | | | | | |
G | | | | | | | | | | |
H | | | | | | | | | | |
I | | | | | | | | | | |
J | | | | | | | | | | |
-----------------------------------------
YOUR BOARD:
1 2 3 4 5 6 7 8 9 10
-----------------------------------------
A | O | | O | | O | | O | | O | |
B | O | | O | | O | | O | | O | |
C | | | O | | O | | O | | O | |
D | | | | | | | O | | O | |
E | | | | | | | | | O | |
F | | | | | | | | | | |
G | | | | | | | | | | |
H | | | | | | | | | | |
I | | | | | | | | | | |
J | | | | | | | | | | |
-----------------------------------------
}
end
class BattleshipTest < Minitest::Test
def self.test_order
:alpha
end
def test_01_grid_can_be_bigger
grid = Grid.new([20,20])
assert_equal grid.size, [20,20]
grid = Grid.new
assert_equal grid.size, [10,10]
refute_equal grid.size, [9,9]
grid = Grid.new([701,701])
assert_equal grid.size, [701,701]
grid = Grid.new([10, 20])
assert_equal grid.size, [10,20]
end
def test_02_big_grid_tracks_fires
grid = Grid.new([30,30])
ship = Ship.new(3)
assert grid.place_ship(ship,15,15,true)
assert grid.fire_at(15,15)
assert_equal ship.shots_received.length, 1
refute grid.fire_at(1,1)
assert_equal ship.shots_received.length, 1
end
def test_03_cannot_create_too_big_grid
assert_raises(InvalidGridSizeError) do
grid = Grid.new([703,703])
end
end
def test_05_accept_any_case_response
$mock_inputs.clear
$mock_inputs += "David"
$mock_inputs += "David2"
$mock_inputs += "normal"
$mock_inputs += standard_ships
$mock_inputs += "10x10"
$mock_inputs += standard_placement.map(&:downcase)
assert_output(starting_game_status) do
game = Game.new(HumanPlayer.new("Tester"),ComputerPlayer.new)
end
end
def test_06_can_exit_during_placement
end
def test_07_can_exit_during_call_shot
end
def test_08_display_grid_every_turn
end
def test_09_enable_salvo_mode
end
def test_10_salvo_mode_call_shot_is_num_ships
end
def test_11_introduction_collect_mode
end
def test_12_introduction_collect_players
end
end