예제 #1
0
 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])
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 def test_len(self):
     s = SortedSet([1, 2])
     s.add(3)
     self.assertEqual(len(s), 3)
예제 #5
0
 def test_len_initially_0(self):
     s = SortedSet()
     self.assertEqual(len(s), 0)
예제 #6
0
 def test_ctor(self):
     s = SortedSet([1, 2])
     self.assertTrue(1 in s)
     self.assertTrue(2 in s)
예제 #7
0
 def test_pop_empty(self):
     s = SortedSet()
     self.assertRaises(KeyError, s.pop)
예제 #8
0
 def test_remove_nonexistent_item(self):
     s = SortedSet()
     self.assertRaises(KeyError, s.remove, 1)
예제 #9
0
 def test_remove(self):
     s = SortedSet([1, 2, 3])
     s.remove(2)
     self.assertEqual(s, set([1, 3]))
     self.assertEqual(list(s), [1, 3])
예제 #10
0
 def test_add_new_item(self):
     s = SortedSet()
     s.add(1)
     self.assertEqual(s, set([1]))
예제 #11
0
 def test_eq_SortedSet(self):
     s = SortedSet([1, 2])
     self.assertTrue(s == SortedSet([1, 2]))
     self.assertFalse(s == SortedSet([1, 2, 3]))
예제 #12
0
 def test_iter(self):
     s = SortedSet([2, 1, 3])
     s.add(5)
     s.add(4)
     self.assertEqual(list(s), [1, 2, 3, 4, 5])
예제 #13
0
 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)
예제 #14
0
 def test_ctor(self):
     queue = TraceQueue()
     self.assertEqual(queue.traced_processor_states, set())
     self.assertEqual(queue.untraced_processor_states, SortedSet())