Item removal

This commit is contained in:
David Underwood
2026-07-15 11:50:49 -04:00
parent 07a9c25d9e
commit e7f6a9620f
3 changed files with 55 additions and 1 deletions
+47
View File
@@ -108,6 +108,41 @@ class TestCheckout < Minitest::Test
assert_equal (30.00 + 10.50), @checkout.total
end
# Item removal
def test_that_removing_an_item_not_in_the_checkout_removes_nothing
@checkout.add(:PICO2)
@checkout.remove(:PI5)
assert_equal [:PICO2], @checkout.items
end
def test_that_items_are_removed_one_by_one
4.times do
@checkout.add(:ZERO2W)
end
3.times do
@checkout.add(:PICO2)
end
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W, :ZERO2W, :PICO2, :PICO2, :PICO2].sort, @checkout.items.sort
@checkout.remove(:ZERO2W)
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W, :PICO2, :PICO2, :PICO2].sort, @checkout.items.sort
@checkout.remove(:PICO2)
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W, :PICO2, :PICO2].sort, @checkout.items.sort
2.times do
@checkout.remove(:PICO2)
end
assert_equal [:ZERO2W, :ZERO2W, :ZERO2W].sort, @checkout.items.sort
end
def test_that_total_is_correctly_recalculated_when_items_are_added
2.times do
@checkout.add(:PICO2)
@@ -125,4 +160,16 @@ class TestCheckout < Minitest::Test
assert_equal 40.50, @checkout.total
end
def test_that_total_is_correctly_recalculated_when_items_are_removed
3.times do
@checkout.add(:PICO2) # Bulk discount applies
end
assert_equal 10.50, @checkout.total
@checkout.remove(:PICO2) # Bulk discount no longer applies
assert_equal 8.00, @checkout.total
end
end