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