Skip to content

Commit

Permalink
add test for run_step_by_step
Browse files Browse the repository at this point in the history
  • Loading branch information
noskill committed Nov 1, 2023
1 parent ec5a7c7 commit 92d136a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions python/tests/test_run_metta.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
from hyperon import MeTTa, Environment, E
from test_common import HyperonTestCase

Expand Down Expand Up @@ -68,6 +69,22 @@ def test_comments(self):
result = MeTTa(env_builder=Environment.test_env()).run(program)
self.assertEqual('[[1]]', repr(result))

def test_run_step_by_step(self):
program = '''
(= (TupleCount $tuple) (if (== $tuple ()) 0 (+ 1 (TupleCount (cdr-atom $tuple)))))
(= tup (1 2))
(= tup (3 4 5))
!(match &self (= tup $t) (TupleCount $t))
'''
runner = MeTTa(env_builder=Environment.test_env())
i = 0
for _state, results in runner.run_step_by_step(program):
pass
i += 1
print('number of steps ' + str(i))
self.assertLess(i, 600)
self.assertEqual(len(results[0]), 2)

def process_exceptions(self, results):
for result in results:
self.assertEqual(result, [E()])
Expand Down Expand Up @@ -95,3 +112,6 @@ def test_scripts(self):
self.process_exceptions(MeTTa(env_builder=Environment.test_env()).import_file(f"{pwd}/scripts/e3_match_states.metta"))
self.process_exceptions(MeTTa(env_builder=Environment.test_env()).import_file(f"{pwd}/scripts/f1_imports.metta"))


if __name__ == '__main__':
unittest.main()

0 comments on commit 92d136a

Please sign in to comment.