コード例 #1
0
 def test_total(self):
     my_CashDesk = CashDesk()
     my_CashDesk.take_money({1: 2, 100: 3})
     self.assertEqual(302, my_CashDesk.total())
     my_CashDesk.take_money({1: 2, 100: 3})
     self.assertEqual(604, my_CashDesk.total())
     my_CashDesk.take_money({1: 0, 100: 0, 50: 0, 20: 0, 10: 0, 5: 0, 2: 0})
     self.assertEqual(604, my_CashDesk.total())
     my_CashDesk.take_money({1: 1, 100: 1, 50: 1, 20: 1, 10: 1, 5: 1, 2: 1})
     self.assertEqual(792, my_CashDesk.total())
コード例 #2
0
 def test_take_money(self):
     my_CashDesk = CashDesk()
     self.assertEqual({
         1: 2,
         100: 3,
         50: 0,
         20: 0,
         10: 0,
         5: 0,
         2: 0
     }, my_CashDesk.take_money({
         1: 2,
         100: 3
     }))
     self.assertEqual({
         1: 3,
         100: 4,
         50: 1,
         20: 1,
         10: 1,
         5: 1,
         2: 1
     },
                      my_CashDesk.take_money({
                          1: 1,
                          100: 1,
                          2: 1,
                          5: 1,
                          10: 1,
                          20: 1,
                          50: 1
                      }))
     my_CashDesk = CashDesk()
     self.assertEqual({
         100: 0,
         50: 0,
         20: 0,
         10: 0,
         5: 0,
         2: 0,
         1: 0
     }, my_CashDesk.take_money({}))
コード例 #3
0
def main():
    #a = Bill(20)
    #print(a)
    #print(repr(a))
    #b = Bill(30)
    #a == 2
    #print(a==b)
    
    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()
コード例 #4
0
class CashDeskTest(unittest.TestCase):
    def setUp(self):
        self.cash_desk = CashDesk()

    def test_cashdesk_empty_when_created(self):
        self.assertEqual(self.cash_desk.money, {
            100: 0,
            50: 0,
            20: 0,
            10: 0,
            5: 0,
            2: 0,
            1: 0
        })
        self.assertEqual(self.cash_desk.total(), 0)

    def test_take_money(self):
        self.cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertEqual(self.cash_desk.total(), 72)
        self.cash_desk.take_money({1: 1, 2: 1, 5: 1, 20: 1})
        self.assertEqual(self.cash_desk.total(), 100)

    def test_can_withdraw_money(self):
        self.cash_desk.take_money({50: 1, 100: 2})
        self.assertTrue(self.cash_desk.can_withdraw_money(250))
        self.assertTrue(self.cash_desk.can_withdraw_money(150))
        self.assertFalse(self.cash_desk.can_withdraw_money(70))
        self.assertFalse(self.cash_desk.can_withdraw_money(180))
コード例 #5
0
 def test_take_money_negative(self):
     my_CashDesk = CashDesk()
     self.assertEqual({
         1: 0,
         100: 3,
         50: 0,
         20: 0,
         10: 0,
         5: 0,
         2: 0
     }, my_CashDesk.take_money({
         1: -2,
         100: 3
     }))
コード例 #6
0
class CashDeskTests(unittest.TestCase):
    def setUp(self):
        self.my_cash_desk = CashDesk()

    def test_init(self):
        self.assertEqual({100: 0, 50: 0, 20: 0, 10: 0, 5: 0, 2: 0, 1: 0}, self.my_cash_desk.money)

    def test_take_money(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertEqual({100: 0, 50: 1, 20: 1, 10: 0, 5: 0, 2: 0, 1: 2}, self.my_cash_desk.money)

    def test_total(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertEqual(72, self.my_cash_desk.total())

    def test_can_withdraw_money_no_such_banknotes(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertFalse(self.my_cash_desk.can_withdraw_money(30))

    def test_can_withdraw_money_possible(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertTrue(self.my_cash_desk.can_withdraw_money(70))
コード例 #7
0
class CashDeskTests(unittest.TestCase):
    def setUp(self):
        self.my_cash_desk = CashDesk()

    def test_init(self):
        self.assertEqual({
            100: 0,
            50: 0,
            20: 0,
            10: 0,
            5: 0,
            2: 0,
            1: 0
        }, self.my_cash_desk.money)

    def test_take_money(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertEqual({
            100: 0,
            50: 1,
            20: 1,
            10: 0,
            5: 0,
            2: 0,
            1: 2
        }, self.my_cash_desk.money)

    def test_total(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertEqual(72, self.my_cash_desk.total())

    def test_can_withdraw_money_no_such_banknotes(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertFalse(self.my_cash_desk.can_withdraw_money(30))

    def test_can_withdraw_money_possible(self):
        self.my_cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertTrue(self.my_cash_desk.can_withdraw_money(70))
コード例 #8
0
class CashDeskTest(unittest.TestCase):

    def setUp(self):
        self.cash_desk = CashDesk()

    def test_cashdesk_empty_when_created(self):
        self.assertEqual(
            self.cash_desk.money, {100: 0, 50: 0, 20: 0, 10: 0,
                                   5: 0, 2: 0, 1: 0})
        self.assertEqual(self.cash_desk.total(), 0)

    def test_take_money(self):
        self.cash_desk.take_money({1: 2, 50: 1, 20: 1})
        self.assertEqual(self.cash_desk.total(), 72)
        self.cash_desk.take_money({1: 1, 2: 1, 5: 1, 20: 1})
        self.assertEqual(self.cash_desk.total(), 100)

    def test_can_withdraw_money(self):
        self.cash_desk.take_money({50: 1, 100: 2})
        self.assertTrue(self.cash_desk.can_withdraw_money(250))
        self.assertTrue(self.cash_desk.can_withdraw_money(150))
        self.assertFalse(self.cash_desk.can_withdraw_money(70))
        self.assertFalse(self.cash_desk.can_withdraw_money(180))
コード例 #9
0
 def test_can_withdraw_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))
コード例 #10
0
 def test_can_withdraw_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))
コード例 #11
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())
コード例 #12
0
 def can_withdraw_money(self):
     my_CashDesk = CashDesk()
     my_CashDesk.take_money({1: 2, 100: 3})
     self.assertTrue(my_CashDesk.can_withdraw_money(2))
     self.assertTrue(my_CashDesk.can_withdraw_money(302))
     self.assertFalse(my_CashDesk.can_withdraw_money(5))
コード例 #13
0
 def test_can_withdraw_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))
コード例 #14
0
 def test_can_withdraw_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))
コード例 #15
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())