Automated tests

This commit is contained in:
Jay McCarthy 2010-04-26 11:54:09 -06:00
parent 3cf1dc3440
commit 9fce3c6963
6 changed files with 53 additions and 30 deletions

View File

@ -75,6 +75,9 @@
(%which (kk) (%which (kk)
(%set-of k (%father 'terach k) 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. ;This is a better definition of the %children predicate.
;Uses set predicate %bag-of ;Uses set predicate %bag-of
@ -93,6 +96,9 @@
(%father dad x)) (%father dad x))
kids))))) kids)))))
(check-equal? (dad-kids-test-2)
`((dad terach) (kids (abraham nachor haran))))
(define dad-kids-test-3 (define dad-kids-test-3
;looks like dad-kids-test-2, but dad is now ;looks like dad-kids-test-2, but dad is now
;existentially quantified. returns a set of ;existentially quantified. returns a set of
@ -103,6 +109,9 @@
(%set-of x (%father dad x) (%set-of x (%father dad x)
kids))))) kids)))))
(check-equal? (dad-kids-test-3)
`((dad _) (kids (abraham nachor haran isaac lot milcah yiscah))))
(define dad-kids-test-4 (define dad-kids-test-4
;find the set of dad-kids. ;find the set of dad-kids.
;since dad is existentially quantified, ;since dad is existentially quantified,
@ -115,6 +124,9 @@
(%set-of x (%father dad x) kids) (%set-of x (%father dad x) kids)
dad-kids))))) dad-kids)))))
(check-equal? (dad-kids-test-4)
`((dad-kids ((_ (abraham nachor haran isaac lot milcah yiscah))))))
(define dad-kids-test-5 (define dad-kids-test-5
;the correct solution. dad is ;the correct solution. dad is
;identified as a free var. ;identified as a free var.
@ -128,3 +140,6 @@
(%father dad x)) (%father dad x))
kids) kids)
dad-kids))))) dad-kids)))))
(check-equal? (dad-kids-test-5)
`((dad-kids ((terach (abraham nachor haran)) (abraham (isaac)) (haran (lot milcah yiscah))))))

View File

@ -1,6 +1,7 @@
#lang racket #lang racket
(require schelog) (require schelog
tests/eli-tester)
;This is a very trivial program. In Prolog, it would be: ;This is a very trivial program. In Prolog, it would be:
; ;
@ -22,19 +23,24 @@
;For a more Prolog-style syntax, you can rewrite the same thing, ;For a more Prolog-style syntax, you can rewrite the same thing,
;using the `%rel' macro, as the following: ;using the `%rel' macro, as the following:
'(define %city (define %city*
(%rel () (%rel ()
(('amsterdam)) (('amsterdam))
(('brussels)))) (('brussels))))
'(define %country (define %country*
(%rel () (%rel ()
(('holland)) (('holland))
(('belgium)))) (('belgium))))
;Typical easy queries: ;Typical easy queries:
; (test
; (%which (x) (%city x)) succeeds twice (%which (x) (%city x))
; (%which (x) (%country x)) succeeds twice (%more)
; (%which () (%city 'amsterdam)) succeeds (%more) => #f
; (%which () (%country 'amsterdam)) fails (%which (x) (%country x))
(%more)
(%more) => #f
(%which () (%city 'amsterdam))
(%more) => #f
(%which () (%country 'amsterdam)) => #f)

View File

@ -140,13 +140,9 @@
(list (list zebra-owner 'owns 'the 'zebra) (list (list zebra-owner 'owns 'the 'zebra)
(list water-drinker 'drinks 'water)))))) (list water-drinker 'drinks 'water))))))
;Load puzzle.scm and type (solve-puzzle %houses) ;Note: Perhaps there is a way to rewrite the
;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
;program so that it doesn't rely on the occurs check. ;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))

View File

@ -79,7 +79,6 @@
(%rel () (%rel ()
(('(red yellow blue white))))) (('(red yellow blue white)))))
;ask (%which (M) (%test-color 'test M)) or (require tests/eli-tester)
;ask (%which (M) (%test-color 'western-europe M)) for the (test (%which (M) (%test-color 'test M))
;respective (non-unique) colorings. (%which (M) (%test-color 'western-europe M)))

View File

@ -1,2 +1,9 @@
#lang racket #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)))

View File

@ -30,7 +30,7 @@
;(%count x n) holds if n is the number of elements in x without ;(%count x n) holds if n is the number of elements in x without
;counting duplicates ;counting duplicates
'(define %count (define %count*
(%rel (x n y) (%rel (x n y)
((x n) (%remdup x y) (%length y n)))) ((x n) (%remdup x y) (%length y n))))
@ -54,7 +54,7 @@
;(%reverse x y) holds if the y is the reversal of x ;(%reverse x y) holds if the y is the reversal of x
'(define %reverse (define %reverse*
(%rel (x y z yy) (%rel (x y z yy)
(('() '())) (('() '()))
(((cons x y) z) (%reverse y yy) (%append yy (list x) z)))) (((cons x y) z) (%reverse y yy) (%append yy (list x) z))))
@ -71,7 +71,7 @@
;(%fact n m) holds if m = n! ;(%fact n m) holds if m = n!
'(define %fact (define %fact*
(%rel (n n! n-1 n-1!) (%rel (n n! n-1 n-1!)
((0 1)) ((0 1))
((n n!) (%is n-1 (- n 1)) (%fact n-1 n-1!) (%is n! (* n n-1!))))) ((n n!) (%is n-1 (- n 1)) (%fact n-1 n-1!) (%is n! (* n n-1!)))))