def setUp(self):
     values = [10, 20, 50, 100, 100, 100]
     bills = [Bill(value) for value in values]
     batch = BatchBill(bills)
     self.desk = CashDesk()
     self.desk.take_money(batch)
     self.desk.take_money(Bill(10))
Exemplo n.º 2
0
 def setUp(self):
     self.cash = CashDesk()
     self.values = [10, 20, 50, 100, 100, 100]
     self.bills = [Bill(value) for value in self.values]
     self.batch = BillBatch(self.bills)
     self.cash.take_money(self.batch)
     self.cash.take_money(Bill(10))
Exemplo n.º 3
0
    def test_total_works_with_batch_bills(self):
        bills = [Bill(10), Bill(5), Bill(20)]
        batch = BillBatch(bills)
        desk = CashDesk()
        desk.take_money(batch)

        self.assertEqual(35, desk.total())
Exemplo n.º 4
0
    def test_take_money_with_element_different_than_batch_and_bill(self):
        exc = None
        a = CashDesk()

        try:
            a.take_money(3)
        except TypeError as err:
            exc = err

        self.assertIsNotNone(exc)
Exemplo n.º 5
0
    def test_take_money_with_a_single_bill(self):
        b = Bill(10)

        desk = CashDesk()
        desk.take_money(b)

        result = desk.cash_desk

        expected = {b: 1}

        self.assertEqual(result, expected)
Exemplo n.º 6
0
    def test_take_money_with_bad_type(self):
        e = None
        bad = dict()
        desk = CashDesk()

        try:
            desk.take_money(bad)
        except TypeError as exc:
            e = exc

        self.assertIsNotNone(e)
        self.assertEqual(str(e), "Non-bill type.")
Exemplo n.º 7
0
    def test_take_money_with_bad_bill_type(self):
        e = None
        badBills = [Bill(1), Bill(2), 3]
        desk = CashDesk()

        try:
            desk.take_money(badBills)
        except TypeError as exc:
            e = exc

        self.assertIsNotNone(e)
        self.assertEqual(str(e), "Non-bill type.")
Exemplo n.º 8
0
    def test_take_money_type(self):

        desk = CashDesk()
        exc = None

        try:
            desk.take_money(10)
        except Exception as err:
            exc = err

        self.assertIsNotNone(exc)
        self.assertEqual(str(exc), 'Wrong type!')
Exemplo n.º 9
0
    def test_take_money_with_a_batch_bill(self):
        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)

        desk = CashDesk()
        desk.take_money(batch)

        result = desk.cash_desk

        expected = {bills[0]: 1, bills[1]: 1, bills[2]: 1, bills[3]: 3}

        self.assertEqual(result, expected)
Exemplo n.º 10
0
    def test_total(self):
        e = None
        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)
        desk = CashDesk()
        desk.take_money(batch)

        try:
            res = desk.total()
        except Exception as exc:
            e = exc

        self.assertIsNone(e)
        self.assertEqual(380, res)
Exemplo n.º 11
0
class TestCashDesk(unittest.TestCase):
    def setUp(self):
        self.cash = CashDesk()
        self.values = [10, 20, 50, 100, 100, 100]
        self.bills = [Bill(value) for value in self.values]
        self.batch = BillBatch(self.bills)
        self.cash.take_money(self.batch)
        self.cash.take_money(Bill(10))

    def test_init(self):
        self.assertTrue(isinstance(self.cash, CashDesk))

    def test_take_money(self):
        self.assertEqual(self.cash.vault, [self.batch, Bill(10)])

    def test_total(self):
        self.assertEqual(self.cash.total(), 390)
Exemplo n.º 12
0
 def test_inspect(self):
     d = CashDesk()
     d.take_money(BatchBill([Bill(30),Bill(10),Bill(10),Bill(23),Bill(10),Bill(15)]))
     d.take_money(Bill(30))
     res = d.inspect()
     s = res.split('\n')
     self.assertEqual(s,['A 10$ bill 3','A 15$ bill 1','A 23$ bill 1','A 30$ bill 2', ''])
Exemplo n.º 13
0
    def test_init_dunder(self):
        e = None

        try:
            desk = CashDesk()
        except Exception as exc:
            e = exc

        self.assertIsNone(e)
