forked from trueagi-io/hyperon-experimental
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_metta.py
More file actions
44 lines (34 loc) · 1.16 KB
/
test_metta.py
File metadata and controls
44 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import unittest
from hyperon import *
class MettaTest(unittest.TestCase):
def test_adding_tokens_while_parsing(self):
metta = MeTTa()
atom = metta.parse_single('(A B)')
self.assertEqual(atom, E(S('A'), S('B')))
metta.register_atom('A', S('C'))
atom = metta.parse_single('(A B)')
self.assertEqual(atom, E(S('C'), S('B')))
metta.register_atom('A', S('F'))
atom = metta.parse_single('(A B)')
self.assertEqual(atom, E(S('F'), S('B')))
def test_metta_runner(self):
program = '''
(= (And T T) T)
(= (frog $x)
(And (croaks $x)
(eat_flies $x)))
(= (croaks Fritz) T)
(= (eat_flies Fritz) T)
(= (green $x) (frog $x))
!(green Fritz)
'''
runner = MeTTa()
result = runner.run(program)
self.assertEqual([[S('T')]], result)
def test_gnd_type_error(self):
program = '''
!(+ 2 "String")
'''
runner = MeTTa()
result = runner.run(program)
self.assertEqual([[E(S('Error'), ValueAtom('String'), S('BadType'))]], result)