Commits

Steven! Ragnarök committed 410212e

Add some simple tests.

Comments (0)

Files changed (4)

13/test/.simple_validator_test.rb.swp

Binary file added.

13/test/board_test.rb

+require 'minitest/unit'
+require 'minitest/autorun'
+require './lib/board'
+
+class BoardTest < MiniTest::Unit::TestCase
+  def setup
+    @input = <<BOARD
+bR bN bB bQ bK bB bN bR
+bP bP bP bP bP bP bP bP
+-- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- --
+-- -- -- -- -- -- -- --
+wP wP wP wP wP wP wP wP
+wR wN wB wQ wK wB wN wR
+BOARD
+
+  @board = Board.new @input
+  end
+
+
+  def test_board_reads_board_state_from_input
+    assert_equal "bR", @board[0][0]
+  end
+
+  def test_algebraic_predicate
+    assert @board.algebraic?(:a8), "Expected a8 to be algebraic, wasn't."
+    assert @board.algebraic?(:g4), "Expected g4 to be algebraic, wasn't."
+    refute @board.algebraic?(:d9), "Expected d9 not to be algebraic, was."
+    refute @board.algebraic?(:n7), "Expected n7 not to be algebraic, was."
+  end
+
+  def test_board_responds_to_algebraic_methods
+    assert_equal "bR", @board.a8
+    assert_equal "wK", @board.e1
+    assert_equal "wR", @board.h1
+  end
+end

13/test/piece_test.rb

+require 'minitest/unit'
+require 'minitest/autorun'
+require './lib/piece'
+
+class PieceTest < MiniTest::Unit::TestCase
+  def setup
+    @piece = Piece.new :wP, :b2
+  end
+
+  def test_piece_knows_type
+    assert_equal :P, @piece.type
+  end
+
+  def test_piece_knows_color
+    assert_equal :w, @piece.color
+  end
+
+  def test_piece_validates_moves
+    fail
+  end
+end
+

13/test/simple_validator_test.rb

+require 'minitest/unit'
+require 'minitest/autorun'
+
+class SimpleValidatorTest < MiniTest::Unit::TestCase
+  def test_validates_simple_move_set
+    output = `bin/move_validator simple_board.txt simple_moves.txt`
+    assert_equal `cat simple_results.txt`, output
+  end
+end