Skip to content

Commit

Permalink
more tests. signatures are doing more.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Yoo committed Oct 3, 2011
1 parent 27ea253 commit 8629e8c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
9 changes: 9 additions & 0 deletions js-assembler/runtime-src/baselib-primitives.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions tests/more-tests/sigs-cs019.expected
@@ -0,0 +1,2 @@
Running tests...
All 37 tests passed!
22 changes: 21 additions & 1 deletion tests/more-tests/sigs-cs019.rkt
Expand Up @@ -50,6 +50,7 @@
(define: c1 : Char$ #\c)
(check-expect c1 #\c)


#;(define: key1 : Key$ "up")
#;(check-expect key1 "up")

Expand All @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -132,6 +138,7 @@
(list 12))



(define: (tree-sum (t : Tree$)) -> Number$
(cond
[(mt? t) 0]
Expand All @@ -151,6 +158,7 @@
(list 14))



(define: (prime? [n : (Sig: (lambda (n) (and (positive? n) (integer? n))))])
-> Boolean$
(local ([define (check k)
Expand All @@ -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$)))
Expand Down Expand Up @@ -212,6 +222,8 @@
(list "Number$")
(list 27))



(define: (i [f : (Number$ -> Number$)]) -> Number$
(f 5))
(check-expect (i add1) 6)
Expand Down Expand Up @@ -265,6 +277,8 @@
(list "String$")
(list 22))



(check-expect (local ([define: (f [x : Number$]) -> String$
(number->string x)])
(f 10))
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -343,4 +363,4 @@
(local [(define: v : S 4)]
v)
(list "2")
(list 15))
(list 15))
3 changes: 2 additions & 1 deletion tests/run-more-tests.rkt
Expand Up @@ -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")

0 comments on commit 8629e8c

Please sign in to comment.