Fix minishogi notation, enabling play against gnuminishogi.
[kaya/ydirson.git] / test / test_animations.rb
bloba6e3833f59025abdebfb50d39dc60f85e661c15b
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 'animations'
10 require 'board/point_converter'
11 require 'helpers/animation_test_helper'
12 require 'helpers/stubs'
13 require 'rubygems'
15 class FakeAnimator
16   include Animations
17   
18   class Board
19     include PointConverter
20     def unit
21       Qt::Point.new(50, 50)
22     end
23     
24     def flipped?
25       false
26     end
27     
28     def raise(item)
29     end
30     
31     def lower(item)
32     end
33   end
34   
35   attr_reader :board
36   def initialize
37     @board = Board.new
38   end
39 end
41 class TestAnimations < Test::Unit::TestCase
42   def setup
43     @field = FakeAnimationField.new
44     @c = FakeAnimator.new
45   end
46   
47   def test_disappear
48     item = GeneralMock.new
49     @field.run @c.disappear(item, "disappear")
50     @field.run_test
51     
52     assert_equal [:opacity=, [1.0]], item.calls.shift
53     assert_equal [:visible=, [true]], item.calls.shift
54     
55     old_op = 1.0
56     while old_op > 0.0
57       method, args = item.calls.shift
58       break unless method == :opacity=
59       assert_operator args.first, :<=, old_op
60       old_op = args.first
61     end
62     
63     assert_equal [:remove, []], item.calls.shift
64     assert_equal [], item.calls
65   end
66   
67   def test_appear
68     item = GeneralMock.new
69     @field.run @c.appear(item, "appear")
70     @field.run_test
71     
72     assert_equal [:opacity=, [0.0]], item.calls.shift
73     assert_equal [:visible=, [true]], item.calls.shift
74     
75     old_op = 0.0
76     while true
77       method, args = item.calls.shift
78       break unless method == :opacity=
79       assert_operator args.first, :>=, old_op
80       old_op = args.first
81     end
82     
83     assert_equal [], item.calls
84   end
85   
86   def test_movement
87     item = GeneralMock.new
88     @field.run @c.movement(item, Point.new(3, 4), Point.new(5, 6), Path::Linear)
89     @field.run_test
90     
91     old_p = nil
92     while not item.calls.empty?
93       method, args = item.calls.shift
94       assert_equal :pos=, method
95       p = args.first
96       assert_not_nil p
97       if old_p
98         assert_operator old_p.x, :<=, p.x
99         assert_operator old_p.y, :<=, p.y
100         delta = p - old_p
101         assert_in_delta 1.0, (delta.y.to_f / delta.x), 1e-5 if delta.x.abs >= 1e-5
102       end
103       old_p = p
104     end
105   end