def test_concat_two_carts_with_two_differents_items(): result_cart = Cart.concat( cart(item(reference='x', quantity=1)), cart(item(reference='y', quantity=1))) assert Cart.create( item(reference='x', quantity=1), item(reference='y', quantity=1)) == result_cart
def test_bundle_serie_of_should_build_max_bundles(): bundler = bundle_series_of(references=['A', 'B']) result_bundles = list( bundler( cart(item(reference='A', quantity=3), item(reference='B', quantity=2)))) assert result_bundles == [Bundle(size=2)] * 2 + [Bundle(size=1)]
def price_for(*items): return pricer(cart(*items), bundle_series_of(references=['A', 'B', 'C', 'D', 'E']))
def test_bundle_serie_of_with_empty_cart(): bundler = bundle_series_of(references=['A', 'B']) assert list(bundler(cart())) == []
def test_emptycart_is_neutral_element(): neutral = cart() element = cart(item()) assert Cart.concat(neutral, element) == element assert Cart.concat(element, neutral) == element
def test_empty_cart_is_empty(): assert cart().items == tuple()
def test_concat_two_carts_with_same_items(): result_cart = Cart.concat( cart(item(reference='x', quantity=3)), cart(item(reference='x', quantity=2))) assert Cart.create(item(reference='x', quantity=5)) == result_cart
def test_associativity(): x = cart(item()) y = cart(item()) z = cart(item()) assert Cart.concat(Cart.concat(x, y), z) == Cart.concat(x, Cart.concat(y, z))