Ejemplo n.º 1
0
    def testReceipt_add(self):
        receipt = Receipt()

        barcode = "ITEM000001"
        one_receipt_info = OneReceiptInfo(barcode, 2)

        receipt.add(one_receipt_info)
        self.assertEquals(receipt.receipt_infos[barcode], 2)
        receipt.add(one_receipt_info)
        self.assertEquals(receipt.receipt_infos[barcode], 4)
Ejemplo n.º 2
0
    def testReceipt_add(self):
        receipt = Receipt()

        barcode = "ITEM000001"
        one_receipt_info = OneReceiptInfo(barcode, 2)

        receipt.add(one_receipt_info)
        self.assertEquals(receipt.receipt_infos[barcode], 2)
        receipt.add(one_receipt_info)
        self.assertEquals(receipt.receipt_infos[barcode], 4)
Ejemplo n.º 3
0
    def parse(cls, input_file=_DEFAULT_INPUT_FILE):

        f = open(input_file)

        shopping_list = json.load(f, encoding='GBK')

        receipt = Receipt()

        for each in shopping_list:
            barcode, quantity = cls.parse_line(each)
            one_receipt_info = OneReceiptInfo(barcode, quantity)
            receipt.add(one_receipt_info)
        return receipt
Ejemplo n.º 4
0
def read_input(file_name):
    receipt = Receipt()

    print "INPUT"
    with open(file_name) as file:
        print "Input: %s" % file_name
        for line in file:
            print line.strip()
            quantity, description, price = parse_line(line.strip())
            receipt.add(quantity, description, price)

    print "OUTPUT"
    print receipt
Ejemplo n.º 5
0
class TestReceiptMethods(unittest.TestCase):
    def setUp(self):
        self.receipt = Receipt()

    def test_round(self):
        self.assertAlmostEqual(self.receipt._round(3.81, 0.05), 3.85)
        self.assertAlmostEqual(self.receipt._round(3.85, 0.05), 3.85)
        self.assertAlmostEqual(self.receipt._round(3.86, 0.05), 3.90)
        self.assertAlmostEqual(self.receipt._round(3.9, 0.05), 3.90)

    def test_imported_food(self):
        self.receipt.add(1, "imported box of chocolates", 11.25)
        self.assertAlmostEqual(self.receipt.tax[0], 0.05)
        self.assertAlmostEqual(self.receipt.calculate_final_price(0), 11.85)

    def test_local_food(self):
        self.receipt.add(1, "chocolate bar", 0.85)
        self.assertAlmostEqual(self.receipt.tax[0], 0.0)
        self.assertAlmostEqual(self.receipt.calculate_final_price(0), 0.85)

    def test_imported_general_product(self):
        self.receipt.add(1, "imported bottle of perfume", 47.5)
        self.assertAlmostEqual(self.receipt.tax[0], 0.15)
        self.assertAlmostEqual(self.receipt.calculate_final_price(0), 54.65)

    def test_general_product(self):
        self.receipt.add(1, "music CD", 14.99)
        self.assertAlmostEqual(self.receipt.tax[0], 0.10)
        self.assertAlmostEqual(self.receipt.calculate_final_price(0), 16.49)