def test_add_existing_item(self): s = SortedSet() s.add(1) s.add(1) s.add(1) self.assertEqual(s, set([1])) self.assertEqual(list(s), [1])
def test_pop_no_sort_key(self): s = SortedSet([3, 1, 4]) s.add(2) self.assertEqual(s.pop(), 1) self.assertEqual(s.pop(), 2) self.assertEqual(s.pop(), 3) self.assertEqual(s.pop(), 4)
def test_pop_sort_key(self): items = [ ProcessorState(pc=3), ProcessorState(pc=1), ProcessorState(pc=4) ] s = SortedSet(items, key=attrgetter('pc')) s.add(ProcessorState(pc=2)) self.assertEqual(s.pop().pc, 1) self.assertEqual(s.pop().pc, 2) self.assertEqual(s.pop().pc, 3) self.assertEqual(s.pop().pc, 4)
def test_len(self): s = SortedSet([1, 2]) s.add(3) self.assertEqual(len(s), 3)
def test_len_initially_0(self): s = SortedSet() self.assertEqual(len(s), 0)
def test_ctor(self): s = SortedSet([1, 2]) self.assertTrue(1 in s) self.assertTrue(2 in s)
def test_pop_empty(self): s = SortedSet() self.assertRaises(KeyError, s.pop)
def test_remove_nonexistent_item(self): s = SortedSet() self.assertRaises(KeyError, s.remove, 1)
def test_remove(self): s = SortedSet([1, 2, 3]) s.remove(2) self.assertEqual(s, set([1, 3])) self.assertEqual(list(s), [1, 3])
def test_add_new_item(self): s = SortedSet() s.add(1) self.assertEqual(s, set([1]))
def test_eq_SortedSet(self): s = SortedSet([1, 2]) self.assertTrue(s == SortedSet([1, 2])) self.assertFalse(s == SortedSet([1, 2, 3]))
def test_iter(self): s = SortedSet([2, 1, 3]) s.add(5) s.add(4) self.assertEqual(list(s), [1, 2, 3, 4, 5])
def test_contains(self): s = SortedSet([1]) s.add(2) self.assertTrue(1 in s) self.assertTrue(2 in s) self.assertFalse(3 in s)
def test_ctor(self): queue = TraceQueue() self.assertEqual(queue.traced_processor_states, set()) self.assertEqual(queue.untraced_processor_states, SortedSet())