Fix unit tests

db4
Slava Pestov 2008-05-15 00:03:21 -05:00
parent 08715844d4
commit 46c76b8b1b
11 changed files with 41 additions and 44 deletions

View File

@ -2,7 +2,7 @@ USING: help.markup help.syntax kernel ;
IN: boxes IN: boxes
HELP: box HELP: box
{ $class-description "A data type holding a single value in the " { $link box-value } " slot. The " { $link box-full? } " slot indicates if the value is set." } ; { $class-description "A data type holding a single value in the " { $snippet "value" } " slot. The " { $snippet "occupied" } " slot indicates if the value is set." } ;
HELP: <box> HELP: <box>
{ $values { "box" box } } { $values { "box" box } }
@ -27,12 +27,11 @@ ARTICLE: "boxes" "Boxes"
{ $subsection box } { $subsection box }
"Creating an empty box:" "Creating an empty box:"
{ $subsection <box> } { $subsection <box> }
"Testing if a box is full:"
{ $subsection box-full? }
"Storing a value and removing a value from a box:" "Storing a value and removing a value from a box:"
{ $subsection >box } { $subsection >box }
{ $subsection box> } { $subsection box> }
"Safely removing a value:" "Safely removing a value:"
{ $subsection ?box } ; { $subsection ?box }
"Testing if a box is full can be done by reading the " { $snippet "occupied" } " slot." ;
ABOUT: "boxes" ABOUT: "boxes"

View File

@ -1,17 +1,17 @@
IN: boxes.tests IN: boxes.tests
USING: boxes namespaces tools.test ; USING: boxes namespaces tools.test accessors ;
[ ] [ <box> "b" set ] unit-test [ ] [ <box> "b" set ] unit-test
[ ] [ 3 "b" get >box ] unit-test [ ] [ 3 "b" get >box ] unit-test
[ t ] [ "b" get box-full? ] unit-test [ t ] [ "b" get occupied>> ] unit-test
[ 4 "b" >box ] must-fail [ 4 "b" >box ] must-fail
[ 3 ] [ "b" get box> ] unit-test [ 3 ] [ "b" get box> ] unit-test
[ f ] [ "b" get box-full? ] unit-test [ f ] [ "b" get occupied>> ] unit-test
[ "b" get box> ] must-fail [ "b" get box> ] must-fail
@ -21,4 +21,4 @@ USING: boxes namespaces tools.test ;
[ 12 t ] [ "b" get ?box ] unit-test [ 12 t ] [ "b" get ?box ] unit-test
[ f ] [ "b" get box-full? ] unit-test [ f ] [ "b" get occupied>> ] unit-test

View File

@ -3,24 +3,24 @@
USING: kernel accessors ; USING: kernel accessors ;
IN: boxes IN: boxes
TUPLE: box value full? ; TUPLE: box value occupied ;
: <box> ( -- box ) box new ; : <box> ( -- box ) box new ;
ERROR: box-full box ; ERROR: box-full box ;
: >box ( value box -- ) : >box ( value box -- )
dup full?>> dup occupied>>
[ box-full ] [ t >>full? (>>value) ] if ; [ box-full ] [ t >>occupied (>>value) ] if ;
ERROR: box-empty box ; ERROR: box-empty box ;
: box> ( box -- value ) : box> ( box -- value )
dup full?>> dup occupied>>
[ [ f ] change-value f >>full? drop ] [ box-empty ] if ; [ [ f ] change-value f >>occupied drop ] [ box-empty ] if ;
: ?box ( box -- value/f ? ) : ?box ( box -- value/f ? )
dup full?>> [ box> t ] [ drop f f ] if ; dup occupied>> [ box> t ] [ drop f f ] if ;
: if-box? ( box quot -- ) : if-box? ( box quot -- )
>r ?box r> [ drop ] if ; inline >r ?box r> [ drop ] if ; inline

View File

