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_when_bills_are_not_equal(self): bill1 = Bill(5) bill2 = Bill(15) result = bill1 == bill2 self.assertFalse(result)
def test_with_given_two_bills_with_different_amounts_should_return_that_are_not_equal(self): amount_lhs = 10 amount_rhs = 20 bill_lhs = Bill(amount_lhs) bill_rhs = Bill(amount_rhs) self.assertNotEqual(bill_lhs, bill_rhs)
def test_total_sum_of_bills(self): bills = [Bill(5), Bill(10), Bill(15)] batch = BatchBill(bills) expected_sum = 30 self.assertEqual(batch.total(), expected_sum)
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)
def payment(bill: Bill, user: str) -> None: """Write information to bill object and send it to the database.""" if user == self.user1: bill.user1_paid = True bill.note += ( f"\n{self.user1_upper} paid {bill.owed_amount} " f"for bill (ID {bill.id}) " f"on {formatted_today()}, " "paying off their portion of the bill." ) else: bill.user2_paid = True bill.note += ( f"\n{self.user2_upper} paid {bill.owed_amount} " f"for bill (ID {bill.id}) " f"on {formatted_today()}, " "paying off their portion of the bill." ) if bill.user1_paid is True and bill.user2_paid is True: bill.paid = True self.db.pay_bill(bill) print(f"Bill ID {bill.id} has been completely paid off!") else: self.db.pay_bill(bill) print("You successfully paid your bill!")
def test_when_bills_are_equal(self): bill1 = Bill(5) bill2 = Bill(5) result = bill1 == bill2 self.assertTrue(result)
def test_len_of_batch(self): bills = [Bill(5), Bill(10), Bill(15)] batchBill = BatchBill(bills) expected_len = 3 self.assertEqual(len(batchBill), expected_len)
def test_sum_bills(self): bill1 = Bill(5) bill2 = Bill(15) expected = Bill(20) result = bill1 + bill2 self.assertEqual(result, expected)
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_index_of_some_Bill_in_BatchBill(self): values = [10, 20, 50, 100] bills = [Bill(value) for value in values] batch = BatchBill(bills) index = 3 result = batch[index] self.assertEqual(result, Bill(100))
def setUp(self): bills = [] bills.append(Bill(5)) bills.append(Bill(15)) bills.append(Bill(11)) bills.append(Bill(7)) bills.append(Bill(2)) self.batch_bill = BatchBill(bills) self.empty_batch_bill = BatchBill([])
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_with_given_list_of_bills_as_argument_should_raise_exception(self): bill_one = Bill(10) bill_two = Bill(20) bill_batch_argment = [bill_one, bill_two] batch = BillBatch(bill_batch_argment) self.assertEqual(type(batch), BillBatch) self.assertEqual(batch.batch, bill_batch_argment)
def test_with_given_bill_batch_should_be_available_to_return_bill_by_given_index( self): batch = BillBatch([Bill(i) for i in range(1, 5)]) result = batch[2] expected = Bill(3) #bill on pos 2 is A 3$ bill self.assertEqual(result, expected)
def new_month(self, month: int, year: int, bill: Bill) -> None: """ Advance to a new month in the contract, corresponding to <month> and <year>. This may be the first month of the contract. per minute and fixed cost. Store the <bill> argument in this contract and set the appropriate rate """ bill.add_fixed_cost(MTM_MONTHLY_FEE) bill.set_rates("MTM", MTM_MINS_COST) self.bill = bill
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_take_money_function_by_using_total_bill_and_batch_test(self): values = [10, 20, 50, 100] bills = [Bill(value) for value in values] batch = BatchBill(bills) bill = Bill(10) desk = CashDesk() desk.take_money(bill) desk.take_money(batch) result = desk.total() self.assertEqual(result, 190)
def test_with_given_empty_cashdesk_and_bill_batch_object_as_argument_should_add_all_bills_in_batch_to_table( self): cashdesk = Cashdesk() bill_batch = BillBatch([Bill(i) for i in (1, 5)]) take_money_bill_batch_argument = bill_batch cashdesk.take_money(take_money_bill_batch_argument) for i in (1, 5): self.assertEqual(cashdesk.money_table[Bill(i)], 1)
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 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_with_given_non_empty_cashdesk_and_bill_batch_object_as_argument_that_all_elements_in_it_exist_in_table_should_icrement_values_in_table( self): cashdesk = Cashdesk() bill_batch = BillBatch([Bill(i) for i in (1, 5)]) take_money_bill_batch_argument = bill_batch cashdesk.take_money(take_money_bill_batch_argument) cashdesk.take_money(take_money_bill_batch_argument) for i in (1, 5): self.assertEqual(cashdesk.money_table[Bill(i)], 2)
def do_GET(self): querypath = urlparse(self.path) filepath, query = querypath.path, querypath.query print(filepath) if filepath.endswith('/list'): bl = Bill() self._send_response(bl.get_list()) return else: self.show_index() return
def test_with_given_multi_bill_cashdesk_and_bill_occurs_more_than_ones_should_print_in_ascending_order_of_amount_of_bill( self): cashdesk = Cashdesk() cashdesk.take_money(Bill(10)) batch = BillBatch([Bill(i) for i in range(1, 5)]) cashdesk.take_money(batch) cashdesk.take_money(batch) expected = '1$ bills - 2\n2$ bills - 2\n3$ bills - 2\n4$ bills - 2\n10$ bills - 1\n' self.assertEqual(cashdesk.__repr__(), expected)
def new_month(self, month: int, year: int, bill: Bill) -> None: """ Advance to a new month in the contract, corresponding to <month> and <year>. This may be the first month of the contract. Store the <bill> argument in this contract and set the appropriate rate per minute and fixed cost. """ # didnt use month year parameters # why MTM mins_cost is less than cost of term_mins.handout says oppsite. bill.set_rates("MTM", MTM_MINS_COST) bill.add_fixed_cost(MTM_MONTHLY_FEE) self.bill = bill
def test___init___method(self): self.assertEqual(self.batch_bill.bills, [Bill(10), Bill(20), Bill(50), Bill(100)]) self.bills[0] = Bill(50) self.assertEqual(self.batch_bill.bills, [Bill(10), Bill(20), Bill(50), Bill(100)])
def new_month(self, month: int, year: int, bill: Bill) -> None: """ Advance to a new month in the contract, corresponding to <month> and <year>. This may be the first month of the contract. Store the <bill> argument in this contract and set the appropriate rate per minute and fixed cost. """ if self.balance > -10.00: self.balance -= 25 self.bill = bill bill.set_rates('Prepaid', PREPAID_MINS_COST) bill.add_fixed_cost(self.balance)
def main(): 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)) print(desk.total()) desk.inspect()
def test_with_given_non_empty_cashdesk_and_bill_object_as_argument_should_add_to_table( self): cashdesk = Cashdesk() bill_10_dollars = Bill(10) take_money_bill_argument = bill_10_dollars cashdesk.take_money(take_money_bill_argument) bill_20_dollars = Bill(20) take_money_bill_argument = bill_20_dollars cashdesk.take_money(take_money_bill_argument) self.assertEqual(cashdesk.money_table[bill_20_dollars], 1) self.assertEqual(cashdesk.money_table[bill_10_dollars], 1)
def test_with_given_multi_bill_cashdesk_and_bill_occurs_more_than_ones_should_return_amount_of_all_bills( self): cashdesk = Cashdesk() cashdesk.take_money(Bill(10)) batch = BillBatch([Bill(i) for i in range(1, 5)]) cashdesk.take_money(batch) cashdesk.take_money(batch) result = cashdesk.total() expected = sum(range(1, 5)) * 2 + 10 self.assertEqual(result, expected)
def billme(): my_bill = Bill("origin", ["gas"]) result = my_bill.all() print(result)