diff --git a/tests.rb b/tests.rb index db7e68f..2622192 100644 --- a/tests.rb +++ b/tests.rb @@ -13,6 +13,12 @@ class TestCheckout < Minitest::Test 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 @checkout.add(:PI5) @checkout.add(:ZERO2W) @@ -84,7 +90,7 @@ class TestCheckout < Minitest::Test def test_that_price_is_not_reduced_for_less_than_3_picos 2.times do - @checkout.add(:PICO2) + @checkout.add(:PICO2) # 4.00 * 2 = 8 end assert_equal 8.00, @checkout.total @@ -92,13 +98,31 @@ class TestCheckout < Minitest::Test def test_that_both_discounts_apply_at_the_same_time 4.times do - @checkout.add(:ZERO2W) # 30.00 total + @checkout.add(:ZERO2W) # 30.00 with BOGOF end 3.times do - @checkout.add(:PICO2) # 10.50 total + @checkout.add(:PICO2) # 10.50 with bulk discount end assert_equal (30.00 + 10.50), @checkout.total 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