def test_iter(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertSequenceEqual([entity1, entity2, entity3], list(sut))
def test_getitem_by_indices(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertSequenceEqual([entity1, entity3], sut[0::2])
def test_len(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertEqual(3, len(sut))
def test_contains(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() sut.append(entity1) self.assertIn(entity1, sut) self.assertNotIn(entity2, sut)
def test_clear(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) sut.clear() self.assertSequenceEqual([], sut)
def test_list(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertIs(entity1, sut[0]) self.assertIs(entity2, sut[1]) self.assertIs(entity3, sut[2])
def test_remove(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() entity4 = Entity() sut.append(entity1, entity2, entity3, entity4) sut.remove(entity4, entity2) self.assertSequenceEqual([entity1, entity3], sut)
def test_delitem_by_index(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) del sut[1] self.assertSequenceEqual([entity1, entity3], sut)
def test_delitem_by_entity_id(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity('1') entity2 = Entity('2') entity3 = Entity('3') sut.append(entity1, entity2, entity3) del sut['2'] self.assertSequenceEqual([entity1, entity3], sut)
def test_add(self) -> None: sut1 = SingleTypeEntityCollection() sut2 = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() sut1.append(entity1) sut2.append(entity2) sut_added = sut1 + sut2 self.assertIsInstance(sut_added, SingleTypeEntityCollection) self.assertSequenceEqual([entity1, entity2], sut_added)
def test_getitem_by_index(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity1, entity2, entity3) self.assertIs(entity1, sut[0]) self.assertIs(entity2, sut[1]) self.assertIs(entity3, sut[2]) with self.assertRaises(IndexError): sut[3]
def test_append(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() sut.append(entity3) sut.append(entity2) sut.append(entity1) # Append an already appended value again, and assert that it was ignored. sut.append(entity1) self.assertSequenceEqual([entity3, entity2, entity1], sut)
def test_getitem_by_entity_id(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity('1') entity2 = Entity('2') entity3 = Entity('3') sut.append(entity1, entity2, entity3) self.assertIs(entity1, sut['1']) self.assertIs(entity2, sut['2']) self.assertIs(entity3, sut['3']) with self.assertRaises(KeyError): sut['4']
def test_prepend(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity('1') entity2 = Entity('2') entity3 = Entity('3') sut.prepend(entity3) sut.prepend(entity2) sut.prepend(entity1) # Prepend an already prepended value again, and assert that it was ignored. sut.prepend(entity1) self.assertIs(entity1, sut['1']) self.assertIs(entity2, sut['2']) self.assertIs(entity3, sut['3'])
def test_set_like_functionality(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() entity4 = Entity() entity5 = Entity() entity6 = Entity() entity7 = Entity() entity8 = Entity() entity9 = Entity() # Ensure duplicates are skipped. sut.append(entity1, entity2, entity3, entity1, entity2, entity3, entity1, entity2, entity3) # Ensure skipped duplicates do not affect further new values. sut.append(entity1, entity2, entity3, entity4, entity5, entity6, entity7, entity8, entity9) self.assertSequenceEqual([ entity1, entity2, entity3, entity4, entity5, entity6, entity7, entity8, entity9 ], sut)
def test_replace(self) -> None: sut = SingleTypeEntityCollection() entity1 = Entity() entity2 = Entity() entity3 = Entity() entity4 = Entity() entity5 = Entity() entity6 = Entity() sut.append(entity1, entity2, entity3) sut.replace(entity4, entity5, entity6) self.assertSequenceEqual([entity4, entity5, entity6], sut)
def test_entity_type_with_instance(self) -> None: self.assertEqual(Entity, Entity().entity_type())
def test_id(self) -> None: entity_id = '000000001' sut = Entity(entity_id) self.assertEqual(entity_id, sut.id)