1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 require 'games/chess/state'
10 require 'games/chess/piece'
12 require 'helpers/validation_helper'
14 class TestChessState < Test::Unit::TestCase
15 include ValidationHelper
18 @board = Chess::Board.new(Point.new(8, 8))
19 @state = Chess::State.new(@board, Chess::Move, Chess::Piece)
23 assert_same @board, @state.board
29 assert_piece :white, :pawn, 4, 6
30 assert_piece :white, :pawn, 2, 6
31 assert_piece :black, :pawn, 2, 1
32 assert_piece :black, :pawn, 7, 1
34 assert_piece :white, :queen, 3, 7
35 assert_piece :black, :bishop, 5, 0
36 assert_piece :black, :rook, 0, 0
38 assert_piece :white, :knight, 6, 7
39 assert_piece :white, :knight, 1, 7
40 assert_piece :black, :knight, 6, 0
41 assert_piece :black, :knight, 1, 0
45 assert_equal 2, @state.row(2, :black)
46 assert_equal 5, @state.row(2, :white)
50 assert_equal [:white, :black], @state.to_enum(:each_color).to_a
53 def test_opposite_turn
54 assert_equal :white, @state.opposite_turn(:black)
55 assert_equal :black, @state.opposite_turn(:white)
58 def test_king_starting_position
59 assert_equal Point.new(4, 7), @state.king_starting_position(:white)
60 assert_equal Point.new(4, 0), @state.king_starting_position(:black)
64 assert_equal Point.new(0, -1), @state.direction(:white)
65 assert_equal Point.new(0, 1), @state.direction(:black)
70 assert_not_same @state, other
71 assert_not_same @state.board, other.board
72 assert_not_same @state.castling_rights, other.castling_rights
76 piece_factory = mock('piece factory') do |m|
77 m.expects(:new).with(:white, :knight)
79 @state = Chess::State.new(@board, Chess::Move, piece_factory)
80 @state.piece_factory.new(:white, :knight)