Пример #1
0
 def setUp(self):
     self.seq = SequenceQueue()
Пример #2
0
class TestSequenceQueue(unittest.TestCase):
    def setUp(self):
        self.seq = SequenceQueue()

    def test_add_range(self):
        self.seq.put(1, 10)
        self.assertEqual(self.seq._list, [(1, 10)])
        self.assertEqual(len(self.seq), 10)
        self.seq.put(21, 30)
        self.assertEqual(self.seq._list, [(1, 10), (21, 30)])
        self.assertEqual(len(self.seq), 20)
        self.seq.put(31, 40)
        self.assertEqual(self.seq._list, [(1, 10), (21, 40)])
        self.assertEqual(len(self.seq), 30)

    def test_get(self):
        self.seq.put(1, 10)
        self.assertEqual(self.seq._list, [(1, 10)])
        self.assertEqual(len(self.seq), 10)
        self.assertEqual(self.seq.get(10), [(1, 10)])
        self.assertEqual(self.seq._list, [])
        self.assertEqual(len(self.seq), 0)
        self.seq.put(1, 100)
        self.assertEqual(self.seq._list, [(1, 100)])
        self.assertEqual(len(self.seq), 100)
        self.assertEqual(self.seq.get(10), [(91, 100)])
        self.assertEqual(self.seq._list, [(1, 90)])
        self.assertEqual(len(self.seq), 90)
        self.assertEqual(self.seq.get(100), [(1, 90)])
        self.assertEqual(self.seq._list, [])
        self.assertEqual(len(self.seq), 0)
        self.seq.put(1, 10)
        self.seq.put(21, 30)
        self.assertEqual(self.seq._list, [(1, 10), (21, 30)])
        self.assertEqual(len(self.seq), 20)
        self.assertEqual(self.seq.get(12), [(21, 30), (9, 10)])
        self.assertEqual(self.seq._list, [(1, 8)])
        self.assertEqual(len(self.seq), 8)

    def test_delete(self):
        self.seq.put(7, 10)
        self.seq.put(21, 25)
        self.assertEqual(self.seq._list, [(7, 10), (21, 25)])
        self.assertEqual(len(self.seq), 9)
        self.seq.delete(25)
        self.assertEqual(self.seq._list, [(7, 10), (21, 24)])
        self.assertEqual(len(self.seq), 8)
        self.seq.delete(23)
        self.assertEqual(self.seq._list, [(7, 10), (21, 23)])
        self.assertEqual(len(self.seq), 7)
        self.seq.delete(21)
        self.assertEqual(self.seq._list, [(7, 10), (21, 22)])
        self.assertEqual(len(self.seq), 6)
        self.seq.delete(15)
        self.assertEqual(self.seq._list, [(7, 10), (20, 21)])
        self.assertEqual(len(self.seq), 6)
        self.seq.delete(10)
        self.assertEqual(self.seq._list, [(7, 9), (19, 20)])
        self.assertEqual(len(self.seq), 5)
        self.seq.delete(8)
        self.assertEqual(self.seq._list, [(7, 8), (18, 19)])
        self.assertEqual(len(self.seq), 4)
        self.seq.delete(7)
        self.assertEqual(self.seq._list, [(7, 7), (17, 18)])
        self.assertEqual(len(self.seq), 3)
        self.seq.delete(7)
        self.assertEqual(self.seq._list, [(16, 17)])
        self.assertEqual(len(self.seq), 2)
        self.seq.delete(17)
        self.assertEqual(self.seq._list, [(16, 16)])
        self.assertEqual(len(self.seq), 1)
        self.seq.delete(16)
        self.assertEqual(self.seq._list, [])
        self.assertEqual(len(self.seq), 0)