Exemplo n.º 14
0
class TestCashDesk(unittest.TestCase):
    def setUp(self):
        self.my_cash_desk = CashDesk()
    def test_total_zero_when_new_instance_made(self):
        self.assertEqual(0,self.my_cash_desk.total())
    def test_total_after_money_take(self):
        self.my_cash_desk.take_money({1:2,100:3})
        self.assertEqual(302, self.my_cash_desk.total())
    def test_can_withdraw_money_all_money(self):
        self.my_cash_desk.take_money({1: 2, 100: 3})
        self.assertTrue(self.my_cash_desk.can_withdraw_money(302))
    #def test_can_withdraw_money_not_all_money(self):
    #    self.my_cash_desk.take_money({1: 2, 100: 3})
    #    self.assertTrue(self.my_cash_desk.can_withdraw_money(202))

    def test_can_withdraw_money_cant_withdraw(self):
        self.my_cash_desk = CashDesk()
        self.my_cash_desk.take_money({1: 2, 100: 3})
        self.assertFalse(self.my_cash_desk.can_withdraw_money(105))
Exemplo n.º 15
0
    def test_total(self):

        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BillBatch(bills)
        desk = CashDesk()

        desk.take_money(batch)
        desk.take_money(Bill(10))
        total = desk.total()

        self.assertEqual(total, 390)
Exemplo n.º 16
0
    def test_checking_total(self):
        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)

        desk = CashDesk()
        desk.take_money(batch)
        desk.take_money(Bill(10))

        result = desk.total()

        expected = 390
class CashDeskTests(unittest.TestCase):
    def setUp(self):
        self.desk = CashDesk()
        self.desk.bills = [Bill(1), Bill(2), Bill(3)]
        self.desk2 = CashDesk()
        self.desk2.bills = [Bill(4), Bill(5), Bill(6)]

    def test_total(self):
        self.assertEqual(self.desk.total(), 6)
        self.assertEqual(self.desk2.total(), 15)

    def test_take_money_from_a_bill(self):
        self.desk.take_money(Bill(5))
        self.assertEqual(self.desk.total(), 11)
        self.desk.take_money(BatchBill([Bill(1), Bill(2), Bill(3)]))
        self.assertEqual(self.desk.total(), 17)
Exemplo n.º 18
0
def main():
    """Create cash desks"""
    cashdesks = []
    for i in range(const.n_cashdesks):
        cashdesks.append(CashDesk(const.skills[i]))
    """Place people to the queues"""
    for i in range(const.n_people - 1):
        where = i % const.n_cashdesks
        cashdesks[where].add_customer(customer.Customer(where))
        # print(cashdesks[where].queue[-1].patience)
    me = Me(np.random.randint(const.n_cashdesks))
    cashdesks[me.where].add_customer(me)
    """Set state of 1st customer to SCANNING"""
    for cashdesk in cashdesks:
        cashdesk.queue[0].state = customer.State.SCANNING
    """Run simulation"""
    run_simul(cashdesks)
Exemplo n.º 19
0
    def test_str_inspect(self):
        e = None
        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)
        extraBill1 = Bill(10)
        extraBill2 = Bill(500)
        desk = CashDesk()
        desk.take_money(batch)
        desk.take_money(extraBill1)
        desk.take_money(extraBill2)
        expected = "We have a total of 890$ in the desk\nWe have the following count of bills, sorted in ascending order:\n10$ bills: 2\n20$ bills: 1\n50$ bills: 1\n100$ bills: 3\n500$ bills: 1"

        try:
            res = desk.str_inspect()
        except Exception as exc:
            e = exc

        self.assertIsNone(e)
        self.assertEqual(expected, res)
class TestCashDesck(unittest.TestCase):
    def setUp(self):
        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)
        self.desk = CashDesk()
        self.desk.take_money(batch)
        self.desk.take_money(Bill(10))

    def test_total(self):
        self.assertEqual(self.desk.total(), 390)

    def test_inspect(self):
        expect = "We have a total of 390$ in the desk\n"
        expect += "We have the following count of bills, sorted in ascending order:\n"
        expect += "10$ bills - 2\n20$ bills - 1\n50$ bills - 1\n100$ bills - 3"
        self.assertEqual(self.desk.inspect(), expect)
Exemplo n.º 21
0
    def test_take_money(self):
        e = None
        values = [10, 20, 50, 100, 100, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)
        extraBill = Bill(10)
        desk = CashDesk()
        expected = [BatchBill(bills), Bill(10)]

        try:
            desk.take_money(batch)
            desk.take_money(extraBill)
        except Exception as exc:
            e = exc

        self.assertIsNone(e)
        self.assertEqual(expected, desk.__dict__["money"])
