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 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_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())
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)
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)
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.")
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.")
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!')
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)
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)
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)
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', ''])
def test_init_dunder(self): e = None try: desk = CashDesk() except Exception as exc: e = exc self.assertIsNone(e)
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))
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)
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)
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)
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)
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"])
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()
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()
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.')
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))
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())
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)
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))
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 setUp(self): self.my_cash_desk = CashDesk()
def test_adding_bill(self): d = CashDesk() d.take_money(Bill(10)) self.assertEqual(str(d), str(Bill(10)))
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())
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)
def test_total_zero_when_new_instance_made(self): new_cash_desk = CashDesk() self.assertEqual(0, new_cash_desk.total())
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()
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 ')
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)
def setUp(self): self.kasa = CashDesk() self.kasa.scan('Sandwich')
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_())