def test_ShadowedList__reverse__values_and_shadow_values_identical(self): # ShadowList.reverse() works also when passed the same # sequence as values and as shadow_values. list_ = range(3) shadow_list = ShadowedList(list_, list_) shadow_list.reverse() self.assertEqual(0, shadow_list[-1]) self.assertEqual(2, shadow_list[0]) self.assertEqual(0, shadow_list.shadow_values[-1]) self.assertEqual(2, shadow_list.shadow_values[0])
def test_ShadowedList__add(self): # Two shadowedLists can be added, yielding another ShadowedList. list1 = range(3) list2 = self.makeStringSequence(list1) shadow_list1 = ShadowedList(list1, list2) list3 = range(4) list4 = self.makeStringSequence(list3) shadow_list2 = ShadowedList(list3, list4) list_sum = shadow_list1 + shadow_list2 self.assertIsInstance(list_sum, ShadowedList) self.assertEqual(list1 + list3, list_sum.values) self.assertEqual(list2 + list4, list_sum.shadow_values)
def test_ShadowedList__reverse(self): # ShadowList.reverse() reverses its elements. list1 = range(3) list2 = self.makeStringSequence(list1) first1 = list1[0] last1 = list1[-1] first2 = list2[0] last2 = list2[-1] shadow_list = ShadowedList(list1, list2) shadow_list.reverse() self.assertEqual(first1, shadow_list[-1]) self.assertEqual(last1, shadow_list[0]) self.assertEqual(first2, shadow_list.shadow_values[-1]) self.assertEqual(last2, shadow_list.shadow_values[0])
def test_ShadowedList__getitem(self): # Accessing a single element of a ShadowedList is equivalent to # accessig an element of its values attribute. list1 = range(3) list2 = self.makeStringSequence(list1) shadowed_list = ShadowedList(list1, list2) self.assertEqual(list1[1], shadowed_list[1])
def test_ShadowedList__init(self): # ShadowedList instances need two lists as constructor parametrs. list1 = range(3) list2 = self.makeStringSequence(list1) shadowed_list = ShadowedList(list1, list2) self.assertEqual(shadowed_list.values, list1) self.assertEqual(shadowed_list.shadow_values, list2)
def test_ShadowedList__slice(self): # A slice of a ShadowedList contains the slices of its # values and shaow_values. list1 = range(5) list2 = self.makeStringSequence(list1) shadowed_list = ShadowedList(list1, list2) self.assertEqual(list1[2:4], shadowed_list[2:4].values) self.assertEqual(list2[2:4], shadowed_list[2:4].shadow_values)
def test_ShadowedList__iterator(self): # Iterating over a ShadowedList yields if values elements. list1 = range(3) list2 = self.makeStringSequence(list1) shadow_list = ShadowedList(list1, list2) self.assertEqual(list1, list(iter(shadow_list)))
def test_ShadowedList__len(self): # The length of a ShadowedList ist the same as the list of # the sequences it stores. list1 = range(3) list2 = self.makeStringSequence(list1) self.assertEqual(len(list1), len(ShadowedList(list1, list2)))