def test_receipt_calculate_price() -> None: items: List[IItem] = [ Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer") ] receipt = Receipt(items) catalogue = { Item("Milk"): 3.00, Item("Lemonade"): 2.00, OrdinaryPack(2, "Beer"): 1.00, } price = receipt.calculate_price(catalogue, {}) assert price == 12.00
def test_receipt() -> None: items: List[IItem] = [ Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer") ] receipt = Receipt(items) assert items == receipt.get_items()
def test_receipt_calculate_price_with_discount() -> None: items: List[IItem] = [ Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer") ] receipt = Receipt(items) catalogue = { Item("Milk"): 3.00, Item("Lemonade"): 2.00, OrdinaryPack(2, "Beer"): 1.00, } discounts = { (Item("Milk"), ): 1, (Item("Lemonade"), OrdinaryPack(7, "Beer")): 0.5, } price = receipt.calculate_price(catalogue, discounts) assert price == (3 * 0 + 2.00 * 0.5 + 7 * 1 * 0.5)
def test_item(db: IStoreDatabase) -> None: item = Item("Sour Milk") item_with_price = (item, 1.5) db.add_item(item_with_price) assert item in db.get_items() assert db.get_items()[item] == 1.5 pack = OrdinaryPack(5, "Cigarette") pack_with_price = (pack, 1.0) db.add_item(pack_with_price) assert pack in db.get_items() assert db.get_items()[pack] == 1.0
def test_discount(db: IStoreDatabase) -> None: discount = ((Item("Sour Milk"), ), 0.1) db.add_discount(discount) assert discount[0] in db.get_discounts() assert db.get_discounts()[discount[0]] == discount[1] discount1: Tuple[Tuple[IItem, ...], float] = ( (Item("Sour Milk"), OrdinaryPack(5, "Beer")), 0.2, ) db.add_discount(discount1) assert discount1[0] in db.get_discounts() assert db.get_discounts()[discount1[0]] == discount1[1]
def test_sold_item(db: IStoreDatabase) -> None: item = Item("Sour Milk") db.add_sold_item(item) assert item in db.get_sold_items() assert db.get_sold_items()[item] == 1 item1 = Item("Sour Milk") assert item1 in db.get_sold_items() db.add_sold_item(item1) assert db.get_sold_items()[item] == 2 pack = OrdinaryPack(5, "Cigarette") db.add_sold_item(pack) assert pack in db.get_sold_items() assert db.get_sold_items()[pack] == 1
def test_make_receipt(actor_factory: DefaultActorFactory) -> None: cashier = actor_factory.create_cashier() cashier.open_receipt(receipt_builder=ReceiptBuilder()) items: List[IItem] = [ Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer") ] for item in items: cashier.add_item_to_receipt(item) receipt = cashier.give_receipt() for item in receipt: items.remove(item) assert len(items) == 0
def __init_database(self) -> IStoreDatabase: database = StoreDatabase() items = { Item("Milk"): 4.99, Item("Mineral Water"): 3.00, Item("Bread"): 0.80, Item("Diapers"): 1.39, OrdinaryPack(6, "Beer"): 1.00, Item("Cheese"): 4.00, OrdinaryPack(10, "Tissues"): 1.50, } discounts = { (OrdinaryPack(10, "Tissues"), ): 0.1, (Item("Bread"), Item("Cheese")): 0.05, (Item("Mineral Water"), ): 0.5, } for item in items.items(): database.add_item(item) for discount in discounts.items(): database.add_discount(discount) return database
def test_make_x_report(actor_factory: DefaultActorFactory) -> None: manager = actor_factory.create_manager() sold_items = { Item("Milk"): 4, Item("Lemonade"): 3, OrdinaryPack(2, "Beer"): 2, } x_report = manager.make_X_report(sold_items.copy(), 15.0) for item in x_report: assert item[0] in sold_items assert item[1] == sold_items[item[0]] sold_items.pop(item[0]) assert len(sold_items) == 0 assert x_report.calculate_price() == 15.0
def test_receive_receipt(actor_factory: DefaultActorFactory) -> None: cashier = actor_factory.create_cashier() cashier.open_receipt(receipt_builder=ReceiptBuilder()) items: List[IItem] = [ Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer") ] customer = Customer(items.copy(), cashier, [""]) for item in customer.show_items(): cashier.add_item_to_receipt(item) customer.receive_receipt() receipt = customer.show_receipt() for item in receipt: items.remove(item) assert len(items) == 0
def test_pack_price_with_discount() -> None: pack = OrdinaryPack(5, "Tissue") catalogue = {OrdinaryPack(5, "Tissue"): 1.00} discounts = {(OrdinaryPack(5, "Tissue"), ): 0.5} assert pack.calculate_price(catalogue, discounts) == 2.5
def test_pack_price() -> None: pack = OrdinaryPack(5, "Tissue") catalogue = {OrdinaryPack(5, "Tissue"): 1.00} assert pack.calculate_price(catalogue, {}) == 5.00
def test_pack_count() -> None: pack = OrdinaryPack(5, "Tissue") assert pack.get_count() == 5
def test_pack_name() -> None: pack = OrdinaryPack(5, "Tissue") assert pack.get_name() == "Tissue"
def test_show_items(actor_factory: DefaultActorFactory) -> None: cashier = actor_factory.create_cashier() items = [Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer")] customer = actor_factory.create_customer(cashier, items) assert set(customer.show_items()).issubset(items)
def test_create_customer(actor_factory: DefaultActorFactory) -> None: cashier = actor_factory.create_cashier() items = [Item("Milk"), Item("Lemonade"), OrdinaryPack(5, "Beer")] customer = actor_factory.create_customer(cashier, items) assert customer is not None assert isinstance(cashier, Cashier)