Parser of berki style problems and generator of latex file
Samo Penic
2018-11-24 8fe4d9b44bde3cec33314bcafe2130b6e4dac7af
Dec debbuged and unit tests done.
2 files modified
167 ■■■■■ changed files
aoi_gen/Variable.py 26 ●●●●● patch | view | raw | blame | history
aoi_gen/tests/formatter_test.py 141 ●●●●● patch | view | raw | blame | history
aoi_gen/Variable.py
@@ -130,18 +130,13 @@
        num=float(("{:."+str(self.precision-1)+"e}").format(num))
        places=self.fexp(num)
        if(places>0):
            decimal_places=self.precision-places-1
            if(decimal_places<0):
                decimal_places=0
            format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
        else:
            format_str="{:."+str(self.precision)+"f}"
        decimal_places=self.precision-places-1
        if(decimal_places<0):
            decimal_places=0
        format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
        return (
        return format_str.format(num).replace(".", ",\!")
                format_str.format(num).replace(".", ",\!")
            )
    def getValue(self, num):
@@ -149,13 +144,10 @@
        num=float(("{:."+str(self.precision-1)+"e}").format(num))
        places=self.fexp(num)
        if(places>0):
            decimal_places=self.precision-places-1
            if(decimal_places<0):
                decimal_places=0
            format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
        else:
            format_str="{:."+str(self.precision)+"f}"
        decimal_places=self.precision-places-1
        if(decimal_places<0):
            decimal_places=0
        format_str="{:"+str(places)+"."+str(decimal_places)+"f}"
        val=format_str.format(num)
        return float(val)
aoi_gen/tests/formatter_test.py
@@ -28,32 +28,34 @@
            0,
        ]
        sci2_solutions = [
            "1.2",
            "1.2",
            "3.0",
            "3.5",
            "5.0 \cdot 10^{-2}",
            "-1.2",
            "-3.0",
            "1.1 \cdot 10^{-6}",
            "-1.1 \cdot 10^{6}",
            "9.8 \cdot 10^{255}",
            "0.0",
            "1,\!2",
            "1,\!2",
            "3,\!0",
            "3,\!5",
            "5,\!0 \cdot 10^{-2}",
            "-1,\!2",
            "-3,\!0",
            "1,\!1 \cdot 10^{-6}",
            "-1,\!1 \cdot 10^{6}",
            "9,\!8 \cdot 10^{255}",
            "0,\!0",
        ]
        sci3_solutions = [
            "1.24",
            "1.20",
            "3.00",
            "3.50",
            "5.00 \cdot 10^{-2}",
            "-1.23",
            "-3.00",
            "1.12 \cdot 10^{-6}",
            "-1.12 \cdot 10^{6}",
            "9.81 \cdot 10^{255}",
            "0.00",
            "1,\!24",
            "1,\!20",
            "3,\!00",
            "3,\!50",
            "5,\!00 \cdot 10^{-2}",
            "-1,\!23",
            "-3,\!00",
            "1,\!12 \cdot 10^{-6}",
            "-1,\!12 \cdot 10^{6}",
            "9,\!81 \cdot 10^{255}",
            "0,\!00",
        ]
        sci2 = Variable.FormatterFactory().get_formatter("sci 2")
        for case, result in zip(testcases, sci2_solutions):
            self.assertEqual(result, sci2.toFormat(case))
@@ -61,6 +63,57 @@
        sci3 = Variable.FormatterFactory().get_formatter("sci 3")
        for case, result in zip(testcases, sci3_solutions):
            self.assertEqual(result, sci3.toFormat(case))
    def test_additionalDecTests(self):
        testcases = [
            1.235678910111213,
            1.2,
            3,
            "3.5",
            "0.05",
            -1.2343567,
            -3,
            1.123e-6,
            -1.123e6,
            0,
            32,
        ]
        dec2_solutions = [
            "1,\!2",
            "1,\!2",
            "3,\!0",
            "3,\!5",
            "0,\!050",
            "-1,\!2",
            "-3,\!0",
            "0,\!0000011",
            "-1100000",
            "0,\!0",
            "32"
        ]
        dec1_solutions=[
            "1",
            "1",
            "3",
            "4",
            "0,\!05",
            "-1",
            "-3",
            "0,\!000001",
            "-1000000",
            "0",
            "30",
        ]
        dec2 = Variable.FormatterFactory().get_formatter("dec 2")
        for case, result in zip(testcases, dec2_solutions):
            self.assertEqual(result, dec2.toFormat(case))
        dec1 = Variable.FormatterFactory().get_formatter("dec 1")
        for case, result in zip(testcases, dec1_solutions):
            self.assertEqual(result, dec1.toFormat(case))
    def test_valueClass(self):
        testcases = [
@@ -77,31 +130,31 @@
            0,
        ]
        sci2_solutions = [
            "1.2",
            "1.2",
            "3.0",
            "3.5",
            "5.0 \cdot 10^{-2}",
            "-1.2",
            "-3.0",
            "1.1 \cdot 10^{-6}",
            "-1.1 \cdot 10^{6}",
            "9.8 \cdot 10^{255}",
            "0.0",
            "$1,\!2\,$",
            "$1,\!2\,$",
            "$3,\!0\,$",
            "$3,\!5\,$",
            "$5,\!0 \cdot 10^{-2}\,$",
            "$-1,\!2\,$",
            "$-3,\!0\,$",
            "$1,\!1 \cdot 10^{-6}\,$",
            "$-1,\!1 \cdot 10^{6}\,$",
            "$9,\!8 \cdot 10^{255}\,$",
            "$0,\!0\,$",
        ]
        sci3_solutions = [
            "1.24",
            "1.20",
            "3.00",
            "3.50",
            "5.00 \cdot 10^{-2}",
            "-1.23",
            "-3.00",
            "1.12 \cdot 10^{-6}",
            "-1.12 \cdot 10^{6}",
            "9.81 \cdot 10^{255}",
            "0.00",
            "$1,\!24\,$",
            "$1,\!20\,$",
            "$3,\!00\,$",
            "$3,\!50\,$",
            "$5,\!00 \cdot 10^{-2}\,$",
            "$-1,\!23\,$",
            "$-3,\!00\,$",
            "$1,\!12 \cdot 10^{-6}\,$",
            "$-1,\!12 \cdot 10^{6}\,$",
            "$9,\!81 \cdot 10^{255}\,$",
            "$0,\!00\,$",
        ]
        sci2_rounded = [