def test_total_money_when_desk_is_empty(self): desk = CashDesk() expected = 0 result = desk.total() self.assertEqual(result, expected)
def test_when_bills_are_unordered(self): batch = BatchBill([Bill(25), Bill(10), Bill(15), Bill(10)]) desk = CashDesk() desk.take_money(batch) expected = '10$ bills: 2\n15$ bills: 1\n25$ bills: 1\n' self.assertEqual(str(desk), expected)
def test_take_batch(self): batch = BatchBill([Bill(5), Bill(10), Bill(15)]) desk = CashDesk() expected_dict = {Bill(5): 1, Bill(10): 1, Bill(15): 1} desk.take_money(batch) self.assertEqual(desk.get_dict(), expected_dict)
def test_take_one_bill(self): bill = Bill(10) desk = CashDesk() expected_dict = {Bill(10): 1} desk.take_money(bill) self.assertEqual(desk.get_dict(), expected_dict)
def test_take_money_function_by_using_total_batch_test(self): values = [10, 20, 50, 100] bills = [Bill(value) for value in values] batch = BatchBill(bills) desk = CashDesk() desk.take_money(batch) result = desk.total() self.assertEqual(result, 180)
def test_take_no_bill(self): bill = None desk = CashDesk() expected_dict = {} desk.take_money(bill) self.assertEqual(desk.get_dict(), expected_dict)
def test_total_money(self): batch = BatchBill([Bill(5), Bill(10), Bill(15), Bill(10)]) desk = CashDesk() desk.take_money(batch) expected = 40 result = desk.total() self.assertEqual(result, expected)
def test_take_more_different_bills_consecutively(self): bill1 = Bill(10) bill2 = Bill(15) desk = CashDesk() expected_dict = {Bill(10): 1, Bill(15): 1} desk.take_money(bill1) desk.take_money(bill2) self.assertEqual(desk.get_dict(), expected_dict)
def test___str___method_with_one_Bill(self): desk = CashDesk() desk.take_money(Bill(100)) self.assertEqual(str(desk), '100$ bills - 1\n')
def test___str___method_with_not_any_money(self): self.assertEqual(str(CashDesk()), '')
def test_total_method_without_any_money(self): desk = CashDesk() self.assertEqual(desk.total(), 0)
def test_total_zero_when_new_instance_made(self): new_cash_desk = CashDesk() self.assertEqual(0, new_cash_desk.total())
def test_can_withdraw_money_cant_withdraw(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_can_withdraw_money_not_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_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_total_fuction(self): desk = CashDesk() result = desk.total() self.assertEqual(result, 0)
class TestCashDesk(unittest.TestCase): def setUp(self): self.bill = Bill(10) self.cash_desk = CashDesk() self.cash_desk.money = [Bill(5), Bill(20)] def test_take_money_method_with_a_Bill(self): self.cash_desk.take_money(self.bill) self.assertEqual(self.cash_desk.money, [Bill(5), Bill(20), Bill(10)]) def test_take_money_method_with_a_Batch_of_Bills(self): values = [10, 20, 50] bills = [Bill(value) for value in values] batch = BatchBill(bills) self.cash_desk.take_money(batch) self.assertEqual( self.cash_desk.money, [Bill(5), Bill(20), Bill(10), Bill(20), Bill(50)]) def test_take_money_method_with_invalid_argument(self): with self.assertRaises(TypeError): self.cash_desk.take_money('not Bill or BatchBill') def test_total_method_without_any_money(self): desk = CashDesk() self.assertEqual(desk.total(), 0) def test_total_method_with_money(self): self.assertEqual(self.cash_desk.total(), 25) self.cash_desk.take_money(Bill(100)) self.assertEqual(self.cash_desk.total(), 125) def test___str___method_with_not_any_money(self): self.assertEqual(str(CashDesk()), '') def test___str___method_with_one_Bill(self): desk = CashDesk() desk.take_money(Bill(100)) self.assertEqual(str(desk), '100$ bills - 1\n') def test___str___method(self): self.cash_desk.take_money(BatchBill([Bill(10), Bill(10), Bill(5)])) self.assertEqual(str(self.cash_desk), '5$ bills - 2\n' '10$ bills - 2\n' '20$ bills - 1\n') self.cash_desk.take_money(Bill(20)) self.cash_desk.take_money(Bill(10)) self.assertEqual(str(self.cash_desk), '5$ bills - 2\n' '10$ bills - 3\n' '20$ bills - 2\n')
def setUp(self): self.bill = Bill(10) self.cash_desk = CashDesk() self.cash_desk.money = [Bill(5), Bill(20)]
def test_take_money_function_by_using_total_bill_only_test(self): bill = Bill(10) desk = CashDesk() desk.take_money(bill) result = desk.total() self.assertEqual(result, 10)