e9bd0632eadd

Add problem 14 from 99PP as a test
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 20 Aug 2016 21:15:52 +0000
parents ab7de6629c42
children cb324d188513
branches/tags (none)
files test/99.lisp

Changes

--- a/test/99.lisp	Sun Jul 24 12:44:54 2016 +0000
+++ b/test/99.lisp	Sat Aug 20 21:15:52 2016 +0000
@@ -178,6 +178,8 @@
                  (list ?))
        (?what (f cats dogs))))))
 
+
+
 ; (define-test p9
 ;   (with-fresh-database
 ;     (%=)
@@ -207,3 +209,22 @@
 ;        (?what ((a a a))))
 ;       ((pack (list a a b a) ?what)
 ;        (?what ((a a) (b) (a)))))))
+
+
+(define-test p14
+  ;; Duplicate the elements of a list.
+  (with-fresh-database
+    (push-logic-frame-with
+      (fact (duplicate nil nil))
+      (rule (duplicate (list* ?x ?rest) (list* ?x ?x ?rest-dup))
+        (duplicate ?rest ?rest-dup)))
+
+    (should-return
+      ((duplicate nil nil)
+       empty)
+      ((duplicate (list 1) (list 1 1))
+       empty)
+      ((duplicate (list a b c d) (list a a b b c c d d))
+       empty)
+      ((duplicate ?what (list ?x 2 3 ?y))
+       (?what (2 3) ?x 2 ?y 3)))))