Skip to content

Commit

Permalink
New tests
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Mar 4, 2013
1 parent 0a75b95 commit e147646
Show file tree
Hide file tree
Showing 370 changed files with 8,766 additions and 8 deletions.
4 changes: 2 additions & 2 deletions trunk/Creshendo/Functions/DeffunctionFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ public virtual String toPPString(IParameter[] params_Renamed, int indents)

public void setParameters(IParameter[] parameters1)
{
throw new NotImplementedException();
parameters = parameters1;
}

public void setFunction(IList infunc)
{
throw new NotImplementedException();
functions = infunc;
}
}
}
2 changes: 2 additions & 0 deletions trunk/Creshendo/Util/Rete/LinkedActivationList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/
using System;
using Creshendo.Util.Rete.Strategies;

namespace Creshendo.Util.Rete
{
Expand All @@ -37,6 +38,7 @@ public class LinkedActivationList : AbstractActivationList

public LinkedActivationList()
{
stratey = new DepthStrategy();
}

public override bool AscendingOrder
Expand Down
9 changes: 9 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/JessTemplate/test.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

(deffunction test-something ()
)


(printout t "Testing *** :" crlf)
(test-something)
(printout t "Test done." crlf)
(exit)
2 changes: 2 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/JessTemplate/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Testing *** :
Test done.
2 changes: 2 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/JessTemplate/test.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Testing *** :
Test done.
Empty file.
29 changes: 29 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/agenda/test.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(defmodule module-1)
(defmodule module-2)

(defrule module-1::rule-1 => )
(defrule module-1::rule-2 => )
(defrule module-2::rule-3 => )
(defrule module-2::rule-4 => )

(deffunction test-something ()
(reset)
(printout t "Explicit module 1" crlf)
(agenda module-1)
(rules module-1)
(printout t "Explicit module 2" crlf)
(agenda module-2)
(rules module-2)
(printout t "No qualifier -- should be module-2" crlf)
(agenda)
(rules)
(printout t "Agenda *" crlf)
(agenda *)
(rules *)
)


(printout t "Testing agenda command :" crlf)
(test-something)
(printout t "Test done." crlf)
(exit)
Empty file.
8 changes: 8 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/agenda/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
truetrueEncountered "(" at line 11, column 3.
Was expecting:
")" ...

AlphaNode count 2
total AlphaMemories = 0
BetaNode Count 0
total BetaMemories = 0
37 changes: 37 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/agenda/test.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Testing agenda command :
Explicit module 1
[Activation: module-1::rule-1 f-0 ; time=1 ; salience=0]
[Activation: module-1::rule-2 f-0 ; time=1 ; salience=0]
For a total of 2 activations.
module-1::rule-1
module-1::rule-2
For a total of 2 rules.
Explicit module 2
[Activation: module-2::rule-3 f-0 ; time=1 ; salience=0]
[Activation: module-2::rule-4 f-0 ; time=1 ; salience=0]
For a total of 2 activations.
module-2::rule-4
module-2::rule-3
For a total of 2 rules.
No qualifier -- should be module-2
[Activation: module-2::rule-3 f-0 ; time=1 ; salience=0]
[Activation: module-2::rule-4 f-0 ; time=1 ; salience=0]
For a total of 2 activations.
module-2::rule-4
module-2::rule-3
For a total of 2 rules.
Agenda *
MAIN:
module-1:
[Activation: module-1::rule-1 f-0 ; time=1 ; salience=0]
[Activation: module-1::rule-2 f-0 ; time=1 ; salience=0]
module-2:
[Activation: module-2::rule-3 f-0 ; time=1 ; salience=0]
[Activation: module-2::rule-4 f-0 ; time=1 ; salience=0]
For a total of 4 activations.
module-1::rule-1
module-2::rule-4
module-2::rule-3
module-1::rule-2
For a total of 4 rules.
Test done.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/agenda/test2.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(defrule MAIN::rule-1 => )
(defrule MAIN::rule-2 => )
(defrule MAIN::rule-3 => )
(defrule MAIN::rule-4 => )


(printout t "Make sure single stepping works" crlf)
(reset)
(printout t "1: " (run 1) crlf)
(printout t "2: " (run 2) crlf)
(printout t "1: " (run 1) crlf)

(printout t "0: " (run 1) crlf)

(printout t "Test done." crlf)
2 changes: 2 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/agenda/test2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make sure single stepping works
1:
6 changes: 6 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/agenda/test2.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Make sure single stepping works
1: 1
2: 2
1: 1
0: 0
Test done.
15 changes: 15 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/autofocus/test.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(printout t "Testing auto-focus :" crlf)

(defmodule DETECTION)

(defrule DETECTION::example
(declare (auto-focus TRUE))
=>
(printout t "Fire!" crlf))

(watch focus)
(reset)
(run)

(printout t "Test done." crlf)
(exit)
9 changes: 9 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/autofocus/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Testing auto-focus :
==> Focus MAIN
<== Focus MAIN
==> Focus DETECTION
Fire!
<== Focus DETECTION
==> Focus MAIN
<== Focus MAIN
Test done.
9 changes: 9 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/autofocus/test.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Testing auto-focus :
==> Focus MAIN
<== Focus MAIN
==> Focus DETECTION
Fire!
<== Focus DETECTION
==> Focus MAIN
<== Focus MAIN
Test done.
Empty file.
18 changes: 18 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain-not/test.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(deftemplate pattern (slot slot))

(do-backward-chaining pattern)

(defrule rule-1
(not (pattern (slot 1)))
=>)

(deffunction test-something ()
(reset)
(facts)
)


(printout t "Testing that negated patterns shouldn't trigger backward chaining :" crlf)
(test-something)
(printout t "Test done." crlf)
(exit)
4 changes: 4 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain-not/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Testing that negated patterns shouldn't trigger backward chaining :
f-0 (MAIN::initial-fact)
For a total of 1 facts.
Test done.
4 changes: 4 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain-not/test.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Testing that negated patterns shouldn't trigger backward chaining :
f-0 (MAIN::initial-fact)
For a total of 1 facts.
Test done.
Empty file.
47 changes: 47 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain-query/test.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(deftemplate factorial (slot in) (slot out))

(do-backward-chaining factorial)

(deffacts one-value (factorial (in 5) (out 120)))

(defquery get-factorial-1
(declare (variables ?x))
(factorial (in ?x) (out ?y)))

(defquery get-factorial-2
(declare (variables ?x)
(max-background-rules 10))
(factorial (in ?x) (out ?y)))

(defrule do-factorial
(need-factorial (in ?x))
=>
(printout t "( Calculating the factorial of " ?x "... )" crlf)
(bind ?r 1)
(bind ?n ?x)
(while (> ?n 1)
(bind ?r (* ?r ?n))
(bind ?n (- ?n 1)))
(assert (factorial (in ?x) (out ?r))))

(printout t "Testing backwards chaining in during defqueries:" crlf)

(deffacts facts (factorial (in 5) (out 120)))
(reset)

(printout t "#1, in WM " (count-query-results get-factorial-1 5) crlf)
(printout t "#1, not in WM " (count-query-results get-factorial-1 10) crlf)

(reset)

(printout t "#2, in WM " (count-query-results get-factorial-2 5) crlf)
(printout t "#2, not in WM " (count-query-results get-factorial-2 10) crlf)









6 changes: 6 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain-query/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Testing backwards chaining in during defqueries:
#1, in WM 1
#1, not in WM 0
#2, in WM 1
( Calculating the factorial of 10... )
#2, not in WM 1
6 changes: 6 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain-query/test.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Testing backwards chaining in during defqueries:
#1, in WM 1
#1, not in WM 0
#2, in WM 1
( Calculating the factorial of 10... )
#2, not in WM 1
Empty file.
48 changes: 48 additions & 0 deletions trunk/Test.Creshendo/ClpFiles/backchain/foo.clp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
(do-backward-chaining factorial)

(defrule print-factorial-10
(factorial 10 ?r1)
=>
(printout t "The factorial of 10 is " ?r1 crlf))

(defrule print-factorial-10-and-12
(factorial 12 ?r1)
(factorial 10 ?r2)
=>
(printout t "The factorial of 12 is " ?r1
", and of 10 is " ?r2 crlf))

(defrule print-factorial-5-10-and-12
"Shows how chaining won't be done if fact already exists"
(factorial 5 ?r0)
(factorial 12 ?r1)
(factorial 10 ?r2)
=>
(printout t "The factorial of 12 is " ?r1
", and of 10 is " ?r2 ", and of 5 is " ?r0 crlf))

(defrule print-factorial-1000
"Shows how explicit modifer can be used to prevent backwards chaining."
?a <- (explicit (factorial 1000 ?r1))
=>
(printout t "The factorial of 1000 is " ?r1 crlf))


(defrule do-factorial
(need-factorial ?x ?)
=>
(printout t "( Calculating the factorial of " ?x "... )" crlf)
(bind ?r 1)
(bind ?n ?x)
(while (> ?n 1)
(bind ?r (* ?r ?n))
(bind ?n (- ?n 1)))
(assert (factorial ?x ?r)))

(printout t "Testing backwards chaining in ordered facts:" crlf)
(reset)
(assert (factorial 5 120))

(run)
(printout t "Test part 2 done." crlf)

Loading

0 comments on commit e147646

Please sign in to comment.