2004-11-28 19:07:24 -05:00
|
|
|
IN: scratchpad
|
|
|
|
USE: hashtables
|
|
|
|
USE: namespaces
|
|
|
|
USE: generic
|
|
|
|
USE: test
|
2004-12-10 19:29:07 -05:00
|
|
|
USE: kernel
|
2004-12-12 16:32:47 -05:00
|
|
|
USE: math
|
|
|
|
USE: words
|
|
|
|
USE: lists
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
TRAITS: test-traits
|
2004-12-11 18:18:43 -05:00
|
|
|
C: test-traits ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
[ t ] [ <test-traits> test-traits? ] unit-test
|
|
|
|
[ f ] [ "hello" test-traits? ] unit-test
|
|
|
|
[ f ] [ <namespace> test-traits? ] unit-test
|
|
|
|
|
|
|
|
GENERIC: foo
|
|
|
|
|
2004-12-11 18:18:43 -05:00
|
|
|
M: test-traits foo drop 12 ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
TRAITS: another-test
|
2004-12-11 18:18:43 -05:00
|
|
|
C: another-test ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
2004-12-11 18:18:43 -05:00
|
|
|
M: another-test foo drop 13 ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
[ 12 ] [ <test-traits> foo ] unit-test
|
|
|
|
[ 13 ] [ <another-test> foo ] unit-test
|
|
|
|
|
|
|
|
TRAITS: quux
|
2004-12-11 18:18:43 -05:00
|
|
|
C: quux ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
2004-12-11 18:18:43 -05:00
|
|
|
M: quux foo "foo" swap hash ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
"Hi"
|
|
|
|
] [
|
|
|
|
<quux> [
|
|
|
|
"Hi" "foo" set
|
|
|
|
] extend foo
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
TRAITS: ctr-test
|
2004-12-11 18:18:43 -05:00
|
|
|
C: ctr-test [ 5 "x" set ] extend ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
5
|
|
|
|
] [
|
|
|
|
<ctr-test> [ "x" get ] bind
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
TRAITS: del1
|
2004-12-11 18:18:43 -05:00
|
|
|
C: del1 ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
GENERIC: super
|
2004-12-11 18:18:43 -05:00
|
|
|
M: del1 super drop 5 ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
TRAITS: del2
|
2004-12-11 18:18:43 -05:00
|
|
|
C: del2 ( delegate -- del2 ) [ delegate set ] extend ;
|
2004-11-28 19:07:24 -05:00
|
|
|
|
|
|
|
[ 5 ] [ <del1> <del2> super ] unit-test
|
2004-12-12 16:32:47 -05:00
|
|
|
|
|
|
|
GENERIC: class-of
|
|
|
|
|
|
|
|
M: fixnum class-of drop "fixnum" ;
|
|
|
|
M: word class-of drop "word" ;
|
|
|
|
M: cons class-of drop "cons" ;
|
|
|
|
|
|
|
|
[ "fixnum" ] [ 5 class-of ] unit-test
|
|
|
|
[ "cons" ] [ [ 1 2 3 ] class-of ] unit-test
|
|
|
|
[ "word" ] [ \ class-of class-of ] unit-test
|
|
|
|
[ 3.4 class-of ] unit-test-fails
|
|
|
|
|
|
|
|
GENERIC: foobar
|
|
|
|
M: object foobar drop "Hello world" ;
|
|
|
|
M: fixnum foobar drop "Goodbye cruel world" ;
|
|
|
|
|
|
|
|
[ "Hello world" ] [ 4 foobar foobar ] unit-test
|
|
|
|
[ "Goodbye cruel world" ] [ 4 foobar ] unit-test
|
2004-12-12 16:54:29 -05:00
|
|
|
|
|
|
|
GENERIC: bool>str
|
|
|
|
M: t bool>str drop "true" ;
|
|
|
|
M: f bool>str drop "false" ;
|
|
|
|
|
|
|
|
: str>bool
|
|
|
|
[
|
|
|
|
[ "true" | t ]
|
|
|
|
[ "false" | f ]
|
|
|
|
] assoc ;
|
|
|
|
|
|
|
|
[ t ] [ t bool>str str>bool ] unit-test
|
|
|
|
[ f ] [ f bool>str str>bool ] unit-test
|
2004-12-12 23:49:44 -05:00
|
|
|
|
|
|
|
PREDICATE: cons nonempty-list list? ;
|
|
|
|
|
|
|
|
GENERIC: funny-length
|
|
|
|
M: cons funny-length drop 0 ;
|
|
|
|
M: nonempty-list funny-length length ;
|
|
|
|
|
|
|
|
[ 0 ] [ [ 1 2 | 3 ] funny-length ] unit-test
|
|
|
|
[ 3 ] [ [ 1 2 3 ] funny-length ] unit-test
|
|
|
|
[ "hello" funny-length ] unit-test-fails
|
2004-12-18 23:18:32 -05:00
|
|
|
|
|
|
|
! Testing method sorting
|
|
|
|
GENERIC: sorting-test
|
|
|
|
M: fixnum sorting-test drop "fixnum" ;
|
|
|
|
M: object sorting-test drop "object" ;
|
|
|
|
[ "fixnum" ] [ 3 sorting-test ] unit-test
|
|
|
|
[ "object" ] [ f sorting-test ] unit-test
|
|
|
|
|
|
|
|
! Testing unions
|
|
|
|
UNION: funnies cons ratio complex ;
|
|
|
|
|
|
|
|
GENERIC: funny
|
|
|
|
M: funnies funny drop 2 ;
|
|
|
|
M: object funny drop 0 ;
|
|
|
|
|
|
|
|
[ 2 ] [ [ { } ] funny ] unit-test
|
|
|
|
[ 0 ] [ { } funny ] unit-test
|
|
|
|
|
|
|
|
PREDICATE: funnies very-funny number? ;
|
|
|
|
|
|
|
|
GENERIC: gooey
|
|
|
|
M: very-funny gooey sq ;
|
|
|
|
|
|
|
|
[ 1/4 ] [ 1/2 gooey ] unit-test
|