@ -101,23 +101,6 @@ SYMBOL: error-counter
[ 1 ] [ error-counter get ] unit-test [ 1 ] [ error-counter get ] unit-test
] with-scope ] with-scope
TUPLE: dispose-error ;
M: dispose-error dispose 3 throw ;
TUPLE: dispose-dummy disposed? ;
M: dispose-dummy dispose t >>disposed? drop ;
T{ dispose-error } "a" set
T{ dispose-dummy } "b" set
[ f ] [ "b" get disposed?>> ] unit-test
[ { "a" "b" } [ get ] map dispose-each ] [ 3 = ] must-fail-with
[ t ] [ "b" get disposed?>> ] unit-test
[ ] [ [ return ] with-return ] unit-test [ ] [ [ return ] with-return ] unit-test
[ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with [ { } [ ] attempt-all ] [ attempt-all-error? ] must-fail-with

View File

@ -1,6 +1,23 @@
USING: destructors kernel tools.test continuations ; USING: destructors kernel tools.test continuations ;
IN: destructors.tests IN: destructors.tests
TUPLE: dispose-error ;
M: dispose-error dispose 3 throw ;
TUPLE: dispose-dummy disposed? ;
M: dispose-dummy dispose t >>disposed? drop ;
T{ dispose-error } "a" set
T{ dispose-dummy } "b" set
[ f ] [ "b" get disposed?>> ] unit-test
[ { "a" "b" } [ get ] map dispose-each ] [ 3 = ] must-fail-with
[ t ] [ "b" get disposed?>> ] unit-test
TUPLE: dummy-obj destroyed? ; TUPLE: dummy-obj destroyed? ;
: <dummy-obj> dummy-obj new ; : <dummy-obj> dummy-obj new ;

View File

@ -5,7 +5,7 @@ sequences strings vectors words quotations effects tools.test
continuations generic.standard sorting assocs definitions continuations generic.standard sorting assocs definitions
prettyprint io inspector classes.tuple classes.union prettyprint io inspector classes.tuple classes.union
classes.predicate debugger threads.private io.streams.string classes.predicate debugger threads.private io.streams.string
io.timeouts io.thread sequences.private ; io.timeouts io.thread sequences.private destructors ;
IN: inference.tests IN: inference.tests
[ ] [ [ 1 ] dataflow [ ] transform-nodes drop ] unit-test [ ] [ [ 1 ] dataflow [ ] transform-nodes drop ] unit-test

View File

@ -13,8 +13,7 @@ concurrency.messaging continuations ;
[ ] [ test-node dup 1array swap (start-node) ] unit-test [ ] [ test-node dup 1array swap (start-node) ] unit-test
[ ] [ yield ] unit-test [ ] [ 100 sleep ] unit-test
[ ] [ yield ] unit-test
[ ] [ [ ] [
[ [

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel threads boxes ; USING: kernel threads boxes accessors ;
IN: concurrency.exchangers IN: concurrency.exchangers
! Motivated by ! Motivated by
@ -12,10 +12,10 @@ TUPLE: exchanger thread object ;
<box> <box> exchanger boa ; <box> <box> exchanger boa ;
: exchange ( obj exchanger -- newobj ) : exchange ( obj exchanger -- newobj )
dup exchanger-thread box-full? [ dup thread>> occupied>> [
dup exchanger-object box> dup object>> box>
>r exchanger-thread box> resume-with r> >r thread>> box> resume-with r>
] [ ] [
[ exchanger-object >box ] keep [ object>> >box ] keep
[ exchanger-thread >box ] curry "exchange" suspend [ thread>> >box ] curry "exchange" suspend
] if ; ] if ;

View File

@ -1,7 +1,7 @@
IN: concurrency.mailboxes.tests IN: concurrency.mailboxes.tests
USING: concurrency.mailboxes concurrency.count-downs vectors USING: concurrency.mailboxes concurrency.count-downs vectors
sequences threads tools.test math kernel strings namespaces sequences threads tools.test math kernel strings namespaces
continuations calendar ; continuations calendar destructors ;
[ V{ 1 2 3 } ] [ [ V{ 1 2 3 } ] [
0 <vector> 0 <vector>

View File

@ -71,7 +71,7 @@ M: mailbox dispose* threads>> notify-all ;
f swap mailbox-get-timeout? ; inline f swap mailbox-get-timeout? ; inline
: wait-for-close-timeout ( mailbox timeout -- ) : wait-for-close-timeout ( mailbox timeout -- )
over closed>> over disposed>>
[ 2drop ] [ 2dup wait-for-mailbox wait-for-close-timeout ] if ; [ 2drop ] [ 2dup wait-for-mailbox wait-for-close-timeout ] if ;
: wait-for-close ( mailbox -- ) : wait-for-close ( mailbox -- )

View File

@ -1,7 +1,6 @@
USING: accessors math kernel namespaces continuations USING: accessors math kernel namespaces continuations
io.files io.monitors io.monitors.recursive io.backend io.files io.monitors io.monitors.recursive io.backend
concurrency.mailboxes concurrency.mailboxes tools.test destructors ;
tools.test ;
IN: io.monitors.recursive.tests IN: io.monitors.recursive.tests
\ pump-thread must-infer \ pump-thread must-infer