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.
10 require 'helpers/animation_test_helper'
12 class TestChessAnimator < Test::Unit::TestCase
13 include AnimationAssertions
15 FakeItem = Struct.new(:name)
18 @chess = Game.get(:chess)
20 Point.new(3, 4) => FakeItem.new(@chess.piece.new(:white, :king)),
21 Point.new(3, 1) => FakeItem.new(@chess.piece.new(:black, :king)),
22 Point.new(7, 7) => FakeItem.new(@chess.piece.new(:black, :queen))
24 @board = FakeBoard.new(@items)
26 @animator = @chess.animator.new(@board)
28 include StubbedAnimations
30 @state = @chess.state.new
34 @state.board[Point.new(3, 4)] = @chess.piece.new(:white, :king)
35 @state.board[Point.new(3, 1)] = @chess.piece.new(:black, :king)
36 @state.board[Point.new(7, 7)] = @chess.piece.new(:black, :queen)
38 anim = @animator.warp(@state)
39 assert_animation(:group, anim) do |args|
45 @state.board[Point.new(4, 3)] = @chess.piece.new(:white, :king)
46 @state.board[Point.new(3, 1)] = @chess.piece.new(:black, :king)
47 @state.board[Point.new(7, 7)] = @chess.piece.new(:black, :queen)
49 anim = @animator.warp(@state)
50 assert_animation(:group, anim) do |args|
51 assert_equal 2, args.size
53 appear, disappear = args.sort
54 assert_animation :instant_appear, appear
55 assert_animation :instant_disappear, disappear
59 def test_simple_noninstant_warp
60 @state.board[Point.new(4, 3)] = @chess.piece.new(:white, :king)
61 @state.board[Point.new(3, 1)] = @chess.piece.new(:black, :king)
62 @state.board[Point.new(7, 7)] = @chess.piece.new(:black, :queen)
64 anim = @animator.warp(@state, :instant => false)
65 assert_animation(:group, anim) do |args|
66 assert_equal 2, args.size
68 appear, disappear = args.sort
69 assert_animation :appear, appear
70 assert_animation :disappear, disappear
74 def test_simple_forward
75 move = @state.move_factory.new(Point.new(7, 7), Point.new(5, 5))
76 @state.board[Point.new(3, 4)] = @chess.piece.new(:white, :king)
77 @state.board[Point.new(3, 1)] = @chess.piece.new(:black, :king)
78 @state.board[Point.new(5, 5)] = @chess.piece.new(:black, :queen)
80 anim = @animator.forward(@state, move)
82 assert_animation(:sequence, anim) do |args|
83 assert_equal 2, args.size
85 warp, main = args.sort_by {|a| a.args.size }
87 assert_animation(:group, warp) {|a| assert_equal [], a }
88 assert_animation(:group, main) do |args|
89 mov = args.find {|a| a.animation == :movement }
90 assert_animation(:movement, mov) do |args|
91 piece, src, dst = args
92 assert_equal FakeItem.new(@chess.piece.new(:black, :queen)), piece
93 assert_equal Point.new(7, 7), src
94 assert_equal Point.new(5, 5), dst