def test_dunder_len_should_return_length_of_the_list(self): lst = [Bill(2), Bill(3)] batch = BillBatch(lst) result = len(batch) self.assertTrue(result == 2)
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_dunder_eq_should_return_boolean(self): bill1 = Bill(5) bill2 = Bill(5) bill3 = Bill(10) self.assertTrue(bill1 == bill2) self.assertFalse(bill1 == bill3)
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(self): bills = [Bill(10), Bill(30), Bill(15), Bill(5)] batch = BillBatch(bills) result = batch.total() self.assertEqual(result, 60)
def test_init_dunder_with_list_of_non_bills(self): e = None try: BatchBill([Bill(5), Bill(10), "stringiboi", Bill(15)]) except TypeError as exc: e = exc self.assertIsNotNone(e) self.assertEqual(str(e), "Non-bill bill.")
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_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
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_bills_type(self): bills = [Bill(10), Bill(20), 30] exc = None try: BillBatch(bills) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), 'Wrong type!')
def test_eq_dunder(self): e = None val1 = [1, 2, 3] val2 = [3, 2, 1] val3 = [1, 3, 5] bills1 = [Bill(val) for val in val1] bills2 = [Bill(val) for val in val2] bills3 = [Bill(val) for val in val3] batch1 = BatchBill(bills1) batch2 = BatchBill(bills2) batch3 = BatchBill(bills3) self.assertTrue(batch1 == batch2, "Unexpectedly, Batch1 != Batch2") self.assertFalse(batch2 == batch3, "Unexpectedly, Batch2 == Batch3") self.assertFalse(batch1 == batch3, "Unexpectedly, Batch1 == Batch3")
def test_init_dunder(self): e = None bill5 = Bill(5) bill10 = Bill(10) try: batch1 = BatchBill([bill5, bill10]) batch2 = BatchBill([bill5]) except Exception as exc: e = exc self.assertIsNone(e) self.assertEqual(bill5, batch1.__dict__["bills"][0]) self.assertEqual(bill10, batch1.__dict__["bills"][1]) self.assertEqual(bill5, batch2.__dict__["bills"][0])
def test_getitem_dunder(self): e = None billList = [Bill(i) for i in range(1, 5)] batch = BatchBill(billList) res = [] expected = [Bill(1), Bill(2), Bill(3), Bill(4)] try: for item in batch: res.append(item) except Exception as exc: e = exc self.assertIsNone(e) self.assertEqual(expected, res)
def test_hash_dunder(self): e = None bill1 = Bill(1) bill2 = Bill(1) di = dict() try: di[bill1] = 1 di[bill2] = 2 except Exception as exc: e = exc self.assertIsNone(e) self.assertEqual(1, len(di)) self.assertNotEqual(2, len(di)) self.assertEqual(di[bill1], 2)
def test_total_returns_correct_result(self): values = [10, 20, 50, 100] bills = [Bill(value) for value in values] batch = BillBatch(bills) x = batch.total() self.assertEqual(x, 180)
def test_string_representation(self): bill = Bill(10) result = str(bill) expected = 'A 10$ bill' self.assertEqual(result, expected)
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 test_hash_dunder_with_mutation(self): e = None bill1 = Bill(1) bill2 = Bill(2) di = dict() try: di[bill1] = 1 di[bill2] = 2 setattr(bill2, "__amount", 1) except AttributeError as exc: e = exc self.assertIsNotNone(e) self.assertEqual(str(e), "Can't change bill amount!") self.assertEqual(di[bill1], 1) self.assertEqual(di[bill2], 2)
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_with_negative_number(self): exc = None try: b = Bill(-5) except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), "The amount cannot be negative number!")
def test_with_string_as_input(self): exc = None try: b = Bill("5") except Exception as err: exc = err self.assertIsNotNone(exc) self.assertEqual(str(exc), "The amount must be integer!")
def test_init_dunder_with_bad_type(self): e = None try: Bill("stringiboi") except Exception as exc: e = exc self.assertIsNotNone(e) self.assertEqual(str(e), "A non-integer bill.")
def test_raising_of_value_error_for_negative_bill_amount(self): exc = None try: Bill(-3) except Exception as err: exc = err self.assertEqual(str(exc), 'Amount cannot be a negative number.')
def test_getitem(self): values = [1, 2, 5, 10] bills = [Bill(value) for value in values] batch = BatchBill(bills) result = str(batch[3]) expected = 'A $10 bill' self.assertEqual(result, expected)
def test_showing_batch_lenght(self): values = [1, 2, 5, 10] bills = [Bill(value) for value in values] batch = BatchBill(bills) result = len(batch) expected = 4 self.assertEqual(result, expected)
def test_init_dunder(self): e = None try: bill = Bill(10) except Exception as exc: e = exc self.assertIsNone(e) self.assertEqual(10, getattr(bill, "_Bill__amount"))
def test_init_dunder_with_bad_integer_value(self): e1 = None e2 = None try: Bill(-10) except Exception as exc: e1 = exc try: Bill(0) except Exception as exc: e2 = exc self.assertIsNotNone(e1) self.assertEqual(str(e1), "Negative or zero bill.") self.assertIsNotNone(e2) self.assertEqual(str(e2), "Negative or zero bill.")
def test_showing_total_amount_in_batch(self): values = [1, 2, 5, 10] bills = [Bill(value) for value in values] batch = BatchBill(bills) result = batch.total() expected = 18 self.assertEqual(result, expected)
def test_constructor_if_given_list_is_not_from_Bills(self): lst = [Bill(2), 2] exc = None try: BillBatch(lst) except TypeError as err: exc = err self.assertIsNotNone(exc)