Пример #1
0
    def test_get_most_simple_representation(self):
        cpl = get_most_simple_representation(qc_sympify('1 + 1j'))
        self.assertIsInstance(cpl, str)
        self.assertTrue(bool(sympy.Eq(sympy.sympify(cpl), 1 + 1j)))

        integer = get_most_simple_representation(qc_sympify('3'))
        self.assertIsInstance(integer, int)
        self.assertEqual(integer, 3)

        flt = get_most_simple_representation(qc_sympify('3.1'))
        self.assertIsInstance(flt, float)
        self.assertEqual(flt, 3.1)

        st = get_most_simple_representation(qc_sympify('a + b'))
        self.assertIsInstance(st, str)
        self.assertEqual(st, 'a + b')
Пример #2
0
 def nested_get_most_simple_representation(list_or_expression):
     if isinstance(list_or_expression, list):
         return [
             nested_get_most_simple_representation(entry)
             for entry in list_or_expression
         ]
     else:
         return get_most_simple_representation(list_or_expression)
Пример #3
0
 def get_serialization_data(self) -> Union[str, float, int]:
     serialized = get_most_simple_representation(self._sympified_expression)
     if isinstance(serialized, str):
         return self.original_expression
     else:
         return serialized