def test_with_given_bill_batch_should_return_total_sum_of_bills(self):
        batch = BillBatch([Bill(i) for i in range(1, 5)
                           ])  #bills with values: 1, 2, 3, 4

        result = batch.total()

        expected = 10

        self.assertEqual(result, expected)
    def test_with_given_bill_batch_with_more_than_zero_elements_should_return_length_of_batch(
            self):
        batch = BillBatch([Bill(i) for i in range(1, 5)])

        length = len(batch)

        self.assertEqual(length, len(batch.batch))
    def test_with_given_bill_batch_with_zero_elements_should_return_zero_as_length_of_batch(
            self):
        batch = BillBatch([])

        length = len(batch)

        self.assertEqual(length, len(batch.batch))
    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 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_multi_bill_cashdesk_should_return_amount_of_all_bills(
            self):
        cashdesk = Cashdesk()
        cashdesk.take_money(BillBatch([Bill(i) for i in range(1, 5)]))

        result = cashdesk.total()

        expected = sum(range(1, 5))

        self.assertEqual(result, expected)
    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_with_given_bill_batch_should_be_available_for_iteration(self):
        batch = BillBatch([Bill(i) for i in range(1, 5)])

        result = []
        for bill in batch:
            result.append(bill.amount)

        expected = [1, 2, 3, 4]

        self.assertEqual(result, expected)
    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 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 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 test_with_given_non_list_as_argument_should_raise_exception(self):
        bill_batch_argment = None

        exc = None
        try:
            batch = BillBatch(bill_batch_argment)
        except Exception as e:
            exc = e

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc),
            'Invalid argument given, argument needs to be of type list!')
    def test_with_given_list_of_non_bills_as_argument_should_raise_exception(
            self):
        bill_batch_argment = [1, 2, 3]

        exc = None
        try:
            batch = BillBatch(bill_batch_argment)
        except Exception as e:
            exc = e

        self.assertIsNotNone(exc)
        self.assertEqual(
            str(exc),
            'Invalid element of list given, argument needs to be list of elements of type Bill!'
        )
Ejemplo n.º 14
0
        sorted_list = sorted(list_of_money_in_table, key=lambda c: c.amount)
        for el in sorted_list:
            representation += str(str(el)[2:]) + 's - ' + str(
                self.money_table[el]) + '\n'
        return representation

    def inspect(self):
        print(self.__repr__())
        # return self.__repr__()   #used for unit testing


if __name__ == '__main__':
    cashdesk = Cashdesk()

    cashdesk.take_money(Bill(10))
    batch = BillBatch([Bill(i) for i in range(1, 5)])
    cashdesk.take_money(batch)
    cashdesk.inspect()

    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()