Parser of berki style problems and generator of latex file
Samo Penic
2018-11-03 c9c8d5997209b1f00b25a6bc2b7fa2b3fb186640
commit | author | age
404823 1 import unittest
c9c8d5 2 from aoi_gen import Variable
404823 3
SP 4
5 class FormatTest(unittest.TestCase):
6     def test_Exceptions(self):
7         exception_cases = [None, "hello"]
8         exception_results = [ValueError, ValueError]
9
6c2245 10         sci2 = Variable.FormatterFactory().get_formatter("sci 2")
404823 11         for case, result in zip(exception_cases, exception_results):
SP 12             with self.assertRaises(result):
13                 sci2.toFormat(case)
14
15     def test_inputStrings(self):
16         # test eng formatter
17         testcases = [
18             1.235678910111213,
19             1.2,
20             3,
21             "3.5",
22             "0.05",
23             -1.2343567,
24             -3,
25             1.123e-6,
26             -1.123e6,
27             9.8123e255,
28             0,
29         ]
30         sci2_solutions = [
78d798 31             "1.2",
SP 32             "1.2",
33             "3.0",
34             "3.5",
ef19a9 35             "5.0 \cdot 10^{-2}",
78d798 36             "-1.2",
SP 37             "-3.0",
ef19a9 38             "1.1 \cdot 10^{-6}",
SP 39             "-1.1 \cdot 10^{6}",
40             "9.8 \cdot 10^{255}",
78d798 41             "0.0",
404823 42         ]
SP 43
5288d6 44         sci3_solutions = [
78d798 45             "1.24",
SP 46             "1.20",
47             "3.00",
48             "3.50",
ef19a9 49             "5.00 \cdot 10^{-2}",
78d798 50             "-1.23",
SP 51             "-3.00",
ef19a9 52             "1.12 \cdot 10^{-6}",
SP 53             "-1.12 \cdot 10^{6}",
54             "9.81 \cdot 10^{255}",
78d798 55             "0.00",
5288d6 56         ]
6c2245 57         sci2 = Variable.FormatterFactory().get_formatter("sci 2")
33c054 58         for case, result in zip(testcases, sci2_solutions):
5288d6 59             self.assertEqual(result, sci2.toFormat(case))
SP 60
6c2245 61         sci3 = Variable.FormatterFactory().get_formatter("sci 3")
33c054 62         for case, result in zip(testcases, sci3_solutions):
5288d6 63             self.assertEqual(result, sci3.toFormat(case))
7b5760 64
SP 65     def test_valueClass(self):
66         testcases = [
67             1.235678910111213,
68             1.2,
69             3,
70             "3.5",
71             "0.05",
72             -1.2343567,
73             -3,
74             1.123e-6,
75             -1.123e6,
76             9.8123e255,
77             0,
78         ]
79         sci2_solutions = [
78d798 80             "1.2",
SP 81             "1.2",
82             "3.0",
83             "3.5",
ef19a9 84             "5.0 \cdot 10^{-2}",
78d798 85             "-1.2",
SP 86             "-3.0",
ef19a9 87             "1.1 \cdot 10^{-6}",
SP 88             "-1.1 \cdot 10^{6}",
89             "9.8 \cdot 10^{255}",
78d798 90             "0.0",
7b5760 91         ]
SP 92
93         sci3_solutions = [
78d798 94             "1.24",
SP 95             "1.20",
96             "3.00",
97             "3.50",
ef19a9 98             "5.00 \cdot 10^{-2}",
78d798 99             "-1.23",
SP 100             "-3.00",
ef19a9 101             "1.12 \cdot 10^{-6}",
SP 102             "-1.12 \cdot 10^{6}",
103             "9.81 \cdot 10^{255}",
78d798 104             "0.00",
7b5760 105         ]
SP 106
78d798 107         sci2_rounded = [
ef19a9 108             1.2,
SP 109             1.2,
110             3.0,
111             3.5,
112             0.05,
113             -1.2,
114             -3.0,
115             1.1e-6,
116             -1.1e6,
117             9.8e255,
78d798 118             0,
ef19a9 119         ]
33c054 120         for case, result in zip(testcases, sci2_solutions):
6c2245 121             self.assertEqual(result, Variable.Variable(case, "sci 2").format_as_tex())
7b5760 122
33c054 123         for case, result in zip(testcases, sci3_solutions):
6c2245 124             self.assertEqual(result, Variable.Variable(case, "sci 3").format_as_tex())
ef19a9 125
SP 126         for case, result in zip(testcases, sci2_rounded):
78d798 127             self.assertEqual(
SP 128                 result, Variable.Variable(case, "sci 2").get_formatted_value()
129             )