more tests. signatures are doing more.

This commit is contained in:
Danny Yoo 2011-10-03 17:09:05 -04:00
parent 27ea253b35
commit 8629e8c2ab
4 changed files with 34 additions and 2 deletions

View File

@ -24,6 +24,7 @@
var isNatural = baselib.numbers.isNatural;
var isPair = baselib.lists.isPair;
var isList = baselib.lists.isList;
var isVector = baselib.vectors.isVector;
var isString = baselib.strings.isString;
var isSymbol = baselib.symbols.isSymbol;
var isBox = baselib.boxes.isBox;
@ -658,6 +659,14 @@
});
installPrimitiveProcedure(
'vector?',
1,
function (M) {
var firstArg = M.e[M.e.length-1];
return isVector(firstArg);
});
installPrimitiveProcedure(
'vector',
baselib.arity.makeArityAtLeast(0),

View File

@ -0,0 +1,2 @@
Running tests...
All 37 tests passed!

View File

@ -50,6 +50,7 @@
(define: c1 : Char$ #\c)
(check-expect c1 #\c)
#;(define: key1 : Key$ "up")
#;(check-expect key1 "up")
@ -68,7 +69,10 @@
(check-expect ((swf-f a-swf) 10) 11)
#;(check-error (set-swf-f! a-swf 3))
#;(check-violation-highlights
(set-swf-f! a-swf 3)
;; What should be highlighted is the entire signature
(list "(Number$ -> Number$)")
(list 26))
@ -98,6 +102,8 @@
(define mt$ (Sig: mt?))
(define-struct: nd ([v : Number$] [l : Tree$] [r : Tree$]))
#;(check-error (set-nd-v! (make-nd 0 (make-mt) (make-mt)) "x"))
#;(check-violation-highlights
(set-nd-v! (make-nd 0 (make-mt) (make-mt)) "x")
@ -132,6 +138,7 @@
(list 12))
(define: (tree-sum (t : Tree$)) -> Number$
(cond
[(mt? t) 0]
@ -151,6 +158,7 @@
(list 14))
(define: (prime? [n : (Sig: (lambda (n) (and (positive? n) (integer? n))))])
-> Boolean$
(local ([define (check k)
@ -173,6 +181,8 @@
(list "(Sig: (lambda (n) (and (positive? n) (integer? n))))")
(list 22))
(define BadSig$ (or: (Number$ -> Number$) Number$))
;(define: bs : BadSig 3)
;(define BadSig2 (not: (Number$ -> Number$)))
@ -212,6 +222,8 @@
(list "Number$")
(list 27))
(define: (i [f : (Number$ -> Number$)]) -> Number$
(f 5))
(check-expect (i add1) 6)
@ -265,6 +277,8 @@
(list "String$")
(list 22))
(check-expect (local ([define: (f [x : Number$]) -> String$
(number->string x)])
(f 10))
@ -302,10 +316,13 @@
(list 47))
(define: l : (Listof: Number$) (list 1 2 3))
(check-expect l (list 1 2 3))
; (define: m : (Listof: Number$) (list 1 2 "X"))
(define: (n [l : (Listof: (Number$ -> Number$))]) -> (Listof: Number$)
(map (lambda (f) (f 10)) l))
(check-expect (n (list add1 sub1)) (list 11 9))
@ -316,10 +333,13 @@
(list 38))
#;(check-error (n (list add1 string->number)))
(define: vs : (Vectorof: String$)
(vector "0" "1" "2"))
(check-expect vs (vector "0" "1" "2"))
(define: (cvts [ns : (Listof: Number$)]) -> (Listof: String$)
(local [(define: cv : (Vectorof: ((Listof: String$) -> (Listof: String$)))
(vector (lambda (cs) (cons "0" cs))
@ -343,4 +363,4 @@
(local [(define: v : S 4)]
v)
(list "2")
(list 15))
(list 15))

View File

@ -36,4 +36,5 @@
(test "more-tests/booleans-cs019.rkt")
(test "more-tests/checking-cs019.rkt")
(test "more-tests/sharing-cs019.rkt")
(test "more-tests/basics-cs019.rkt")
(test "more-tests/basics-cs019.rkt")
(test "more-tests/sigs-cs019.rkt")