Beispiel #1
0
    def test__delitem__existing_index__element_returned(self):
        custom_list = CustomList()
        custom_list.append(1)
        deleted = custom_list[0]
        del custom_list[0]

        self.assertEqual(1, deleted)
Beispiel #2
0
    def test__sort__unsorted_list__ascending(self):
        custom_list = CustomList()
        custom_list.append(3)
        custom_list.append(2)
        custom_list.append(1)
        CustomList.sort(custom_list, lambda x, y: x <= y)

        self.assertEqual(custom_list[0], 1)
Beispiel #3
0
    def test__iter__no_elements__0_iterations(self):
        custom_list = CustomList()
        count = 0

        for object in custom_list:
            count += 1

        self.assertEqual(count, 0)
Beispiel #4
0
    def test__filter__all_fail__count_0(self):
        custom_list = CustomList()
        custom_list.append(1)
        custom_list.append(2)
        custom_list.append(3)


        CustomList.filter(custom_list, lambda x: x == 4)

        self.assertEqual(0, custom_list.count)
Beispiel #5
0
    def test__filter__all_pass__count_same(self):
        custom_list = CustomList()
        custom_list.append(1)
        custom_list.append(2)
        custom_list.append(3)

        initial_count = 3

        CustomList.filter(custom_list, lambda x: x < 4)

        self.assertEqual(initial_count, custom_list.count)
Beispiel #6
0
    def test__iter__5_elements__5_iterations(self):
        custom_list = CustomList()
        custom_list.append(1)
        custom_list.append(1)
        custom_list.append(1)
        custom_list.append(1)
        custom_list.append(1)

        count = 0

        for object in custom_list:
            count += 1

        self.assertEqual(count, 5)
Beispiel #7
0
    def test__iter__3_elements_before_delete__2_iterations(self):
        custom_list = CustomList()
        custom_list.append(1)
        custom_list.append(1)
        custom_list.append(1)
        del custom_list[0]

        count = 0

        for object in custom_list:
            count += 1

        self.assertEqual(count, 2)
Beispiel #8
0
    def test__setitem__non_existing_index__index_error(self):
        custom_list = CustomList()

        self.assertRaises(IndexError, custom_list.__setitem__, 0, 0)
Beispiel #9
0
    def test__setitem__existing_index__successful_update(self):
        custom_list = CustomList()
        custom_list.append(1)
        custom_list[0] = 2

        self.assertEqual(2, custom_list[0])
Beispiel #10
0
    def test__count__empty_list__0__ok(self):
        custom_list = CustomList()

        self.assertEqual(0, custom_list.count)
Beispiel #11
0
    def test__delitem__non_existing_index__exception(self):
        custom_list = CustomList()

        self.assertRaises(IndexError, custom_list.__delitem__, 0)
Beispiel #12
0
    def test__delitem__existing_index__count_updates(self):
        custom_list = CustomList()
        custom_list.append(1)
        del custom_list[0]

        self.assertEqual(0, custom_list.count)
Beispiel #13
0
    def test__append__count_changes(self):
        custom_list = CustomList()
        custom_list.append(1)

        self.assertEqual(1, custom_list.count)
Beispiel #14
0
    def test__get_item__not_empty_list__existing_index__no_exception(self):
        custom_list = CustomList()
        custom_list.append(1)

        self.assertEqual(1, custom_list[0])
Beispiel #15
0
    def test__get_item__empty_list__exception(self):
        custom_list = CustomList()

        self.assertRaises(IndexError, custom_list.__getitem__, 1)