コード例 #1
0
    def test_cashdesk_take_only_batch(self):
        desk = CashDesk()
        batch = BillBatch([Bill(10), Bill(5)])

        desk.take_money(batch)

        self.assertEqual(desk.total(), 15)
コード例 #2
0
    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())
コード例 #3
0
    def test_cashdesk_take_only_batch(self):
        desk = CashDesk()
        batch = BillBatch([Bill(10), Bill(5)])

        desk.take_money(batch)

        self.assertEqual(desk.total(), 15)
コード例 #4
0
    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())
コード例 #5
0
    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})
コード例 #6
0
    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})
コード例 #7
0
    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)
コード例 #8
0
 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)
コード例 #9
0
 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')
コード例 #10
0
    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})
コード例 #11
0
    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)
コード例 #12
0
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)
コード例 #13
0
ファイル: test_cashdesk.py プロジェクト: yyotova/Python101
    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)
コード例 #14
0
    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".')
コード例 #15
0
    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()
コード例 #16
0
    def test_cashdesk_take_only_bills(self):
        desk = CashDesk()

        desk.take_money(Bill(10))
        desk.take_money(Bill(5))

        self.assertEqual(desk.total(), 15)
コード例 #17
0
	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()
コード例 #18
0
    def test_cashdesk_take_only_bills(self):
        desk = CashDesk()

        desk.take_money(Bill(10))
        desk.take_money(Bill(5))

        self.assertEqual(desk.total(), 15)
コード例 #19
0
    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)
コード例 #20
0
    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"
        )
コード例 #21
0
    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)
コード例 #22
0
    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())
コード例 #23
0
	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)
コード例 #24
0
ファイル: test_cashdesk.py プロジェクト: yyotova/Python101
    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)
コード例 #25
0
	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.')
コード例 #26
0
    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())
コード例 #27
0
 def test_total_zero_when_new_instance_made(self):
     new_cash_desk = CashDesk()
     self.assertEqual(0, new_cash_desk.total())
コード例 #28
0
 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)
コード例 #29
0
    def test_inspect_on_empty_desk(self):
        desk = CashDesk()
        expected = "We have 0$ in the desk."

        self.assertEqual(desk.inspect(), expected)
コード例 #30
0
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
コード例 #31
0
 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)
コード例 #32
0
 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)
コード例 #33
0
 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')
コード例 #35
0
 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))
コード例 #36
0
 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))
コード例 #37
0
 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())
コード例 #38
0
 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)
コード例 #39
0
ファイル: test_cash_desk.py プロジェクト: m1h41l/week2
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
コード例 #40
0
#!/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())