1 IN: multi-methods.tests
2 USING: multi-methods tools.test math sequences namespaces system
3 kernel strings definitions prettyprint debugger arrays
4 hashtables continuations classes assocs accessors ;
8 [ t ] [ \ first-test generic? ] unit-test
12 SINGLETON: paper INSTANCE: paper thing
13 SINGLETON: scissors INSTANCE: scissors thing
14 SINGLETON: rock INSTANCE: rock thing
18 METHOD: beats? { paper scissors } t ;
19 METHOD: beats? { scissors rock } t ;
20 METHOD: beats? { rock paper } t ;
21 METHOD: beats? { thing thing } f ;
23 : play ( obj1 obj2 -- ? ) beats? 2nip ;
25 [ { } 3 play ] must-fail
26 [ t ] [ error get no-method? ] unit-test
27 [ ] [ error get error. ] unit-test
28 [ { { } 3 } ] [ error get arguments>> ] unit-test
29 [ t ] [ paper scissors play ] unit-test
30 [ f ] [ scissors paper play ] unit-test
32 [ t ] [ { beats? paper scissors } method-spec? ] unit-test
33 [ ] [ { beats? paper scissors } see ] unit-test
39 METHOD: hook-test { array { some-var array } } reverse ;
40 METHOD: hook-test { { some-var array } } class ;
41 METHOD: hook-test { hashtable { some-var number } } assoc-size ;
43 { 1 2 3 } some-var set
44 [ { f t t } ] [ { t t f } hook-test ] unit-test
45 [ fixnum ] [ 3 hook-test ] unit-test
47 [ 0 ] [ H{ } hook-test ] unit-test
50 [ H{ } hook-test ] must-fail
51 [ t ] [ error get no-method? ] unit-test
52 [ { H{ } "error" } ] [ error get arguments>> ] unit-test
57 TUPLE: busted-2 ; INSTANCE: busted-2 busted
62 METHOD: busted-sort { busted-1 busted-2 } ;
63 METHOD: busted-sort { busted-2 busted-3 } ;
64 METHOD: busted-sort { busted busted } ;