[ { 2 1 } ] [ [ swons ] infer ] unit-test
[ { 1 2 } ] [ [ uncons ] infer ] unit-test
[ { 1 1 } ] [ [ unit ] infer ] unit-test
-[ { 1 2 } ] [ [ unswons ] infer ] unit-test
[ { 1 1 } ] [ [ list? ] infer ] unit-test
[ { 1 0 } ] [ [ >n ] infer ] unit-test
[ 1 2 ] [ [[ 1 2 ]] uncons ] unit-test
[ 1 [ 2 ] ] [ [ 1 2 ] uncons ] unit-test
-[ 1 2 ] [ [[ 2 1 ]] unswons ] unit-test
-[ [ 2 ] 1 ] [ [ 1 2 ] unswons ] unit-test
-
[ 1 3 ] [ [[ 1 2 ]] [[ 3 4 ]] 2car ] unit-test
[ 2 4 ] [ [[ 1 2 ]] [[ 3 4 ]] 2cdr ] unit-test
-! Factor test suite.
-
+! Copyright (C) 2003, 2006 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
IN: test
-USING: arrays errors hashtables inspector io kernel lists math
+USING: arrays errors hashtables inspector io kernel math
memory namespaces parser prettyprint sequences strings words ;
TUPLE: assert got expect ;
M: assert summary drop "Assertion failed" ;
-: assert= ( a b -- )
- 2dup = [ 2drop ] [ <assert> throw ] if ;
+: assert= ( a b -- ) 2dup = [ 2drop ] [ <assert> throw ] if ;
-: print-test ( input output -- )
- "--> " write 2array . flush ;
+: print-test ( input output -- ) "--> " write 2array . flush ;
: benchmark ( quot -- gctime runtime )
millis >r gc-time >r call gc-time r> - millis r> - ;
[
2dup print-test
swap >r >r clear r> call
- datastack >list r> assert=
+ datastack r> >vector assert=
] keep-datastack 2drop
] time ;
SYMBOL: failures
-: failure failures [ cons ] change ;
+: failure failures get push ;
: test-handler ( name quot -- ? )
- catch [ dup error. cons failure f ] [ t ] if* ;
+ catch [ dup error. 2array failure f ] [ t ] if* ;
: test-path ( name -- path )
"/library/test/" swap ".factor" append3 ;
] assert-depth drop
] test-handler ;
-: prepare-tests ( -- ) failures off "temporary" forget-vocab ;
+: prepare-tests ( -- )
+ V{ } clone failures set "temporary" forget-vocab ;
: passed.
"Tests passed:" print . ;
: failed.
"Tests failed:" print
- failures get [ unswons write ": " write error. ] each ;
+ failures get [ first2 swap write ": " write error. ] each ;
: run-tests ( list -- )
prepare-tests [ test ] subset terpri passed. failed. ;