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