def test_person_with_some_children(name, children): """Test count_descendants on a person with some children. Each child has *no* children of their own in this test case. """ # children is a list of Person objects, each of whom have no children p = Person(name, children) # The number of descendants of p is equal to their number of children assert p.count_descendants() == len(children)
class TestEx4(unittest.TestCase): def setUp(self): self.person = Person(12, 53, 160) def test_age_weight_and_height(self): self.person.age |should| equal_to(12) self.person.weight |should| equal_to(53) self.person.height |should| equal_to(160) def test_get_old(self): self.person.age = 10 self.person.get_old() self.person.age |should| equal_to(11) self.person.height |should| equal_to(161.5) self.person.age = 21 self.person.height = 170 self.person.get_old() self.person.age |should| equal_to(22) self.person.height |should| equal_to(170) def test_fatten(self): self.person.weight = 30 self.person.fatten(5) self.person.weight |should| equal_to(35) def test_weight_loss(self): self.person.weight = 30 self.person.weight_loss(4) self.person.weight |should| equal_to(26)
def test_small_family(): """Test count_descendants on a small example.""" aura = Person('aura', []) zane = Person('zane', []) goku = Person('goku', [aura, zane]) mina = Person('mina', [goku]) assert mina.count_descendants() == 3
def setUp(self): self.person = Person(12, 53, 160)