From 9fce3c6963077bdd8e3f8e904df59c3492d747be Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Mon, 26 Apr 2010 11:54:09 -0600 Subject: [PATCH] Automated tests --- collects/tests/schelog/bible.rkt | 15 +++++++++++++ collects/tests/schelog/holland.rkt | 34 ++++++++++++++++++------------ collects/tests/schelog/houses.rkt | 14 +++++------- collects/tests/schelog/mapcol.rkt | 7 +++--- collects/tests/schelog/run-all.rkt | 7 ++++++ collects/tests/schelog/toys.rkt | 6 +++--- 6 files changed, 53 insertions(+), 30 deletions(-) diff --git a/collects/tests/schelog/bible.rkt b/collects/tests/schelog/bible.rkt index d591defdb1..fd4fe1a076 100644 --- a/collects/tests/schelog/bible.rkt +++ b/collects/tests/schelog/bible.rkt @@ -75,6 +75,9 @@ (%which (kk) (%set-of k (%father 'terach k) kk))))) +(check-equal? (terachs-kids-test-2) + `((kk (abraham nachor haran)))) + ;This is a better definition of the %children predicate. ;Uses set predicate %bag-of @@ -93,6 +96,9 @@ (%father dad x)) kids))))) +(check-equal? (dad-kids-test-2) + `((dad terach) (kids (abraham nachor haran)))) + (define dad-kids-test-3 ;looks like dad-kids-test-2, but dad is now ;existentially quantified. returns a set of @@ -103,6 +109,9 @@ (%set-of x (%father dad x) kids))))) +(check-equal? (dad-kids-test-3) + `((dad _) (kids (abraham nachor haran isaac lot milcah yiscah)))) + (define dad-kids-test-4 ;find the set of dad-kids. ;since dad is existentially quantified, @@ -115,6 +124,9 @@ (%set-of x (%father dad x) kids) dad-kids))))) +(check-equal? (dad-kids-test-4) + `((dad-kids ((_ (abraham nachor haran isaac lot milcah yiscah)))))) + (define dad-kids-test-5 ;the correct solution. dad is ;identified as a free var. @@ -128,3 +140,6 @@ (%father dad x)) kids) dad-kids))))) + +(check-equal? (dad-kids-test-5) + `((dad-kids ((terach (abraham nachor haran)) (abraham (isaac)) (haran (lot milcah yiscah)))))) \ No newline at end of file diff --git a/collects/tests/schelog/holland.rkt b/collects/tests/schelog/holland.rkt index 97049d22e6..79f39fd4b5 100644 --- a/collects/tests/schelog/holland.rkt +++ b/collects/tests/schelog/holland.rkt @@ -1,6 +1,7 @@ #lang racket -(require schelog) +(require schelog + tests/eli-tester) ;This is a very trivial program. In Prolog, it would be: ; @@ -12,29 +13,34 @@ (define %city (lambda (x) (%or (%= x 'amsterdam) - (%= x 'brussels)))) + (%= x 'brussels)))) (define %country (lambda (x) (%or (%= x 'holland) - (%= x 'belgium)))) + (%= x 'belgium)))) ;For a more Prolog-style syntax, you can rewrite the same thing, ;using the `%rel' macro, as the following: -'(define %city +(define %city* (%rel () - (('amsterdam)) - (('brussels)))) + (('amsterdam)) + (('brussels)))) -'(define %country +(define %country* (%rel () - (('holland)) - (('belgium)))) + (('holland)) + (('belgium)))) ;Typical easy queries: -; -; (%which (x) (%city x)) succeeds twice -; (%which (x) (%country x)) succeeds twice -; (%which () (%city 'amsterdam)) succeeds -; (%which () (%country 'amsterdam)) fails +(test + (%which (x) (%city x)) + (%more) + (%more) => #f + (%which (x) (%country x)) + (%more) + (%more) => #f + (%which () (%city 'amsterdam)) + (%more) => #f + (%which () (%country 'amsterdam)) => #f) diff --git a/collects/tests/schelog/houses.rkt b/collects/tests/schelog/houses.rkt index cf91166066..09a0a69c26 100644 --- a/collects/tests/schelog/houses.rkt +++ b/collects/tests/schelog/houses.rkt @@ -140,13 +140,9 @@ (list (list zebra-owner 'owns 'the 'zebra) (list water-drinker 'drinks 'water)))))) -;Load puzzle.scm and type (solve-puzzle %houses) - -;Note: This program, as written, requires -;the occurs check. Make sure the global -;*schelog-use-occurs-check?* is set to #t before -;calling solve-puzzle. If not, you will get into -;an infinite loop. - -;Note 2: Perhaps there is a way to rewrite the +;Note: Perhaps there is a way to rewrite the ;program so that it doesn't rely on the occurs check. + +(require "puzzle.rkt" tests/eli-tester) +(schelog-use-occurs-check? #t) +(test (solve-puzzle %houses)) diff --git a/collects/tests/schelog/mapcol.rkt b/collects/tests/schelog/mapcol.rkt index c328b52871..172f36b623 100644 --- a/collects/tests/schelog/mapcol.rkt +++ b/collects/tests/schelog/mapcol.rkt @@ -79,7 +79,6 @@ (%rel () (('(red yellow blue white))))) -;ask (%which (M) (%test-color 'test M)) or -;ask (%which (M) (%test-color 'western-europe M)) for the -;respective (non-unique) colorings. - +(require tests/eli-tester) +(test (%which (M) (%test-color 'test M)) + (%which (M) (%test-color 'western-europe M))) diff --git a/collects/tests/schelog/run-all.rkt b/collects/tests/schelog/run-all.rkt index cda82cead4..b4a1bce97d 100644 --- a/collects/tests/schelog/run-all.rkt +++ b/collects/tests/schelog/run-all.rkt @@ -1,2 +1,9 @@ #lang racket +(require racket/runtime-path tests/eli-tester) +(define-runtime-path here ".") +(define this-file (build-path "run-all.rkt")) +(test + (for ([p (in-list (directory-list here))] + #:when (not (equal? this-file p))) + (dynamic-require (build-path here p) #f))) \ No newline at end of file diff --git a/collects/tests/schelog/toys.rkt b/collects/tests/schelog/toys.rkt index daa875659f..73033d4b08 100644 --- a/collects/tests/schelog/toys.rkt +++ b/collects/tests/schelog/toys.rkt @@ -30,7 +30,7 @@ ;(%count x n) holds if n is the number of elements in x without ;counting duplicates -'(define %count +(define %count* (%rel (x n y) ((x n) (%remdup x y) (%length y n)))) @@ -54,7 +54,7 @@ ;(%reverse x y) holds if the y is the reversal of x -'(define %reverse +(define %reverse* (%rel (x y z yy) (('() '())) (((cons x y) z) (%reverse y yy) (%append yy (list x) z)))) @@ -71,7 +71,7 @@ ;(%fact n m) holds if m = n! -'(define %fact +(define %fact* (%rel (n n! n-1 n-1!) ((0 1)) ((n n!) (%is n-1 (- n 1)) (%fact n-1 n-1!) (%is n! (* n n-1!)))))