Skip to content

Commit

Permalink
Merge pull request #118 from jazzbox35/main
Browse files Browse the repository at this point in the history
Changes and updates to sanity tests
  • Loading branch information
TeamSPoon authored Sep 8, 2024
2 parents acc025c + 76ef288 commit 8a3840e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
18 changes: 18 additions & 0 deletions tests/baseline_compat/hyperon-mettalog_sanity/flip_test.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(: recur-until-flip-true (-> Number Bool))
(= (recur-until-flip-true $n)
(if (> $n 40) ; set constant here for max
False
(if (flip)
True
(recur-until-flip-true (+ 1 $n)))))

(: recur-until-flip-false (-> Number Bool))
(= (recur-until-flip-false $n)
(if (> $n 40) ; set constant here for max
False
(if (flip)
(recur-until-flip-false (+ 1 $n))
True)))

!(assertEqualToResult (recur-until-flip-true 1) (True))
!(assertEqualToResult (recur-until-flip-false 1) (True))
26 changes: 26 additions & 0 deletions tests/baseline_compat/hyperon-mettalog_sanity/or_test.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
!(bind! &evaluated (new-state False))
(: set-evaluated (-> Bool)) ; this must return boolean
(= (set-evaluated)
((change-state! &evaluated True) True))
!(or True (set-evaluated))
!(assertEqual (get-state &evaluated) False)

;; Basic or Logic
!(assertEqual (or True False) True)
!(assertEqual (or False True) True)
!(assertEqual (or True True) True)
!(assertEqual (or False False) False)

;; or with Expressions
!(assertEqual (or (> 5 3) (< 2 1)) True)
!(assertEqual (or (== 1 1) (== 2 2)) True)
!(assertEqual (or (not True) (and True False)) False)

(: mprogn (-> Atom Atom Atom ))
(= (mprogn $code1 $code2) (let $_ (eval $code1) (eval $code2)))

;; or with Side Effects to Ensure Both Expressions Are Evaluated
!(assertEqual (or (mprogn (println! "First") True) (mprogn (println! "Second") False)) True)
!(assertEqual (or (mprogn (println! "First") True) (mprogn (println! "Second") True)) True)
!(assertEqual (or (mprogn (println! "First") False) (mprogn (println! "Second") True)) True)
!(assertEqual (or (mprogn (println! "First") False) (mprogn (println! "Second") False)) False)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

!(assertEqualToResult (sealed ($x $y) (quote (= ($y $z)))) ((quote (= ($y $z)))))

; !(assertEqualToResult (let $x (input $x) (output $x)) (output (input $x)))
!(assertEqualToResult (let $x (input $y) (output $x)) ((output (input $y))))

; !(assertEqualToResult (let (quote ($sv $st)) (sealed ($x) (quote ($x (output $x)))) (let $sv (input $x) $st)) (output (input $x)))
!(assertEqual (let (quote ($sv $st)) (sealed ($x) (quote ($x (output $x))))
(let $sv (input $x) $st)) (output (input $x)))

(: callsealer (-> Number Number Expression))

(= (callsealer $a $b) (sealed () (quote ((* (+ 40 $a) (/ 100 $b))))))

!(assertEqualToResult (callsealer $x $y) ((quote ((* (+ 40 $x) (/ 100 $y)))))) ; no sealing
Expand Down

0 comments on commit 8a3840e

Please sign in to comment.