Exemplo n.º 22
0
def main():
    # Task 1
    a = Bill(10)
    b = Bill(5)
    c = Bill(10)

    print(int(a))
    print(str(a))
    print(a)

    print(a == b)
    print(a == c)

    money_holder = {}
    money_holder[a] = 1
    print(money_holder)

    # Task 2
    values = [10, 20, 50, 100]
    bills = [Bill(value) for value in values]

    batch = BillBatch(bills)

    for bill in batch:
        print(bill)

    # Task 3
    values = [10, 20, 50, 100, 100, 100]
    bills = [Bill(value) for value in values]
    batch = BillBatch(bills)

    desk = CashDesk()
    desk.take_money(batch)
    desk.take_money(Bill(10))

    desk.inspect()
Exemplo n.º 23
0
 def test_can_withdraw_money_cant_withdraw(self):
     self.my_cash_desk = CashDesk()
     self.my_cash_desk.take_money({1: 2, 100: 3})
     self.assertFalse(self.my_cash_desk.can_withdraw_money(105))
 def setUp(self):
     self.bill = Bill(10)
     self.batch = BatchBill([Bill(5), Bill(10), Bill(15)])
     self.desk = CashDesk()
Exemplo n.º 25
0
from cash_desk import CashDesk


kasa = CashDesk()

print('Welcome to our store.')
for each in kasa.items:
    print (each, '-', kasa.items[each])

cashout = False
while cashout is False:
    command = input('>>> ').strip().split()
    if command[0] == 'scan':
        scan_item = command[1]
        kasa.scan(scan_item)
        print (kasa.scanned_items)
    elif command[0] == 'cashout':
        cashout = True
        print (kasa.calculate_all())
    else:
        print ('Invalid Command.')
Exemplo n.º 26
0
 def test_can_withdraw_all_money(self):
     new_cash_desk = CashDesk()
     new_cash_desk.take_money({1: 2, 100: 3})
     self.assertTrue(new_cash_desk.can_withdraw_money(302))
Exemplo n.º 27
0
 def test_total_works_with_bills(self):
     desk = CashDesk()
     desk.take_money(Bill(5))
     desk.take_money(Bill(10))
     desk.take_money(Bill(10))
     self.assertEqual(25, desk.total())
Exemplo n.º 28
0
class TestCashDesk(unittest.TestCase):

    def setUp(self):
        self.kasa = CashDesk()
        self.kasa.scan('Sandwich')

    def test_init(self):
        self.assertEqual(
            self.kasa.discounts,
            {'Sandwich': [3, 2], 'Cucumber': [2, 1], 'Apple': [4, 3]})
        self.assertEqual(
            self.kasa.meal_deals,
            [(['Sandwich', 'Coke', 'Apple'], 3.0, [1, 1, 1]),
             (['Soup', 'Noodles', 'Custard'], 6.50, [1, 2, 1])])

    def test_scan_with_present_item(self):
        self.kasa.scan('Sandwich')
        self.assertEqual(self.kasa.scanned_items, {'Sandwich': 2})

    def test_scan_with_new_valid_item(self):
        self.kasa.scan('Apple')
        self.assertEqual(self.kasa.scanned_items,
                         {'Sandwich': 1, 'Apple': 1})

    def test_scan_with_new_invalid_item(self):
        self.kasa.scan('asd')
        self.assertEqual(self.kasa.scanned_items, {'Sandwich': 1})

    def test_total_method(self):
        result = self.kasa.total()
        self.assertEqual(result, 0)

    def test_calculate_meal_with_missing_item(self):
        self.kasa.scanned_items = {'Apple': 2}
        self.kasa.calculate_meal_deals()
        self.assertEqual(self.kasa.total_price, 0)

    def test_calculate_discounts(self):
        self.kasa.scanned_items = {'Soup': 2}
        self.kasa.calculate_discounts()
        self.assertEqual(self.kasa.total_price, 0)

    def test_calculate_all(self):
        result = self.kasa.calculate_all()
        self.assertEqual(result, 2.50)

    def test_cashout(self):
        self.assertEqual(self.kasa.total_price, 0)
Exemplo n.º 29
0
 def test_can_withdraw_money_not(self):
     new_cash_desk = CashDesk()
     new_cash_desk.take_money({1: 2, 100: 3})
     self.assertFalse(new_cash_desk.can_withdraw_money(105))
Exemplo n.º 30
0
 def setUp(self):
     self.bill = Bill(10)
     self.batch = BatchBill([Bill(5), Bill(10), Bill(15)])
     self.desk = CashDesk()
 def setUp(self):
     self.desk = CashDesk()
     self.desk.bills = [Bill(1), Bill(2), Bill(3)]
     self.desk2 = CashDesk()
     self.desk2.bills = [Bill(4), Bill(5), Bill(6)]
