from unittest.case import TestCase from tudelft.utilities.tools.queue import PriorityQueue from tudelft.utilities.tools.comparator import Comparator from typing import Tuple class MyComparator(Comparator[Tuple[int, str]]): def compare(self, o1:Tuple[int, str], o2:Tuple[int, str])-> int: return -1 if o1[1] < o2[1] else 1 if o1[1]>o2[1] else 0 class queueTest(TestCase): def testSimple(self): q=PriorityQueue() q.append(2) q.append(3) q.append(1) print(str(q)) self.assertEqual(1,q[0]) self.assertEqual(2,q[1]) self.assertEqual(3,q[2]) self.assertEqual("[1, 2, 3]", str(q)) def testCustomSort(self): q=PriorityQueue([('a',1),('a',3)], MyComparator()) self.assertEqual("[('a', 1), ('a', 3)]", str(q)) q.append(('b',2)) self.assertEqual("[('a', 1), ('b', 2), ('a', 3)]", str(q))