示例#1
0
    def test_add(self):
        orderedList = OrderedList(True)
        self.assertEqual(orderedList.len(), 0)

        orderedList.add(5)
        self.assertEqual(orderedList.get_all_values(), [5])
        self.assertEqual(orderedList.len(), 1)

        orderedList.add(5)
        self.assertEqual(orderedList.get_all_values(), [5, 5])
        self.assertEqual(orderedList.len(), 2)

        orderedList.add(8)
        self.assertEqual(orderedList.get_all_values(), [5, 5, 8])
        self.assertEqual(orderedList.len(), 3)

        orderedList.add(8)
        self.assertEqual(orderedList.get_all_values(), [5, 5, 8, 8])
        self.assertEqual(orderedList.len(), 4)

        orderedList.clean(True)
        orderedList.add(5)
        orderedList.add(3)
        self.assertEqual(orderedList.get_all_values(), [3, 5])
        self.assertEqual(orderedList.len(), 2)

        orderedList.add(1)
        self.assertEqual(orderedList.get_all_values(), [1, 3, 5])
        self.assertEqual(orderedList.len(), 3)

        orderedList.add(6)
        self.assertEqual(orderedList.get_all_values(), [1, 3, 5, 6])
        self.assertEqual(orderedList.len(), 4)

        orderedList.add(4)
        self.assertEqual(orderedList.get_all_values(), [1, 3, 4, 5, 6])
        self.assertEqual(orderedList.len(), 5)

        orderedList.add(4)
        self.assertEqual(orderedList.get_all_values(), [1, 3, 4, 4, 5, 6])
        self.assertEqual(orderedList.len(), 6)

        orderedList.add(1)
        self.assertEqual(orderedList.get_all_values(), [1, 1, 3, 4, 4, 5, 6])
        self.assertEqual(orderedList.len(), 7)

        orderedList.add(6)
        self.assertEqual(orderedList.get_all_values(),
                         [1, 1, 3, 4, 4, 5, 6, 6])
        self.assertEqual(orderedList.len(), 8)
示例#2
0
    def test_clean(self):
        orderedList = OrderedList(True)
        self.assertEqual(orderedList.len(), 0)
        orderedList.add(1)
        self.assertEqual(orderedList.len(), 1)
        orderedList.add(2)
        self.assertEqual(orderedList.len(), 2)
        orderedList.add(3)
        self.assertEqual(orderedList.len(), 3)

        orderedList.clean(True)
        self.assertEqual(orderedList.get_all(), [])
        self.assertEqual(orderedList.len(), 0)

        orderedList.add(10)
        self.assertEqual(orderedList.len(), 1)

        orderedList.clean(True)
        self.assertEqual(orderedList.len(), 0)

        orderedList.add(5)
        self.assertEqual(orderedList.len(), 1)