File: test_zz_submitted.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 (115 lines) | stat: -rw-r--r-- 3,595 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# test_submitted.py

"""revision $Id: test_zz_submitted.py 348 2008-03-09 01:25:16Z Franz $

TESTS:
COOL rule execution coherence on SYMBOL

"""


class ctc_Submitted(ctestcase):
    """tests submitted by users"""

    def ctf_Submitted01(self):
        """Testing: COOL rule execution coherence on SYMBOL"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            C = e.BuildClass("C", "(is-a USER)(slot a1)")
            c = C.BuildInstance("c")
            c.Slots['a1'] = clips.Symbol("HELLO")
            r = e.BuildRule(
                "r1",
                """(object (is-a C) (a1 ?a1&HELLO))""",
                """(assert (success))"""
                )
            e.Run()
            f = e.InitialFact()
            while f.Next():
                f = f.Next()
            self.assertEqual(f.Relation, clips.Symbol("success"))


    def ctf_Submitted02(self):
        """Testing: COOL rule execution coherence on STRING"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            C = e.BuildClass("C", "(is-a USER)(slot a1)")
            c = C.BuildInstance("c")
            c.Slots['a1'] = clips.String("HELLO")
            r = e.BuildRule(
                "r1",
                """
                    (object (is-a C) (a1 ?a1))
                    (test (eq (str-compare  ?a1 "HELLO") 0))
                """,
                """(assert (success))"""
                )
            e.Run()
            f = e.InitialFact()
            while f.Next():
                f = f.Next()
            self.assertEqual(f.Relation, clips.Symbol("success"))


    def ctf_Submitted03(self):
        """Testing: multiple environment consistency"""
        env1 = clips.Environment()
        env2 = clips.Environment()
        t1 = env1.BuildTemplate("t1", "(slot s1)")
        t2 = env2.BuildTemplate("t2", "(slot s2)")
        f1 = t1.BuildFact()
        f2 = t2.BuildFact()
        f1.Slots["s1"] = "1"
        f2.Slots["s2"] = "2"
        env1.Reset()
        env2.Reset()
        f1.Assert()
        f2.Assert()
        self.assertEqual(f1.Index, f2.Index)
        self.assertEqual(f1.Slots["s1"], clips.String("1"))
        self.assertEqual(f2.Slots["s2"], clips.String("2"))
    
    def ctf_AcceptsForces01(self):
        """Testing: parameter checking and enforcement (Case 1)"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            S1 = unicode("S1")
            S2 = unicode("S2")
            t1 = e.BuildTemplate(
                "t1", """
                (slot S1
                    (type SYMBOL)
                    (default TEST0))
                (slot S2
                    (type SYMBOL)
                    (allowed-values TEST1 TEST2))
                """)
            self.assertEqual(t1.Slots.DefaultValue(S1), clips.Symbol("TEST0"))
            self.assertEqual(t1.Slots.AllowedValues(S2)[0], clips.Symbol("TEST1"))
            self.assertEqual(t1.Slots.AllowedValues(S2)[1], clips.Symbol("TEST2"))

    def ctf_AcceptsForces02(self):
        """Testing: parameter checking and enforcement (Case 2)"""
        for x in self.envdict.keys():
            e = self.envdict[x]
            e.Clear()
            e.Reset()
            S0 = unicode("S0")
            t1 = e.BuildTemplate(
                "t1", "(slot S0)")
            f = t1.BuildFact()
            f.Slots[S0] = 42
            self.assertEqual(f.Slots['S0'], 42)
            
            



# end.