Automated tests
This commit is contained in:
parent
3cf1dc3440
commit
9fce3c6963
|
@ -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))))))
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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)))
|
|
@ -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!)))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user