Update Changelog
[profile/ivi/libgee.git] / tests / testpriorityqueue.vala
1 /* testpriorityqueue.vala
2  *
3  * Copyright (C) 2009  Didier Villevalois
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *
19  * Authors:
20  *      Didier 'Ptitjes Villevalois <ptitjes@free.fr>
21  */
22
23 using Gee;
24
25 public class PriorityQueueTests : QueueTests {
26
27         public PriorityQueueTests () {
28                 base ("PriorityQueue");
29                 add_test ("[PriorityQueue] poll gives minimum", test_poll_gives_minimum);
30         }
31
32         public override void set_up () {
33                 test_collection = new PriorityQueue<string> ();
34         }
35
36         public override void tear_down () {
37                 test_collection = null;
38         }
39
40         private void test_poll_gives_minimum () {
41                 var test_queue = test_collection as Gee.Queue<string>;
42
43                 // Check the queue exists
44                 assert (test_queue != null);
45
46                 // Add two elements and remove the greatest
47                 assert (test_queue.offer ("one"));
48                 assert (test_queue.offer ("two"));
49                 assert (test_queue.peek () == "one");
50                 assert (test_queue.remove ("two"));
51                 assert (test_queue.peek () == "one");
52                 assert (test_queue.poll () == "one");
53
54                 // Add twelve elements
55                 assert (test_queue.offer ("one"));
56                 assert (test_queue.offer ("two"));
57                 assert (test_queue.offer ("three"));
58                 assert (test_queue.offer ("four"));
59                 assert (test_queue.offer ("five"));
60                 assert (test_queue.offer ("six"));
61                 assert (test_queue.offer ("seven"));
62                 assert (test_queue.offer ("eight"));
63                 assert (test_queue.offer ("nine"));
64                 assert (test_queue.offer ("ten"));
65                 assert (test_queue.offer ("eleven"));
66                 assert (test_queue.offer ("twelve"));
67
68                 assert (test_queue.peek () == "eight");
69                 assert (test_queue.poll () == "eight");
70                 assert (test_queue.peek () == "eleven");
71                 assert (test_queue.poll () == "eleven");
72                 assert (test_queue.peek () == "five");
73                 assert (test_queue.poll () == "five");
74                 assert (test_queue.peek () == "four");
75                 assert (test_queue.poll () == "four");
76                 assert (test_queue.peek () == "nine");
77                 assert (test_queue.poll () == "nine");
78                 assert (test_queue.peek () == "one");
79                 assert (test_queue.poll () == "one");
80                 assert (test_queue.peek () == "seven");
81                 assert (test_queue.poll () == "seven");
82                 assert (test_queue.peek () == "six");
83                 assert (test_queue.poll () == "six");
84                 assert (test_queue.peek () == "ten");
85                 assert (test_queue.poll () == "ten");
86                 assert (test_queue.peek () == "three");
87                 assert (test_queue.poll () == "three");
88                 assert (test_queue.peek () == "twelve");
89                 assert (test_queue.poll () == "twelve");
90                 assert (test_queue.peek () == "two");
91                 assert (test_queue.poll () == "two");
92
93                 // Add decreasing elements
94                 assert (test_queue.offer ("2"));
95                 assert (test_queue.offer ("1"));
96
97                 
98                 assert (test_queue.peek () == "1");
99                 assert (test_queue.poll () == "1");
100                 assert (test_queue.peek () == "2");
101                 assert (test_queue.poll () == "2");
102         }
103 }