Source

puzzle_nodes / 13 / test / board_test.rb

Full commit
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