diff options
| -rw-r--r-- | board.rb | 4 | ||||
| -rw-r--r-- | player.rb | 6 | ||||
| -rw-r--r-- | spec/board_spec.rb | 8 | ||||
| -rw-r--r-- | spec/player_spec.rb | 14 |
4 files changed, 29 insertions, 3 deletions
@@ -23,4 +23,8 @@ class Board rescue end end + + def update_cell(row_index, column_index, value) + @board[row_index][column_index] = value + end end @@ -8,4 +8,10 @@ class Player @insignia = insignia @board = board end + + def move(coordinates) + raise ArgumentError if coordinates.nil? + + @board.update_cell(coordinates[0], coordinates[1], @insignia) + end end diff --git a/spec/board_spec.rb b/spec/board_spec.rb index 3e04210..a5c45ef 100644 --- a/spec/board_spec.rb +++ b/spec/board_spec.rb @@ -36,4 +36,12 @@ EOF @board.transform_coordinates('booya,kacha').must_be_nil end end + + describe '#update_cell' do + it 'updates a given cell with a given value' do + value = 'X' + @board.update_cell(1, 2, value) + @board.instance_variable_get(:@board)[1][2].must_equal value + end + end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index 4dee7e7..d33ac05 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -15,17 +15,25 @@ describe Player do describe '#move' do before do - board = Board.new - @player = Player.new(Player::INSIGNIAS[:x], board) + @board = Board.new + @player = Player.new(Player::INSIGNIAS[:x], @board) end - it 'raises an ArgumentError given invalid coordinates' do + it 'raises an ArgumentError given nil coordinates' do + -> { @player.move(nil) }.must_raise ArgumentError end it 'adds a piece to the correct coordinates on `board`' do + @player.move([1, 2]) + @board.instance_variable_get(:@board)[1][2].must_equal \ + @player.instance_variable_get(:@insignia) end it 'uses the correct insignia for the move' do + insignia = Player::INSIGNIAS[:o] + player = Player.new(insignia, @board) + player.move([0, 1]) + @board.instance_variable_get(:@board)[0][1].must_equal insignia end end end |
