Skip to content

Commit

Permalink
testing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Dec 3, 2024
1 parent 7adcbee commit 352b297
Show file tree
Hide file tree
Showing 70 changed files with 3,269 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ftp.flybase.net/**
venv/
src/canary-*/
.*
*.answers
*.qlf
*.datalog
*-wam.vpw?*
Expand Down
15 changes: 0 additions & 15 deletions tests/direct_comp/00a_lang_compiled_case.metta.answers

This file was deleted.

6 changes: 0 additions & 6 deletions tests/direct_comp/add_atom_match.metta.answers

This file was deleted.

15 changes: 0 additions & 15 deletions tests/direct_comp/compiler_walkthru.metta.answers

This file was deleted.

9 changes: 0 additions & 9 deletions tests/direct_comp/define_if_like.metta.answers

This file was deleted.

1 change: 1 addition & 0 deletions tests/direct_comp/easy/efail.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!(1 (empty) 2)
17 changes: 17 additions & 0 deletions tests/direct_comp/morph/add_atom_match.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

(: sequential (-> Expression %Undefined%))
(= (sequential $1) (superpose $1))

; Used to work
;!(assertEqualToResult
; (sequential
; ( (add-atom &self (man mortal))
; (match &self ($A mortal) (mortal $A))))
; ((mortal man)))

!(sequential
( (add-atom &self (man mortal))
(match &self ($A mortal) (mortal $A))))



9 changes: 9 additions & 0 deletions tests/direct_comp/morph/and_or.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(: If (-> Bool Atom Atom))
(= (If True $then) $then)
(= (If False $then) (let $x 0 (let $x 1 $x)))

(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))


!(If (or (and True False) True) 1 2)
2 changes: 2 additions & 0 deletions tests/direct_comp/morph/collapse.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!(collapse (1 2 3))

17 changes: 17 additions & 0 deletions tests/direct_comp/morph/factorial.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))

(= (facF $n)
(If (== $n 0)
1
(* $n (facF (- $n 1)))))

(= (facf $n)
(if (== $n 0)
1
(* $n (facf (- $n 1)))))


!(facF 10)

!(facf 10)
37 changes: 37 additions & 0 deletions tests/direct_comp/morph/hyperpose.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(: If (-> Bool Atom Atom))
(= (If True $then) $then)
(= (If False $then) (let $x 0 (let $x 1 $x)))

(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))


!(assertEqual (hyperpose (1 2)) (superpose (1 2)))

!(assertEqual (hyperpose (1 (If (== 1 2) 1)))
(superpose (1 (If (== 1 2) 1))))

!(assertEqual (hyperpose ((If (== 1 2) 1) 1))
(superpose ((If (== 1 2) 1) 1)))

!(assertEqual (hyperpose (1 2 3))
(superpose (1 2 3)))

!(assertEqual (hyperpose ((If (== 1 2) 1) 2 3))
(superpose ((If (== 1 2) 1) 2 3)))

!(assertEqual (hyperpose (1 (If (== 1 2) 1) 3))
(superpose (1 (If (== 1 2) 1) 3)))

!(assertEqual (hyperpose (1 2 (If (== 1 2) 1)))
(superpose (1 2 (If (== 1 2) 1))))

!(assertEqual (hyperpose (1 (If (== 1 2) 1) (If (== 1 2) 1)))
(superpose (1 (If (== 1 2) 1) (If (== 1 2) 1))))

!(assertEqual (hyperpose (1 2 3 4))
(superpose (1 2 3 4)))

!(assertEqual (hyperpose ((1 2) (3 4)))
(superpose ((1 2) (3 4))))

4 changes: 4 additions & 0 deletions tests/direct_comp/morph/identity.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(= (f $x) (* $x $x))

!(f 1)

4 changes: 4 additions & 0 deletions tests/direct_comp/morph/if.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))