Exemplo n.º 32
0
 def setUp(self):
     self.my_cash_desk = CashDesk()
Exemplo n.º 33
0
 def test_adding_bill(self):
     d = CashDesk()
     d.take_money(Bill(10))
     self.assertEqual(str(d), str(Bill(10)))
Exemplo n.º 34
0
 def test_total_after_take_money(self):
     new_cash_desk = CashDesk()
     new_cash_desk.take_money({1: 2, 100: 3})
     self.assertEqual(302, new_cash_desk.total())
Exemplo n.º 35
0
 def test_total(self):
     d = CashDesk()
     d.take_money(BatchBill([Bill(30),Bill(10),Bill(10)]))
     d.take_money(Bill(29))
     self.assertEqual(d.total(), 79)
Exemplo n.º 36
0
 def test_total_zero_when_new_instance_made(self):
     new_cash_desk = CashDesk()
     self.assertEqual(0, new_cash_desk.total())
Exemplo n.º 37
0
class CashDeskTest(unittest.TestCase):

    def setUp(self):
        self.bill = Bill(10)
        self.batch = BatchBill([Bill(5), Bill(10), Bill(15)])
        self.desk = CashDesk()

    def test_type_of_amount(self):
        with self.assertRaises(TypeError):
            Bill("10")

    def test_value_of_amount(self):
        with self.assertRaises(ValueError):
            Bill(-5)

    def test_batchbill_total(self):
        self.assertEqual(self.batch.total(), 30)

    def test_take_money_from_bill(self):
        self.desk.take_money(self.bill)
        self.assertEqual(self.desk.gold, 10)

    def test_take_money_from_batch(self):
        self.desk.take_money(self.batch)
        self.assertEqual(self.desk.gold, 30)

    def test_cashdesk_total(self):
        self.desk.take_money(self.bill)
        self.desk.take_money(self.batch)
        self.assertEqual(
            self.desk.total(), 'We have a total of 40$ in the bank')

    def test_cashdesk_inspect_value(self):
        self.desk.take_money(self.bill)
        self.desk.take_money(self.batch)
        self.desk.inspect()
Exemplo n.º 38
0
 def test_adding_batch(self):
     d = CashDesk()
     d.take_money(BatchBill([Bill(30),Bill(10),Bill(10)]))
     self.assertEqual(str(d), 'A 30$ bill A 10$ bill A 10$ bill ')
Exemplo n.º 39
0
 def test_total_zero_when_new_instance_made(self):
     new_cash_desk = CashDesk()
     self.assertEqual(0, new_cash_desk.total())
Exemplo n.º 40
0
 def test_can_withdrawSSS_money_all_money(self):
     new_cash_desk = CashDesk()
     new_cash_desk.take_money({1: 2, 100: 3})
     self.assertTrue(301, new_cash_desk.total())
class TestCashDesk(unittest.TestCase):
    def setUp(self):
        self.bill = Bill(10)
        self.batch = BatchBill([Bill(5), Bill(10), Bill(15)])
        self.desk = CashDesk()

    def test_type_of_amount(self):
        with self.assertRaises(TypeError):
            Bill("10")

    def test_value_of_amount(self):
        with self.assertRaises(ValueError):
            Bill(-5)

    def test_take_money_from_bill(self):
        self.desk.take_money(self.bill)
        self.assertEqual(self.desk.total(), 10)

    def test_take_money_from_batch(self):
        self.desk.take_money(self.batch)
        self.assertEqual(self.desk.total(), 30)

    def test_cashdesk_total(self):
        self.desk.take_money(self.bill)
        self.desk.take_money(self.batch)
        self.assertEqual(self.desk.total(), 40)

    def test_cashdesk_inspect_value(self):
        self.desk.take_money(self.bill)
        self.desk.take_money(self.batch)

        expexted = """We have a total of 40$ in the desk
We have the following count of bills, sorted in ascending order:
5$ bills - 1
10$ bills - 2
15$ bills - 1"""

        self.assertEqual(self.desk.inspect(), expexted)
Exemplo n.º 42
0
 def setUp(self):
     self.kasa = CashDesk()
     self.kasa.scan('Sandwich')
Exemplo n.º 43
0
 def test_can_withdrawSSS_money_all_money(self):
     new_cash_desk = CashDesk()
     new_cash_desk.take_money({1: 2, 100: 3})
     self.assertFalse(new_cash_desk.can_withdraw_money_())