Improved shogi theme. Add shadows.
[kaya.git] / test / test_animation_field.rb
blob912b3af501629e6f1c60e3cfc10e62918f646eb6
1 require 'test/unit'
2 require 'animation_field'
3 require 'qtutils'
5 class TestAnimationField < Test::Unit::TestCase
6   def setup
7     # remove connection with timer
8     Qt::Timer.stubs(:every) {}
9     
10     # create a field with an accessor for actions
11     @field = AnimationField.new(10)
12     @field.metaclass_eval do
13       attr_reader :actions
14     end
15   end
16   
17   def test_initialization
18     assert_equal [], @field.actions
19   end
20   
21   def test_tick_empty
22     @field.tick(1.0)
23     assert_equal [], @field.actions
24   end
25   
26   def test_tick_exit
27     action = mock("action") {|x| x.expects(:[]).with(1.0).returns(true) }
28     @field.run action
29     @field.tick(1.0)
30     assert_equal [], @field.actions
31   end
32   
33   def test_long_action
34     @field.run create_action(10)
35     10.times do |i|
36       assert_equal 1, @field.actions.size
37       @field.tick(i.to_f)
38     end
39     
40     assert_equal [], @field.actions
41   end
42   
43   def test_multiple_actions
44     @field.run create_action(3)
45     @field.run create_action(2)
46     
47     assert_equal 2, @field.actions.size
48     @field.tick 1.0
49     assert_equal 2, @field.actions.size
50     @field.tick 2.0
51     assert_equal 1, @field.actions.size
52     @field.tick 3.0
53     assert_equal [], @field.actions
54   end
55   
56 private
57   def create_action(length)
58     x = length
59     lambda { x -= 1; x <= 0 }
60   end
61 end