!(If (> 1 2) (3 4) (5 6))
24 changes: 24 additions & 0 deletions tests/direct_comp/morph/let_superpose_if_case.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(: If (-> Bool Atom Atom))
(= (If True $then) $then)
(= (If False $then) (let $x 0 (let $x 1 $x)))

(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))

(= (f $x) 42)

!(let $y (superpose (3 4 5))
(If (> $y 3)
(case (1 $y)
(((1 3) (f 0))
((1 4) (42 42))
($else (1 1))))))

!(assertEqualToResult
(let $y (superpose (3 4 5))
(If (> $y 3)
(case (1 $y) (((1 3) (f 0))
((1 4) (42 42))
($else (1 1))))))
((42 42) (1 1)))

10 changes: 10 additions & 0 deletions tests/direct_comp/morph/let_superpose_list.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(= (wuza $x)
(let* (($y (* 2 $x))
($z (superpose (4 5))))
($y $z)))

!(wuza 5)

!(assertEqual
(wuza 5)
(superpose ((10 4) (10 5))))
9 changes: 9 additions & 0 deletions tests/direct_comp/morph/let_superpose_list2.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(= (wuzaL $x $L)
(let* (($y (* 2 $x))
($z (superpose $L)))
($y $z)))


!(assertEqual
(wuzaL 2 (3 4))
(superpose ((4 3)(4 4))))
3 changes: 3 additions & 0 deletions tests/direct_comp/morph/letlet.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!(let $T (1.0 0.9)
(let* ((($f1 $c1) $T))
($f1 $c1)))
3 changes: 3 additions & 0 deletions tests/direct_comp/morph/match_feval.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(= (f $x) (* 2 $x))

!(match &self (= (f $x) $y) $y)
19 changes: 19 additions & 0 deletions tests/direct_comp/morph/match_superposed_spaces.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!(bind! &attentional_focus (new-space))
!(add-atom &attentional_focus 1)
!(bind! &concepts (new-space))
!(add-atom &concepts 2)

;; check they are added
!(assertEqualToResult
(match &attentional_focus $1 $1)
(1))

!(assertEqualToResult
(match &concepts $1 $1)
(2))

;; check superposing spaces
!(assertEqualToResult
(match (superpose (&attentional_focus &concepts)) $1 $1)
(1 2))

29 changes: 29 additions & 0 deletions tests/direct_comp/morph/match_void.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
!(bind! &belief_events (new-space))
!(bind! &goal_events (new-space))
!(match &belief_events $1 $1)
!(add-atom &belief_events belief1)
!(match &belief_events $1 $1)
!(case belief1
((%void% 42
)))
!(case (match &belief_events $1 $1)
((%void% 42
)))
!(assertEqualToResult (case (match &belief_events $1 $1)
((belief1 yes) (%void% 42
))) (yes))
!(assertEqualToResult (case (match &goal_events $1 $1)
((%void% 42
))) (42))
!(assertEqualToResult (case (match &goal_events $1 $1)
((goal1 yes)
(%void%
42))) (42))
!(add-atom &goal_events goal1)
!(assertEqualToResult (case (match &goal_events $1 $1)
((goal1 yes) (%void%
42))) (yes))
!(assertEqualToResult (case (match &goal_events $1 $1) ((
%void% 42
))) ())

9 changes: 9 additions & 0 deletions tests/direct_comp/morph/multifunction.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(= (g $x) $x)
(= (g $x) (* 2 $x))
(= (g test ($y $z)) (* (* 1 $y) $z))
(= (g 3 ($y $z)) (* $y $z))
(= (g $x ($y $z)) (* (* $x $y) 42))
(= (g $x ($y $z)) (* (* 42 $x) $y))
(= (g a ($y w)) $y)

!(g 42 (1 2))
4 changes: 4 additions & 0 deletions tests/direct_comp/morph/nested_parameters.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(= (Truth_Deduction ($f1 $c1) ($f2 $c2))
((* $f1 $f2) (* (* $f1 $f2) (* $c1 $c2))))

