Parser of berki style problems and generator of latex file
Samo Penic
2018-11-25 32d3f2f0b9ba799d732255599e1731074a9e6e57
aoi_gen/tests/formatter_test.py
@@ -13,7 +13,6 @@
                sci2.toFormat(case)
    def test_inputStrings(self):
        # test eng formatter
        testcases = [
            1.235678910111213,
            1.2,
@@ -26,6 +25,8 @@
            -1.123e6,
            9.8123e255,
            0,
            45,
        ]
        sci2_solutions = [
            "1,\!2",
@@ -39,6 +40,7 @@
            "-1,\!1 \cdot 10^{6}",
            "9,\!8 \cdot 10^{255}",
            "0,\!0",
            "4,\!5 \cdot 10^{1}"
        ]
        sci3_solutions = [
@@ -53,8 +55,38 @@
            "-1,\!12 \cdot 10^{6}",
            "9,\!81 \cdot 10^{255}",
            "0,\!00",
            "4,\!50 \cdot 10^{1}"
        ]
        eng2_solutions = [
            "1,\!2",
            "1,\!2",
            "3,\!0",
            "3,\!5",
            "50 \cdot 10^{-3}",
            "-1,\!2",
            "-3,\!0",
            "1,\!1 \cdot 10^{-6}",
            "-1,\!1 \cdot 10^{6}",
            "9,\!8 \cdot 10^{255}",
            "0,\!0",
            "45"
        ]
        eng1_solutions = [
            "1",
            "1",
            "3",
            "4",
            "50 \cdot 10^{-3}",
            "-1",
            "-3",
            "1 \cdot 10^{-6}",
            "-1 \cdot 10^{6}",
            "10 \cdot 10^{255}",
            "0",
            "40"
        ]
        sci2 = Variable.FormatterFactory().get_formatter("sci 2")
        for case, result in zip(testcases, sci2_solutions):
@@ -64,6 +96,13 @@
        for case, result in zip(testcases, sci3_solutions):
            self.assertEqual(result, sci3.toFormat(case))
        eng1 = Variable.FormatterFactory().get_formatter("eng 1")
        for case, result in zip(testcases, eng1_solutions):
            self.assertEqual(result, eng1.toFormat(case))
        eng2 = Variable.FormatterFactory().get_formatter("eng 2")
        for case, result in zip(testcases, eng2_solutions):
            self.assertEqual(result, eng2.toFormat(case))
    def test_additionalDecTests(self):
@@ -79,6 +118,33 @@
            -1.123e6,
            0,
            32,
        ]
        prefix2_solutions =[
            "1,\!2\,",
            "1,\!2\,",
            "3,\!0\,",
            "3,\!5\,",
            "50\,\mathrm{m}",
            "-1,\!2\,",
            "-3,\!0\,",
            "1,\!1\,\mathrm{\\upmu}",
            "-1,\!1\,\mathrm{M}",
            "0,\!0\,",
            "32\,"
        ]
        prefix1_solutions = [
            "1\,",
            "1\,",
            "3\,",
            "4\,",
            "50\,\mathrm{m}",
            "-1\,",
            "-3\,",
            "1\,\mathrm{\\upmu}",
            "-1\,\mathrm{M}",
            "0\,",
            "30\,"
        ]
        dec2_solutions = [
            "1,\!2",
@@ -115,6 +181,14 @@
        for case, result in zip(testcases, dec1_solutions):
            self.assertEqual(result, dec1.toFormat(case))
        prefix2 = Variable.FormatterFactory().get_formatter("prefix 2")
        for case, result in zip(testcases, prefix2_solutions):
            self.assertEqual(result, prefix2.toFormat(case))
        prefix1 = Variable.FormatterFactory().get_formatter("prefix 1")
        for case, result in zip(testcases, prefix1_solutions):
            self.assertEqual(result, prefix1.toFormat(case))
    def test_valueClass(self):
        testcases = [
            1.235678910111213,
@@ -128,6 +202,7 @@
            -1.123e6,
            9.8123e255,
            0,
            45,
        ]
        sci2_solutions = [
            "$1,\!2\,$",
@@ -141,6 +216,7 @@
            "$-1,\!1 \cdot 10^{6}\,$",
            "$9,\!8 \cdot 10^{255}\,$",
            "$0,\!0\,$",
            "$4,\!5 \cdot 10^{1}\,$",
        ]
        sci3_solutions = [
@@ -155,6 +231,7 @@
            "$-1,\!12 \cdot 10^{6}\,$",
            "$9,\!81 \cdot 10^{255}\,$",
            "$0,\!00\,$",
            "$4,\!50 \cdot 10^{1}\,$",
        ]
        sci2_rounded = [
@@ -169,7 +246,26 @@
            -1.1e6,
            9.8e255,
            0,
            45
        ]
        sci1_rounded = [
            1,
            1,
            3,
            4,
            50e-3,
            -1,
            -3,
            1e-6,
            -1e6,
            10e255,
            0,
            40
        ]
        eng1_rounded=sci1_rounded
        eng2_rounded=sci2_rounded
        for case, result in zip(testcases, sci2_solutions):
            self.assertEqual(result, Variable.Variable(case, "sci 2").format_as_tex())
@@ -180,3 +276,16 @@
            self.assertEqual(
                result, Variable.Variable(case, "sci 2").get_formatted_value()
            )
        for case, result in zip(testcases, sci1_rounded):
            self.assertEqual(
                result, Variable.Variable(case, "sci 1").get_formatted_value()
            )
        for case, result in zip(testcases, eng1_rounded):
            self.assertEqual(
                result, Variable.Variable(case, "eng 1").get_formatted_value()
            )
        for case, result in zip(testcases, eng2_rounded):
            self.assertEqual(
                result, Variable.Variable(case, "eng 2").get_formatted_value()
            )