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