!(Truth_Deduction (1.0 0.9) (1.0 0.9))
4 changes: 4 additions & 0 deletions tests/direct_comp/morph/peano.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(= (Add $x Z) $x)
(= (Add $x (S $y)) (Add (S $x) $y))

!(Add (S (S Z)) (S (S (S Z))))
26 changes: 26 additions & 0 deletions tests/direct_comp/morph/sequential_nested.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(: sequential (-> Expression %Undefined%))
(= (sequential $1) (superpose $1))

(: do (-> Expression %Undefined%))
(= (do $1) (case $1 ()))



!(bind! &var (new-state 1))
(= (increment)
(superpose ((do (change-state! &var (+ 1 (get-state &var))))
(get-state &var))))

!(sequential ((increment) (increment)))
!(sequential ((increment) (increment) (increment)))
!(sequential ((sequential ((increment) (increment) (increment)))))
!(sequential ((sequential ((increment) (increment) (increment))) (sequential ((increment) (increment) (increment)))))
!(sequential ((sequential ((increment) (increment) (increment))) (increment) (increment) (increment)))
!(do (sequential ((sequential ((increment) (increment) (increment))) (increment) (increment) (increment))))
!(get-state &var)
!(sequential ((increment)))
!(increment)
!(get-state &var)
!(sequential ((change-state! &var (+ 1 (get-state &var)))))
!(get-state &var)

12 changes: 12 additions & 0 deletions tests/direct_comp/morph/states_spaces.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!(bind! &FIFO (new-state 42))
!(bind! &WU (new-space))
!(change-state! &FIFO 45)
!(get-state &FIFO)
!(add-atom &WU a)
!(match &WU $1 $1)
!(add-atom &WU b)
!(remove-atom &WU a)

!(assertEqual
(match &WU $1 $1)
(get-atoms &WU))
38 changes: 38 additions & 0 deletions tests/direct_comp/morph/supercollapse.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@


(: If (-> Bool Atom Atom Atom))
(= (If $cond $then $else) (if $cond $then $else))

; (: TupleConcat (-> Any Any AnyRet))

(= (TupleConcat $Ev1 $Ev2)
(let ($V1 $V2) ($Ev1 $Ev2)
(collapse (superpose ((superpose $V1) (superpose $V2))))))

!(TupleConcat (a b c) (e f g))
!(TupleConcat () (e f g))
!(TupleConcat (a b c) ())

(= (range $K $N)
(If (< $K $N)
(TupleConcat ($K) (range (+ $K 1) $N))
()))

!(TupleConcat (a b c) (range 1 1))

(unused
(pragma! trace-on-exec False)
(pragma! trace-on-eval False)
(pragma! trace-length 1090)
(pragma! stack-max 100))


!(range 1 1)

!(range 1 3)

!(range 2 6)

!(range 1 10)


4 changes: 4 additions & 0 deletions tests/direct_comp/morph/superpose_nested.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!(superpose (a b c))
!(superpose ((superpose (a b c))))
!(superpose ((superpose (a b c)) (superpose (x y z))))
!(superpose ((superpose (a b c)) x y z ))
4 changes: 4 additions & 0 deletions tests/direct_comp/morph/types.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(: f (-> Number Number))
(= (f $x) $x)

!(f 42)
15 changes: 15 additions & 0 deletions tests/direct_comp/morph/types2.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(: Cat Atom)
(: Lion Cat)

(: reproduce (-> Lion Lion Lion))
(= (reproduce $x $y) childlion)

(: lion1 Lion)
(: lion2 Lion)
!(get-type lion1)

!(reproduce lion1 lion2)

!(get-type Lion)
!(match &self (: Lion $1) $1)
!(match &self (: reproduce $1) $1)
Loading

0 comments on commit 352b297

Please sign in to comment.