예제 #1
0
    def test_total_function(self):
        values = [10, 20, 50, 100]
        bills = [Bill(value) for value in values]
        batch = BatchBill(bills)
        result = batch.total()

        self.assertEqual(result, 180)
예제 #2
0
    def test_total_sum_of_bills_when_no_bills(self):
        bills = []
        batchBill = BatchBill(bills)

        expected_sum = 0

        self.assertEqual(batchBill.total(), expected_sum)
예제 #3
0
    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)
예제 #4
0
class TestBatchBill(unittest.TestCase):
    def setUp(self):
        values = [10, 20, 50, 100]
        self.bills = [Bill(value) for value in values]
        self.batch_bill = BatchBill(list_of_bills=self.bills)

    def test___init___method_with_non_Bill_instance_in_list_of_bills(self):
        with self.assertRaises(TypeError):
            BatchBill([Bill(10), Bill(15), 'abc'])

    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 test___len___method(self):
        self.assertEqual(len(self.batch_bill), 4)

    def test_total_method(self):
        self.assertEqual(self.batch_bill.total(), 180)

    def test___getitem___method(self):
        _sum = 0
        for bill in self.batch_bill:
            _sum += int(bill)
        self.assertEqual(self.batch_bill[1], Bill(20))
        self.assertEqual(_sum, 180)