@@ -117,53 +117,6 @@ if __name__ == "__main__":
117117 )
118118 print (pizza_demo)
119119
120-
121- class TestPizzaBuilder (unittest .TestCase ):
122- """ Unit tests for the PizzaBuilder class."""
123-
124- def test_full_pizza (self ):
125- """ Test building a full pizza."""
126- pizza = (
127- PizzaBuilder()
128- .set_size(" medium" )
129- .set_crust(" thin" )
130- .add_topping(" olives" )
131- .add_topping(" onions" )
132- .set_sauce(" pesto" )
133- .build()
134- )
135- self .assertEqual(pizza[" size" ], " medium" )
136- self .assertEqual(pizza[" crust" ], " thin" )
137- self .assertIn(" olives" , pizza[" toppings" ])
138- self .assertEqual(pizza[" sauce" ], " pesto" )
139-
140- def test_invalid_size (self ):
141- """ Test building a pizza with an invalid size."""
142- with self .assertRaises(ValueError ):
143- PizzaBuilder().set_size(" extra large" )
144-
145- def test_duplicate_topping (self ):
146- """ Test building a pizza with duplicate toppings."""
147- with self .assertRaises(ValueError ):
148- (PizzaBuilder()
149- .set_size(" small" )
150- .set_crust(" thick" )
151- .add_topping(" cheese" )
152- .add_topping(" cheese" ))
153-
154- def test_missing_required_fields (self ):
155- """ Test building a pizza with missing required fields."""
156- with self .assertRaises(ValueError ):
157- PizzaBuilder().build()
158-
159- def test_undo_functionality (self ):
160- """ Test the undo functionality of the PizzaBuilder."""
161- builder = PizzaBuilder().set_size(" small" ).set_crust(" thin" ).add_topping(" olives" )
162- builder.set_sauce(" pesto" )
163- builder.undo() # Should undo sauce change
164- pizza = builder.build()
165- self .assertEqual(pizza[" sauce" ], " tomato" )
166-
167120```
168121
169122## Summary
0 commit comments