Debian Codegraph @

ruby/tests/test_utils.rb

raw
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 require 'test_tools'
19 require 'minitest/unit'
20
21 class UtilsTest < MiniTest::Test
22 include Qpid::Proton
23
24 # Make sure Schedule puts tasks in proper order.
25 def test_schedule_empty
26 s = Schedule.new
27 assert_empty s
28 assert_nil s.next_tick
29 assert_nil s.pop(nil)
30 end
31
32 def test_schedule_insert_pop
33 s = Schedule.new
34 [3,5,4].each { |i| s.insert(Time.at(i), i) }
35 assert_equal Time.at(3), s.next_tick
36 assert_nil s.pop(Time.at(2))
37 assert_equal [3,4], [s.pop(Time.at(4)), s.pop(Time.at(4))]
38 refute_empty s
39 assert_nil s.pop(Time.at(4.9))
40 assert_equal Time.at(5), s.next_tick
41 assert_equal 5, s.pop(Time.at(5))
42 assert_empty s
43 end
44
45 # Make sure we sort by time and don't change order if same time
46 def test_schedule_sort
47 s = Schedule.new
48 [4.0, 3, 5, 1, 4.1, 4.2 ].each { |n| s.insert(Time.at(n.to_i), n) }
49 [1, 3, 4.0, 4.1, 4.2].each { |n| assert_equal n, s.pop(Time.at(4)) }
50 refute_empty s # Not empty but nothing due until time 5
51 assert_equal Time.at(5), s.next_tick
52 assert_nil s.pop(Time.at(4))
53 assert_equal 5, s.pop(Time.at(5))
54 end
55
56 def test_schedule_clear
57 s = Schedule.new
58 [3, 5].each { |n| s.insert(Time.at(n.to_i), n) }
59 refute_empty s
60 s.clear
61 assert_empty s
62 end
63 end