def test_has_dairy_attribute(self): flavor = Flavor("vanilla") self.assertIs(flavor.has_dairy, True) flavor = Flavor("vanilla", has_dairy=True) self.assertIs(flavor.has_dairy, True) flavor = Flavor("vanilla", has_dairy=False) self.assertIs(flavor.has_dairy, False)
def test_specifying_ingredients(self): flavor = Flavor("vanilla", ingredients=["milk", "sugar", "vanilla"]) self.assertEqual(flavor.ingredients, ["milk", "sugar", "vanilla"]) flavor = Flavor("chocolate", ingredients=["milk", "sugar", "vanilla", "chocolate"]) self.assertEqual( flavor.ingredients, ["milk", "sugar", "vanilla", "chocolate"], )
def test_string_representation(self): flavor = Flavor("chocolate", has_dairy=False) self.assertEqual( repr(flavor), "Flavor(name='chocolate', ingredients=[], has_dairy=False)") flavor = Flavor("vanilla", ingredients=["milk", "sugar", "vanilla"]) self.assertEqual( repr(flavor), "Flavor(name='vanilla', ingredients=['milk', 'sugar', 'vanilla'], has_dairy=True)", )
def test_string_representation(self): one_quart = Size(quantity=1, unit="quart", price="$9") vanilla = Flavor("vanilla") quart_of_vanilla = IceCream(flavor=vanilla, size=one_quart) self.assertEqual(str(quart_of_vanilla), '1 quart of vanilla') self.assertEqual(str(quart_of_vanilla), '1 quart of vanilla') two_scoops = IceCream( flavor=Flavor("chocolate"), size=Size(quantity=2, unit="scoop", price="$3"), ) self.assertEqual(str(two_scoops), '2 scoops of chocolate')
def test_initializer(self): one_quart = Size(quantity=1, unit="quart", price="$9") vanilla = Flavor("vanilla") quart_of_vanilla = IceCream(flavor=vanilla, size=one_quart) self.assertEqual(quart_of_vanilla.size, one_quart) self.assertEqual(quart_of_vanilla.flavor, vanilla)
def test_modifying_ingredients(self): original_ingredients = ["milk", "sugar", "vanilla"] flavor = Flavor("vanilla", ingredients=original_ingredients) flavor.ingredients.append("red bean") self.assertEqual(original_ingredients, ["milk", "sugar", "vanilla"])
def test_name_attribute(self): flavor = Flavor("vanilla") self.assertEqual(flavor.name, "vanilla")