test_rules_goniometry.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # vim: set fileencoding=utf-8 :
  2. from src.rules.goniometry import match_add_quadrants, add_quadrants, \
  3. match_negated_parameter, negated_sinus_parameter, \
  4. negated_cosinus_parameter, sin, cos
  5. from src.possibilities import Possibility as P
  6. from tests.rulestestcase import RulesTestCase, tree
  7. class TestRulesGoniometry(RulesTestCase):
  8. def test_match_add_quadrants(self):
  9. root = tree('sin t ^ 2 + cos t ^ 2')
  10. possibilities = match_add_quadrants(root)
  11. self.assertEqualPos(possibilities, [P(root, add_quadrants, ())])
  12. def test_add_quadrants(self):
  13. self.assertEqual(add_quadrants(None, ()), 1)
  14. def test_match_negated_parameter(self):
  15. s, c = tree('sin -t, cos -t')
  16. t = s[0]
  17. self.assertEqualPos(match_negated_parameter(s), \
  18. [P(s, negated_sinus_parameter, (t,))])
  19. self.assertEqualPos(match_negated_parameter(c), \
  20. [P(c, negated_cosinus_parameter, (t,))])
  21. def test_negated_sinus_parameter(self):
  22. s = tree('sin -t')
  23. t = s[0]
  24. self.assertEqual(negated_sinus_parameter(s, (t,)), -sin(+t))
  25. def test_negated_cosinus_parameter(self):
  26. c = tree('cos -t')
  27. t = c[0]
  28. self.assertEqual(negated_cosinus_parameter(c, (t,)), cos(+t))