def test_multi_count_receipt(self): imported_chocolate = Food(10, imported=True) imported_perfume = Basic(47.50, imported=True) receipt_2 = Receipt() receipt_2.add(imported_chocolate, count=2) receipt_2.add(imported_perfume, count=3) receipt_2.add(imported_chocolate, count=3) self.assertEqual(23.95, receipt_2.total_tax_amount) self.assertEqual(216.45, receipt_2.total_cost)
def test_receipt_str(self): book = Book(12.49) music_cd = Basic(14.99, name='music CD') chocolate = Food(0.85, name='chocolate bar') receipt_1 = Receipt() receipt_1.add(book) receipt_1.add(music_cd) receipt_1.add(chocolate) expected = "1 book: 12.49\n1 music CD: 16.49\n1 chocolate bar: 0.85\nSales Taxes: 1.50\nTotal: 29.83" self.assertEqual(expected, str(receipt_1)) receipt_empty = Receipt() expected = "\nSales Taxes: 0.00\nTotal: 0.00" self.assertEqual(expected, str(receipt_empty))
def test_receipt_dict(self): book = Book(12.49) music_cd = Basic(14.99, name='music CD') chocolate = Food(0.85, name='chocolate bar') receipt_1 = Receipt() receipt_1.add(book) receipt_1.add(music_cd) receipt_1.add(chocolate) expected = { 'items': [{ 'cost': 12.49, 'count': 1, 'imported': False, 'product': 'book', 'tax': 0.0 }, { 'cost': 16.49, 'count': 1, 'imported': False, 'product': 'music CD', 'tax': 1.5 }, { 'cost': 0.85, 'count': 1, 'imported': False, 'product': 'chocolate bar', 'tax': 0.0 }], 'total cost': 29.83, 'total sale taxes': 1.5 } self.assertEqual(expected, receipt_1.__dict__()) receipt_empty = Receipt() expected = {'items': [], 'total cost': 0, 'total sale taxes': 0} self.assertEqual(expected, receipt_empty.__dict__())
def test_total_tax(self): book = Book(12.49) music_cd = Basic(14.99) chocolate = Food(0.85) receipt_1 = Receipt() receipt_1.add(book) receipt_1.add(music_cd) receipt_1.add(chocolate) self.assertEqual(1.50, receipt_1.total_tax_amount) imported_chocolate = Food(10, imported=True) imported_perfume = Basic(47.50, imported=True) receipt_2 = Receipt() receipt_2.add(imported_chocolate) receipt_2.add(imported_perfume) self.assertEqual(7.65, receipt_2.total_tax_amount) imported_perfume_2 = Basic(27.99, imported=True) perfume = Basic(18.99) headache_pills = Medical(9.75) imported_chocolate_2 = Food(11.25, imported=True) receipt_3 = Receipt() receipt_3.add(imported_perfume_2) receipt_3.add(perfume) receipt_3.add(headache_pills) receipt_3.add(imported_chocolate_2) self.assertEqual(6.70, receipt_3.total_tax_amount)