1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar combinators.short-circuit
4 constructors eval kernel math strings tools.test ;
7 TUPLE: stock-spread stock spread timestamp ;
9 CONSTRUCTOR: <stock-spread> stock-spread ( stock spread -- stock-spread )
15 AAPL 1234 <stock-spread>
19 [ timestamp>> timestamp? ]
28 CONSTRUCTOR: <ct1> ct1 ( a -- obj ) ;
30 CONSTRUCTOR: <ct2> ct2 ( a b -- obj ) ;
32 CONSTRUCTOR: <ct3> ct3 ( a b c -- obj ) ;
34 CONSTRUCTOR: <ct4> ct4 ( a b c d -- obj ) ;
36 { 1000 } [ 1000 <ct1> a>> ] unit-test
37 { 0 } [ 0 0 <ct2> a>> ] unit-test
38 { 0 } [ 0 0 0 <ct3> a>> ] unit-test
39 { 0 } [ 0 0 0 0 <ct4> a>> ] unit-test
43 { name string read-only } { hp integer } { max-hp integer read-only }
44 { computed integer read-only }
45 lots of extra slots that make me not want to use boa, maybe they get set later
46 { stop initial: 18 } ;
48 TUPLE: a-monster < monster ;
50 TUPLE: b-monster < monster ;
53 SLOT-CONSTRUCTOR: a-monster
56 : <a-monster> ( name hp max-hp -- obj )
58 a-monster( name hp max-hp computed ) ;
60 : <b-monster> ( name hp max-hp -- obj )
62 { "name" "hp" "max-hp" "computed" } \ b-monster slots>boa ;
64 { 20 } [ "Norm" 10 10 <a-monster> computed>> ] unit-test
65 { 18 } [ "Norm" 10 10 <a-monster> stop>> ] unit-test
67 { 22 } [ "Phil" 11 11 <b-monster> computed>> ] unit-test
68 { 18 } [ "Phil" 11 11 <b-monster> stop>> ] unit-test
72 IN: constructors.tests
74 CONSTRUCTOR: <foo> foo ( a a -- obj )" eval( -- )
76 error>> repeated-constructor-parameters?
81 IN: constructors.tests
83 CONSTRUCTOR: <foo> foo ( a c -- obj )" eval( -- )
85 error>> unknown-constructor-parameters?