Пример #1
0
 def _generate_formula(description, variable_addresses):
     converter = FormulaConverter(variable_addresses)
     for formula in converter.extract_formulae(description):
         dynamic_coordinates = '="{0}"&{1}'.format(converter.get_orientation(formula),
                                                   '&'.join(converter.split(formula)))
         yield dynamic_coordinates
Пример #2
0
 def test_resolve_normalization_of_braces(self):
     expected = '()'
     converter = FormulaConverter(variable_addresses={'A': 0})
     for text in ['()', '{}', '[]']:
         actual = converter._normalize(text=text)
         self.assertEqual(actual, expected)
Пример #3
0
 def test_resolve_dual_digit_variable(self):
     expected = '(10*C0+1*C1)'
     converter = FormulaConverter(variable_addresses={'A': 0, 'B': 1})
     actual = converter._resolve_formula(text='AB')
     self.assertEqual(actual, expected)
Пример #4
0
 def test_resolve_basic_math_operations(self):
     expected = 'C0 + C1 - C2 * C3 / C4'
     converter = FormulaConverter(variable_addresses={'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4})
     actual = converter._resolve_formula(text='A + B - C * D / E', )
     self.assertEqual(actual, expected)
Пример #5
0
 def test_resolve_casual_math_operations_without_variable_conflict(self):
     expected = 'A * B / C'
     converter = FormulaConverter(variable_addresses={'A': 0, 'B': 1, 'C': 2})
     actual = converter._normalize(text='A x B / C')
     self.assertEqual(actual, expected)
Пример #6
0
 def test_resolve_simple_formula(self):
     expected = 'C0 + C1'
     converter = FormulaConverter(variable_addresses={'A': 0, 'B': 1})
     actual = converter._resolve_formula(text='A + B')
     self.assertEqual(actual, expected)
Пример #7
0
 def test_resolve_reference_of_unknown_variable(self):
     expected = 'A'
     converter = FormulaConverter(variable_addresses={'B': 0})
     actual = converter._resolve_formula(text='A')
     self.assertEqual(actual, expected)
Пример #8
0
 def test_mask_screws_up_static_coordinates(self):
     given = 'Der Schatz liegt bei N 47° 12.345 E 008° 12.345, wobei'
     expected = 'Der Schatz liegt bei |N| 47° 12.345 |E| 008° 12.345, wobei'
     converter = FormulaConverter(variable_addresses=TestFormulaConverter._SAMPLE_ADDRESSES)
     actual = converter._mask_orientation(given)
     self.assertEqual(actual, expected)
Пример #9
0
 def test_mask_ignores_variables_in_longitude_orientation(self):
     given = 'Der Schatz liegt bei N 47° PQ.RST E 008° VW.XYZ, wobei'
     expected = 'Der Schatz liegt bei |N| 47° PQ.RST |E| 008° VW.XYZ, wobei'
     converter = FormulaConverter(variable_addresses=TestFormulaConverter._SAMPLE_ADDRESSES)
     actual = converter._mask_orientation(given)
     self.assertEqual(actual, expected)
Пример #10
0
 def test_mask_alters_double_dimension_match(self):
     given = 'Der Schatz liegt bei N 47° PQ.ABC E 008° VW.XYZ, wobei'
     expected = 'Der Schatz liegt bei |N| 47° PQ.ABC |E| 008° VW.XYZ, wobei'
     converter = FormulaConverter(variable_addresses=TestFormulaConverter._SAMPLE_ADDRESSES)
     actual = converter._mask_orientation(given)
     self.assertEqual(actual, expected)
Пример #11
0
 def test_mask_doesnt_alter_if_no_match(self):
     given = expected = 'Der Schatz liegt bei N 47 PQ.RST E 008 VW.XYZ, wobei'  # no match because missing °
     converter = FormulaConverter(variable_addresses=TestFormulaConverter._SAMPLE_ADDRESSES)
     actual = converter._mask_orientation(given)
     self.assertEqual(actual, expected)
Пример #12
0
 def test_match_static_coordinates(self):
     expected = []
     converter = FormulaConverter(variable_addresses=TestFormulaConverter._SAMPLE_ADDRESSES)
     actual = converter.extract_formulae('N 47° 30.847')
     self.assertEqual(list(actual), expected)