File: test_retpass.py

package info (click to toggle)
python-clips 1.0.7.348%2Bclips-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,376 kB
  • ctags: 2,544
  • sloc: ansic: 17,065; python: 5,668; sh: 20; makefile: 12
file content (70 lines) | stat: -rw-r--r-- 2,266 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# test_retpass.py

"""revision: $Id: test_retpass.py 335 2008-01-13 01:50:50Z Franz $
TESTS:
passing Fact objects as arguments
passing Instance objects as arguments
Fact objects as return values
Instance objects as return values
"""

class ctc_RetPass(ctestcase):
    """test Class objects"""

    def ctf_PassFacts_01(self):
        """Testing: Fact objects as arguments"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            g = e.BuildGlobal("g")
            f = e.Assert("(a)")
            g.Value = f
            e.SendCommand("(ppfact ?*g*)")
            self.assertEqual(clips.StdoutStream.Read().strip(), "(a)")

    def ctf_PassInstances_01(self):
        """Testing: Instance objects as arguments"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            g = e.BuildGlobal("g")
            c = e.BuildClass("C", "(is-a USER)", "New Class")
            i = c.BuildInstance("i")
            g.Value = i
            e.SendCommand("(send ?*g* print)")
            self.assertEqual(
                e.Eval("(instance-name ?*g*)"), clips.InstanceName('i'))

    def ctf_RetFacts_01(self):
        """Testing: Fact objects as return values"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            e.SendCommand("(defglobal ?*g* = nil)")
            e.SendCommand("""(defrule r
                                ?f <- (a)
                            =>
                                (bind ?*g* ?f))""")
            e.SendCommand("(deffunction f () (return ?*g*))")
            e.Assert("(a)")
            e.Run()
            f = clips.Eval("(f)")
            self.assertEqual(f.Relation, clips.Symbol('a'))

    def ctf_RetInstances_01(self):
        """Testing: Instance objects as return values"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            e.SendCommand("(defclass C (is-a USER))")
            e.SendCommand("(make-instance [i] of C)")
            i = clips.Eval("(instance-address [i])")
            self.assertEqual(i.Name, clips.InstanceName('i'))



# end.