| | |
| | | except (ValueError, TypeError): |
| | | self.type = STRING |
| | | self.formatted_value = None |
| | | self.type = STRING |
| | | if formatting is not None: |
| | | self.format_as(formatting) |
| | | self.format_float(formatting) |
| | | self.formatting = formatting |
| | | # self.formatter=FormatterFactory(formatting) |
| | | |
| | | def format_as(self, formatting=None): |
| | | def format_float(self, formatting=None): |
| | | if self.type != STRING: |
| | | if formatting is None: |
| | | formatting = self.formatting |
| | | formatter = FormatterFactory.get_formatter(formatting) |
| | | self.formatted_value = formatter.toFormat(self.value) |
| | | self.formatted_value = formatter.getValue(self.value) |
| | | |
| | | def format_as_tex(self, formatting=None): |
| | | if self.type != STRING: |
| | |
| | | man, int(exp) |
| | | ) |
| | | |
| | | def getValue(self, num): |
| | | exp = self.fexp(num) |
| | | man = self.fman(num) |
| | | man = ("{:." + str(self.precision - 1) + "f}e{}").format( |
| | | man, int(exp)) |
| | | return float(man) |
| | | |
| | | class EngFloatFormatter(FormatterFactory): |
| | | def __init__(self, formatparameters): |
| | |
| | | "$0.00 \cdot 10^{0}$", |
| | | ] |
| | | sci2 = Formatter.FormatterFactory().get_formatter("sci 2") |
| | | for case, result in zip(testcases,sci2_solutions): |
| | | for case, result in zip(testcases, sci2_solutions): |
| | | self.assertEqual(result, sci2.toFormat(case)) |
| | | |
| | | sci3 = Formatter.FormatterFactory().get_formatter("sci 3") |
| | | for case, result in zip(testcases,sci3_solutions): |
| | | for case, result in zip(testcases, sci3_solutions): |
| | | self.assertEqual(result, sci3.toFormat(case)) |
| | | |
| | | def test_valueClass(self): |
| | |
| | | "$0.00 \cdot 10^{0}$", |
| | | ] |
| | | |
| | | for case,result in zip (testcases, sci2_solutions): |
| | | for case, result in zip(testcases, sci2_solutions): |
| | | self.assertEqual(result, Formatter.Variable(case, "sci 2").format_as_tex()) |
| | | |
| | | |
| | | for case,result in zip (testcases, sci3_solutions): |
| | | self.assertEqual(result, Formatter.Variable(case, "sci 3").format_as_tex()) |
| | | for case, result in zip(testcases, sci3_solutions): |
| | | self.assertEqual(result, Formatter.Variable(case, "sci 3").format_as_tex()) |