test_rules_sort.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. from src.rules.sort import match_sort_polynome, swap_factors, \
  2. match_sort_molinome, iter_pairs
  3. from src.node import Scope
  4. from src.possibilities import Possibility as P
  5. from tests.rulestestcase import RulesTestCase, tree
  6. class TestRulesSort(RulesTestCase):
  7. def test_match_sort_molinome_constant(self):
  8. x, l2 = root = tree('x * 2')
  9. self.assertEqualPos(match_sort_molinome(root),
  10. [P(root, swap_factors, (Scope(root), x, l2))])
  11. root = tree('2x')
  12. self.assertEqualPos(match_sort_molinome(root), [])
  13. #def test_match_sort_molinome_variables(self):
  14. # y, x = root = tree('yx')
  15. # self.assertEqualPos(match_sort_molinome(root),
  16. # [P(root, swap_factors, (Scope(root), y, x))])
  17. # root = tree('xy')
  18. # self.assertEqualPos(match_sort_molinome(root), [])
  19. def test_swap_factors(self):
  20. x, l2 = root = tree('x * 2')
  21. self.assertEqualNodes(swap_factors(root, (Scope(root), x, l2)),
  22. l2 * x)