fix process#alive? to not raise on no such file
[god.git] / test / test_conditions_tries.rb
blob44ae07bd87883b8ca5b9182581bd914db790810a
1 require File.dirname(__FILE__) + '/helper'
3 class TestConditionsTries < Test::Unit::TestCase
4   def setup
5     @c = Conditions::Tries.new
6     @c.times = 3
7     @c.prepare
8   end
9   
10   def test_prepare_should_create_timeline
11     assert 3, @c.instance_variable_get(:@timeline).instance_variable_get(:@max_size)
12   end
13   
14   def test_test_should_return_true_if_called_three_times_within_one_second
15     assert !@c.test
16     assert !@c.test
17     assert @c.test
18   end
19   
20   def test_test_should_return_false_on_fourth_call_if_called_three_times_within_one_second
21     3.times { @c.test }
22     assert !@c.test
23   end
24 end
26 class TestConditionsTriesWithin < Test::Unit::TestCase
27   def setup
28     @c = Conditions::Tries.new
29     @c.times = 3
30     @c.within = 1.seconds
31     @c.prepare
32   end
33   
34   def test_test_should_return_true_if_called_three_times_within_one_second
35     assert !@c.test
36     assert !@c.test
37     assert @c.test
38   end
39   
40   def test_test_should_return_false_if_called_three_times_within_two_seconds
41     assert !@c.test
42     assert !@c.test
43     assert sleep(1.1)
44     assert !@c.test
45   end
46 end