|
1 | 1 | require 'microtest' |
| 2 | +require 'ae' |
2 | 3 | require 'ae/legacy' |
3 | 4 |
|
4 | 5 | require 'pqueue' |
5 | 6 |
|
6 | | -class TC_PQueue < MicroTest::TestCase |
| 7 | +class PQueueTest < MicroTest::TestCase |
7 | 8 | include AE::Legacy::Assertions |
8 | 9 |
|
9 | 10 | ARY_TEST = [2,6,1,3,8,15,0,-4,7,8,10] |
@@ -152,5 +153,26 @@ def test_array_copied |
152 | 153 | q.pop |
153 | 154 | assert_not_equal(q, r) |
154 | 155 | end |
155 | | -end |
156 | 156 |
|
| 157 | + def test_reheap |
| 158 | + q = PQueue.new([2,4,5]) |
| 159 | + q << 6 |
| 160 | + q.to_a.assert == [2,4,5,6] |
| 161 | + q << 1 |
| 162 | + q.to_a.assert == [1,2,4,5,6] |
| 163 | + q << 3 |
| 164 | + q.to_a.assert == [1,2,3,4,5,6] |
| 165 | + |
| 166 | + q = PQueue.new([100,5,25]) |
| 167 | + q.to_a.assert == [5,25,100] |
| 168 | + q << 17 |
| 169 | + q.to_a.assert == [5,17,25,100] |
| 170 | + q << 0 |
| 171 | + q.to_a.assert == [0,5,17,25,100] |
| 172 | + q << -5 |
| 173 | + q.to_a.assert == [-5,0,5,17,25,100] |
| 174 | + q << 100 |
| 175 | + q.to_a.assert == [-5,0,5,17,25,100,100] |
| 176 | + end |
| 177 | + |
| 178 | +end |
0 commit comments