def test_cashdesk_take_only_batch(self): desk = CashDesk() batch = BillBatch([Bill(10), Bill(5)]) desk.take_money(batch) self.assertEqual(desk.total(), 15)
def test_if_take_money_works_with_bill(self): bill = Bill(10) cd = CashDesk() cd.take_money(bill) res = 10 self.assertEqual(res, cd.total())
def test_if_take_money_works_with_batch(self): bills = [Bill(i) for i in range(5)] batch = BatchBill(bills) cd = CashDesk() cd.take_money(batch) res = 10 self.assertEqual(res, cd.total())
def test_cashdesk_take_money_works_as_expected_with_empty_desk_and_bill( self): cash_desk = CashDesk() test1 = Bill(10) cash_desk.take_money(test1) self.assertEqual(cash_desk.cash, {test1: 1})
def test_cashdesk_take_money_works_as_expected_with_empty_desk_and_billbatch( self): cash_desk = CashDesk() bill_batch = BillBatch([Bill(10), Bill(15)]) cash_desk.take_money(bill_batch) self.assertEqual(cash_desk.cash, {Bill(10): 1, Bill(15): 1})
def test_take_money_batch(self): values = [10, 20, 50, 100, 100, 100] bills = [Bill(value) for value in values] batch = BillBatch(bills) desk = CashDesk() desk.take_money(batch)
def setUp(self): self.a = Bill(10) self.b = Bill(5) self.c = Bill(10) values = [10, 20, 50, 100] bills = [Bill(value) for value in values] self.batch = BatchBill(bills) self.desk = CashDesk() self.desk.take_money(self.batch)
def test_if_take_money_raises_exception_when_argument_is_not_of_type_bill_nor_batch( self): cd = CashDesk() res = None try: cd.take_money('a') except TypeError as e: res = str(e) self.assertEqual( res, 'Function accepts only objects of type Bill or BatchBill')
def test_cashdesk_take_money_works_as_expected_with_one_type_of_bill_in_desk( self): cash_desk = CashDesk() test1 = Bill(10) test2 = Bill(10) cash_desk.take_money(test1) cash_desk.take_money(test2) self.assertEqual(cash_desk.cash, {test2: 2})
def test_total_if_cash_desk_is_empty(self): values = [10, 20, 50, 100, 100, 100] bills = [Bill(value) for value in values] batch = BillBatch(bills) desk = CashDesk() result = desk.total() expexted = 0 self.assertEqual(result, expexted)
class CashdeskTest(unittest.TestCase): def setUp(self): self.a = Bill(10) self.b = Bill(5) self.c = Bill(10) values = [10, 20, 50, 100] bills = [Bill(value) for value in values] self.batch = BatchBill(bills) self.desk = CashDesk() self.desk.take_money(self.batch) def test_desk_total(self): self.assertEqual(self.desk.total(), 180)
def test_total_amount_of_money_in_the_desk_with_batches(self): Bill.money_holder = {} a = Bill(10) b = Bill(20) c = Bill(40) batch = BatchBill([a, b, c]) desk1 = CashDesk() desk1.take_money(batch) total = desk1.total() self.assertEqual(total, 70)
def test_cashdesk_take_money_raises_exception_if_money_is_not_of_type_bill_or_billbatch( self): money = 50 exc = None test = CashDesk() try: test.take_money(money) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(type(exc), TypeError) self.assertEqual(str(exc), 'Money must be of type "Bill" or type "BillBatch".')
def test_inspect_function(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)) desk.inspect()
def test_cashdesk_take_only_bills(self): desk = CashDesk() desk.take_money(Bill(10)) desk.take_money(Bill(5)) self.assertEqual(desk.total(), 15)
def test_if_inspection_works(self): desk = CashDesk() ls = [10,20,50,100] bills = [Bill(value) for value in ls] batch = BillBatch(bills) desk.take_money(Bill(10)) desk.take_money(batch) desk.inspect()
def test_cashdesk_total_works_as_expected_when_bill_appears_only_once( self): cash_desk = CashDesk() bill1 = Bill(5) bill2 = Bill(10) bill3 = Bill(20) cash_desk.take_money(bill1) cash_desk.take_money(bill2) cash_desk.take_money(bill3) self.assertEqual(cash_desk.total(), 35)
def test_if___stringify_works_correctly(self): bills = [Bill(i) for i in range(5)] batch = BatchBill(bills) cd = CashDesk() cd.take_money(batch) cd.take_money(Bill(1)) s = cd.stringify() self.assertEqual( s, "A 0$ bill - 1\nA 1$ bill - 2\nA 2$ bill - 1\nA 3$ bill - 1\nA 4$ bill - 1" )
def test_total_when_cash_desk_is_not_empty(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)) result = desk.total() expexted = 390 self.assertEqual(result, expexted)
def test_inspect_with_full_desk(self): desk = CashDesk() desk.take_money(Bill(1)) desk.take_money(Bill(2)) desk.take_money(Bill(10)) expected = ["We have 13$ in the desk."] expected.append("Bills are:") expected.append("$1 - 1") expected.append("$2 - 1") expected.append("$10 - 1") self.assertEqual("\n".join(expected), desk.inspect())
def test_if_totall_sum_is_right(self): desk = CashDesk() exp = 190 ls = [10,20,50,100] bills = [Bill(value) for value in ls] batch = BillBatch(bills) desk.take_money(Bill(10)) desk.take_money(batch) res = desk.total() self.assertEqual(res, exp)
def test_total_amount_of_money_in_the_desk_with_bills(self): Bill.money_holder = {} a = Bill(10) b = Bill(20) c = Bill(30) desk = CashDesk() desk.take_money(a) desk.take_money(b) desk.take_money(c) total = desk.total() self.assertEqual(total, 60)
def test_if_bills_are_taken_from_desk(self): desk = CashDesk() ls = [10,20,50,100] bills = [Bill(value) for value in ls] batch = BillBatch(bills) desk.take_money(Bill(10)) desk.take_money(batch) self.assertEqual(str(desk[0]),'A 10$ bill.') self.assertEqual(str(desk[3]),'A 50$ bill.')
def test_total_zero_when_new_instance_made(self): new_cash_desk = CashDesk() self.assertEqual(0, new_cash_desk.total())
def test_when_inspect_then_print_table_repr_of_cash_desk(self): test_cashdesk = CashDesk() test_cashdesk.take_money(BillBatch([Bill(10), Bill(10), Bill(20)])) expected_result = '$10 bills - 2\n$20 bills - 1\n' self.assertEqual(test_cashdesk.inspect(), expected_result)
def test_inspect_on_empty_desk(self): desk = CashDesk() expected = "We have 0$ in the desk." self.assertEqual(desk.inspect(), expected)
from cashdesk import Bill, BillBatch, CashDesk values = [10, 20, 50, 100, 100, 100] bills = [Bill(value) for value in values] batch = BillBatch(bills) desk = CashDesk() desk.take_money(Bill(10)) desk.take_money(batch) print(desk.total()) # 390 desk.inspect() # We have a total of 390$ in the desk # We have the following count of bills, sorted in ascending order: # 10$ bills - 2 # 20$ bills - 1 # 50$ bills - 1 # 100$ bills - 3
def test_take_money_when_a_billbatch_is_added(self): test_cashdesk = CashDesk() test_cashdesk.take_money(BillBatch([Bill(10), Bill(10), Bill(20)])) expected_result = 3 self.assertEqual(test_cashdesk.number_of_bills(), expected_result)
def test_take_money_when_one_of_items_in_list_is_not_bill_then_return_type_error( self): with self.assertRaises(TypeError): test_cashdesk = CashDesk() test_cashdesk.take_money(10)
def test_take_money_when_single_bill_is_added(self): test_cashdesk = CashDesk() test_cashdesk.take_money(Bill(10)) expected_result = 1 self.assertEqual(test_cashdesk.number_of_bills(), expected_result)
def create_cash_desc(self): with self.assertRaises(TypeError): CashDesk('asd')
def test_can_withdraw_money_all_money(self): new_cash_desk = CashDesk() new_cash_desk.take_money({1: 2, 100: 3}) self.assertTrue(new_cash_desk.can_withdraw_money(301))
def test_cant_withdraw_money_not_all_money(self): new_cash_desk = CashDesk() new_cash_desk.take_money({1: 2, 100: 3}) self.assertFalse(new_cash_desk.can_withdraw_money(105))
def test_total_after_money_take(self): new_cash_desk = CashDesk() new_cash_desk.take_money({1: 2, 100: 3}) self.assertEqual(302, new_cash_desk.total())
def test_when_total_then_return_sum_of_amounts_of_all_bills_in_cashdesk( self): test_cashdesk = CashDesk() test_cashdesk.take_money(BillBatch([Bill(10), Bill(10), Bill(20)])) expected_result = 40 self.assertEqual(test_cashdesk.total(), expected_result)
from cashdesk import Bill, BillBatch, CashDesk 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)) print(desk.total()) # 390 desk.inspect() # We have a total of 390$ in the desk # We have the following count of bills, sorted in ascending order: # 10$ bills - 2 # 20$ bills - 1 # 50$ bills - 1 # 100$ bills - 3
#!/usr/bin/env python3 from cashdesk import Bill, BatchBill, CashDesk values = [10, 20, 50, 100, 100, 100] bills = [Bill(value) for value in values] batch = BatchBill(bills) print(batch.nominals) print(batch.total()) desk = CashDesk() desk.take_money(Bill(5)) desk.take_money(batch) desk.take_money(Bill(5)) desk.take_money(batch) print(desk.inspect())