Bulk discount for Pico2
This commit is contained in:
+4
-2
@@ -34,8 +34,10 @@ class Checkout
|
|||||||
# BOGOF ZERO2W
|
# BOGOF ZERO2W
|
||||||
discount = (@items.count(:ZERO2W) / 2.0).floor * AVAILABLE_ITEMS[:ZERO2W]
|
discount = (@items.count(:ZERO2W) / 2.0).floor * AVAILABLE_ITEMS[:ZERO2W]
|
||||||
|
|
||||||
|
# Bulk PICO2
|
||||||
# TODO: Bulk PICO2
|
if(items.count(:PICO2) >= 3)
|
||||||
|
discount += items.count(:PICO2) * 0.50
|
||||||
|
end
|
||||||
|
|
||||||
return discount
|
return discount
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class TestCheckout < Minitest::Test
|
|||||||
assert_equal [:PI5, :ZERO2W, :PICO2].sort, @checkout.items.sort
|
assert_equal [:PI5, :ZERO2W, :PICO2].sort, @checkout.items.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_that_total_is_the_sum_of_all_items # Not accounting for discounts at the moment
|
def test_that_total_is_the_sum_of_all_items_when_no_discounts_apply
|
||||||
@checkout.add(:PI5) # 60.00
|
@checkout.add(:PI5) # 60.00
|
||||||
@checkout.add(:ZERO2W) # 15.00
|
@checkout.add(:ZERO2W) # 15.00
|
||||||
@checkout.add(:PICO2) # 4.00
|
@checkout.add(:PICO2) # 4.00
|
||||||
@@ -39,7 +39,7 @@ class TestCheckout < Minitest::Test
|
|||||||
|
|
||||||
def test_that_bogof_applied
|
def test_that_bogof_applied
|
||||||
4.times do
|
4.times do
|
||||||
@checkout.add(:ZERO2W)
|
@checkout.add(:ZERO2W) # Should remove 2 Zeros
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal 30.00, @checkout.total
|
assert_equal 30.00, @checkout.total
|
||||||
@@ -47,9 +47,45 @@ class TestCheckout < Minitest::Test
|
|||||||
|
|
||||||
def test_that_bogof_applied_with_odd_number
|
def test_that_bogof_applied_with_odd_number
|
||||||
5.times do
|
5.times do
|
||||||
@checkout.add(:ZERO2W)
|
@checkout.add(:ZERO2W) # Should still remove 2 Zeros, 5th is full price
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal 45.00, @checkout.total
|
assert_equal 45.00, @checkout.total
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_that_price_is_reduced_for_3_picos
|
||||||
|
3.times do
|
||||||
|
@checkout.add(:PICO2) # 3.50 * 3 = 10.50
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 10.50, @checkout.total
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_that_price_is_reduced_for_more_than_3_picos
|
||||||
|
4.times do
|
||||||
|
@checkout.add(:PICO2) # 3.50 * 4 = 14
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 14.00, @checkout.total
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_that_price_is_not_reduced_for_less_than_3_picos
|
||||||
|
2.times do
|
||||||
|
@checkout.add(:PICO2)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal 8.00, @checkout.total
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_that_both_discounts_apply_at_the_same_time
|
||||||
|
4.times do
|
||||||
|
@checkout.add(:ZERO2W) # 30.00 total
|
||||||
|
end
|
||||||
|
|
||||||
|
3.times do
|
||||||
|
@checkout.add(:PICO2) # 10.50 total
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal (30.00 + 10.50), @checkout.total
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user