예제 #1
0
 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)
예제 #2
0
 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"],
     )
예제 #3
0
 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)",
     )
예제 #4
0
 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')
예제 #5
0
 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)
예제 #6
0
 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"])
예제 #7
0
 def test_name_attribute(self):
     flavor = Flavor("vanilla")
     self.assertEqual(flavor.name, "vanilla")