Add licence and installation instructions.
[kaya.git] / test / games / chess / test_chess_state.rb
blob38b1ee875eff73ac0ff7e48facef12a0e29eb015
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
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.
8 require 'test/unit'
9 require 'games/chess/state'
10 require 'games/chess/piece'
11 require 'enumerator'
12 require 'helpers/validation_helper'
14 class TestChessState < Test::Unit::TestCase
15   include ValidationHelper
16   
17   def setup
18     @board = Chess::Board.new(Point.new(8, 8))
19     @state = Chess::State.new(@board, Chess::Move, Chess::Piece)
20   end
21   
22   def test_board
23     assert_same @board, @state.board
24   end
25   
26   def test_setup
27     @state.setup
28     
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
33     
34     assert_piece :white, :queen, 3, 7
35     assert_piece :black, :bishop, 5, 0
36     assert_piece :black, :rook, 0, 0
37     
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
42   end
43   
44   def test_row
45     assert_equal 2, @state.row(2, :black)
46     assert_equal 5, @state.row(2, :white)
47   end
48   
49   def test_colors
50     assert_equal [:white, :black], @state.to_enum(:each_color).to_a
51   end
52   
53   def test_opposite_turn
54     assert_equal :white, @state.opposite_turn(:black)
55     assert_equal :black, @state.opposite_turn(:white)
56   end
57   
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)
61   end
62   
63   def test_direction
64     assert_equal Point.new(0, -1), @state.direction(:white)
65     assert_equal Point.new(0, 1), @state.direction(:black)
66   end
67   
68   def test_dup
69     other = @state.dup
70     assert_not_same @state, other
71     assert_not_same @state.board, other.board
72     assert_not_same @state.castling_rights, other.castling_rights
73   end
74   
75   def test_new_piece
76     piece_factory = mock('piece factory') do |m|
77       m.expects(:new).with(:white, :knight)
78     end
79     @state = Chess::State.new(@board, Chess::Move, piece_factory)
80     @state.piece_factory.new(:white, :knight)
81   end
82 end