@@ -51,6 +51,34 @@ def test_5(self):
5151 order_1 = c .Order (id = "1" , items = [service ])
5252 self .assertEqual (c .validorder (order_1 ), "Invalid item type: service" )
5353
54+ # Tricks the system and walks away with 1 television, despite valid payment & reimbursement
55+ def test_6 (self ):
56+ tv_item = c .Item (type = "product" , description = "tv" , amount = 1000.00 , quantity = 1 )
57+ payment = c .Item (
58+ type = "payment" , description = "invoice_4" , amount = 1e19 , quantity = 1
59+ )
60+ payback = c .Item (
61+ type = "payment" , description = "payback_4" , amount = - 1e19 , quantity = 1
62+ )
63+ order_4 = c .Order (id = "4" , items = [payment , tv_item , payback ])
64+ self .assertEqual (
65+ c .validorder (order_4 ), "Order ID: 4 - Payment imbalance: $-1000.00"
66+ )
67+
68+ # Valid payments that should add up correctly, but do not
69+ def test_7 (self ):
70+ small_item = c .Item (
71+ type = "product" , description = "accessory" , amount = 3.3 , quantity = 1
72+ )
73+ payment_1 = c .Item (
74+ type = "payment" , description = "invoice_5_1" , amount = 1.1 , quantity = 1
75+ )
76+ payment_2 = c .Item (
77+ type = "payment" , description = "invoice_5_2" , amount = 2.2 , quantity = 1
78+ )
79+ order_5 = c .Order (id = "5" , items = [small_item , payment_1 , payment_2 ])
80+ self .assertEqual (c .validorder (order_5 ), "Order ID: 5 - Full payment received!" )
81+
5482
5583if __name__ == "__main__" :
5684 unittest .main ()
0 commit comments