Genetic Turmit Evolver
python
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_rpnexpr.py 767B

123456789101112131415161718192021222324252627
  1. import unittest
  2. from gte.turmit import Turmit
  3. from gte.rpnlib import _op_list, RpnSymbol, RpnExpr
  4. class RpnExprTestCase(unittest.TestCase):
  5. def test_init(self):
  6. expr = RpnExpr()
  7. def test_random(self):
  8. expr = RpnExpr.random(5)
  9. self.assertEqual(len(expr), 5)
  10. def test_fromstring(self):
  11. expr = RpnExpr.from_string(""" 5 0xFF
  12. X
  13. \tMOD""")
  14. self.assertEqual(len(expr), 4)
  15. tests = ((RpnSymbol.VALUE, 5),
  16. (RpnSymbol.VALUE, 255),
  17. (RpnSymbol.VARIABLE, 'x'),
  18. (RpnSymbol.OPERATION, 'mod'))
  19. for i, (optype, val) in enumerate(tests):
  20. self.assertEqual(expr[i].optype, optype)
  21. self.assertEqual(expr[i].value, val)