Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the signature True #227

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion htdp-lib/lang/private/teach.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3238,7 +3238,7 @@

(define Boolean (signature/arbitrary arbitrary-boolean Boolean (predicate boolean?)))

(define True (signature True (enum #f)))
(define True (signature True (enum #t)))
(define False (signature False (enum #f)))

(define String (signature/arbitrary arbitrary-printable-ascii-string String (predicate string?)))
Expand Down
34 changes: 33 additions & 1 deletion htdp-test/tests/htdp-lang/signatures.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
(only-in lang/private/teach
beginner-define-struct advanced-define-struct
signature
Integer Boolean)
Integer Natural Boolean True False
String Char Symbol
[EmptyList htdp:EmptyList]
ConsOf)
deinprogramm/signature/signature)

(define-syntax say-no
Expand Down Expand Up @@ -38,6 +41,35 @@
(lambda ()
?body ...))))))

(check-equal? (say-no (apply-signature False #t)) 'no)
(check-equal? (apply-signature False #f) #f)

(check-equal? (say-no (apply-signature True #f)) 'no)
(check-equal? (apply-signature True #t) #t)

(check-equal? (say-no (apply-signature Integer 1/2)) 'no)
(check-pred (λ (v) (= v 20241017))
(apply-signature Integer 20241017))

(check-equal? (say-no (apply-signature Natural -1)) 'no)
(check-pred zero? (apply-signature Natural 0))

(check-equal? (say-no (apply-signature htdp:EmptyList #t)) 'no)
(check-equal? (apply-signature htdp:EmptyList null) null)

(check-equal? (say-no (apply-signature (ConsOf False Natural) (cons #t 5))) 'no)
(check-equal? (say-no (apply-signature (ConsOf False Natural) (cons #f -1))) 'no)
(check-equal? (apply-signature (ConsOf False Natural) (cons #f 5)) (cons #f 5))

(check-equal? (say-no (apply-signature String #\h)) 'no)
(check-equal? (apply-signature String "hello") "hello")

(check-equal? (say-no (apply-signature Char "h")) 'no)
(check-equal? (apply-signature Char #\h) #\h)

(check-equal? (say-no (apply-signature Symbol 0)) 'no)
(check-equal? (apply-signature Symbol 'yes) 'yes)

; Need to test both beginner and advanced
(advanced-define-struct dillo (alive? weight))
(advanced-define-struct parrot (sentence weight))
Expand Down
Loading