Add a couple of extra test cases

This commit is contained in:
David Underwood
2026-07-15 11:36:23 -04:00
parent ba6e6c19af
commit 07a9c25d9e
+27 -3
View File
@@ -13,6 +13,12 @@ class TestCheckout < Minitest::Test
end end
end end
def test_that_nil_is_not_allowed_to_be_added
assert_raises Checkout::InvalidItem do
@checkout.add(nil)
end
end
def test_that_allowed_items_are_added def test_that_allowed_items_are_added
@checkout.add(:PI5) @checkout.add(:PI5)
@checkout.add(:ZERO2W) @checkout.add(:ZERO2W)
@@ -84,7 +90,7 @@ class TestCheckout < Minitest::Test
def test_that_price_is_not_reduced_for_less_than_3_picos def test_that_price_is_not_reduced_for_less_than_3_picos
2.times do 2.times do
@checkout.add(:PICO2) @checkout.add(:PICO2) # 4.00 * 2 = 8
end end
assert_equal 8.00, @checkout.total assert_equal 8.00, @checkout.total
@@ -92,13 +98,31 @@ class TestCheckout < Minitest::Test
def test_that_both_discounts_apply_at_the_same_time def test_that_both_discounts_apply_at_the_same_time
4.times do 4.times do
@checkout.add(:ZERO2W) # 30.00 total @checkout.add(:ZERO2W) # 30.00 with BOGOF
end end
3.times do 3.times do
@checkout.add(:PICO2) # 10.50 total @checkout.add(:PICO2) # 10.50 with bulk discount
end end
assert_equal (30.00 + 10.50), @checkout.total assert_equal (30.00 + 10.50), @checkout.total
end end
def test_that_total_is_correctly_recalculated_when_items_are_added
2.times do
@checkout.add(:PICO2)
end
assert_equal 8.00, @checkout.total
@checkout.add(:PICO2) # 3 in total now, so discount applies
assert_equal 10.50, @checkout.total
4.times do
@checkout.add(:ZERO2W) # 30.00 with BOGOF
end
assert_equal 40.50, @checkout.total
end
end end