Skip to content

Commit

Permalink
added undo test and its passing
Browse files Browse the repository at this point in the history
  • Loading branch information
jphager2 committed May 5, 2014
1 parent 2e8bc13 commit 55f847f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def at(x,y)

def undo
move = @moves.pop
piece = at(*move[:piece][:point_a])
new_piece = piece.class.new(*move[:piece][:point_b])
piece = at(*move[:piece][:point_b])
new_piece = piece.class.new(*move[:piece][:point_a])
capture = move[:capture]

@board.remove(piece)
Expand Down
Binary file added ruby-chess-0.0.1.gem
Binary file not shown.
Binary file added ruby-chess-0.0.2.gem
Binary file not shown.
2 changes: 1 addition & 1 deletion ruby-chess.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ files.push('LICENSE', 'README.md', 'rakefile')

Gem::Specification.new do |s|
s.name = 'ruby-chess'
s.version = '0.0.1'
s.version = '0.0.2'
s.date = "#{Time.now.strftime("%Y-%m-%d")}"
s.homepage = 'https://github.com/jphager2/chess'
s.summary = 'Chess game logic in Ruby'
Expand Down
6 changes: 0 additions & 6 deletions test/game_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ def test_can_play_black
assert_kind_of BlackPawn, this_game.at(6,5)
end

def test_game_can_undo_moves
game = white_in_check
2.times {game.undo}
assert_kind_of EmptySpace, game.at(1,3)
end

def test_cannot_play_while_in_check
game = white_in_check
assert_raises(Game::IllegalMove) do
Expand Down
40 changes: 40 additions & 0 deletions test/undo_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require_relative '../lib/chess'

require 'minitest/autorun'

class UndoTest < Minitest::Test

def white_in_check
game = Game.new
game.play([4,1],[4,3])
game.play([3,6],[3,5])
game.play([6,1],[6,3])
game.play([2,7],[6,3])
game
end

def test_game_can_undo_moves
game = white_in_check
2.times {game.undo}
assert_kind_of EmptySpace, game.at(6,3)
end

def test_undo_adds_removed_pieces
game = Game.new
game.play([4,1],[4,3])
game.play([3,6],[3,4])
game.play([4,3],[3,4])
game.undo
assert_kind_of BlackPawn, game.at(3,4)
end

def test_undo_reverses_the_last_move
game = Game.new
game.play([4,1],[4,3])
game.play([3,6],[3,4])
game.play([4,3],[3,4])
game.undo
assert_kind_of WhitePawn, game.at(4,3)
end

end

0 comments on commit 55f847f

Please sign in to comment.