source: utilitiespy/test/tools/queueTest.py@ 1234

Last change on this file since 1234 was 1231, checked in by wouter, 6 weeks ago

#388 chagned add to append

File size: 969 bytes
Line 
1from unittest.case import TestCase
2from tudelft.utilities.tools.queue import PriorityQueue
3from tudelft.utilities.tools.comparator import Comparator
4from typing import Tuple
5
6
7class MyComparator(Comparator[Tuple[int, str]]):
8 def compare(self, o1:Tuple[int, str], o2:Tuple[int, str])-> int:
9 return -1 if o1[1] < o2[1] else 1 if o1[1]>o2[1] else 0
10
11class queueTest(TestCase):
12 def testSimple(self):
13 q=PriorityQueue()
14 q.append(2)
15 q.append(3)
16 q.append(1)
17
18 print(str(q))
19
20 self.assertEqual(1,q[0])
21 self.assertEqual(2,q[1])
22 self.assertEqual(3,q[2])
23 self.assertEqual("[1, 2, 3]", str(q))
24
25
26
27
28 def testCustomSort(self):
29 q=PriorityQueue([('a',1),('a',3)], MyComparator())
30 self.assertEqual("[('a', 1), ('a', 3)]", str(q))
31 q.append(('b',2))
32 self.assertEqual("[('a', 1), ('b', 2), ('a', 3)]", str(q))
33
Note: See TracBrowser for help on using the repository browser.