diff options
Diffstat (limited to 'stdlib/test')
-rw-r--r-- | stdlib/test/test/lux/paradigm/object.lux | 109 | ||||
-rw-r--r-- | stdlib/test/tests.lux | 2 |
2 files changed, 73 insertions, 38 deletions
diff --git a/stdlib/test/test/lux/paradigm/object.lux b/stdlib/test/test/lux/paradigm/object.lux index 0171ab41f..7998d0000 100644 --- a/stdlib/test/test/lux/paradigm/object.lux +++ b/stdlib/test/test/lux/paradigm/object.lux @@ -3,46 +3,81 @@ (lux (data (coll [list])) (paradigm object))) -(interface: (Queue a) - (push [a] @) - (peek [] (Maybe a)) - (pop [] @) +## No parameters +(interface: Counter + (inc [] @) + (read [] Nat)) + +(class: NatC Counter + Nat + + (def: inc + (update@Counter n.inc)) + + (def: read + get@Counter)) + +(interface: Resettable-Counter + #extends Counter + (reset [] @)) + +(class: NatRC Resettable-Counter + #inherits NatC + Unit + + (def: reset + (set@Counter +0))) + +## With parameters +(interface: (Collection a) + (add [a] @) (size [] Nat)) -(class: (List-Queue a) (Queue a) +(class: (ListC a) (Collection a) (List a) - - (def: (push a) - (update! (|>. (#;Cons a)))) - (def: peek - (|>. get! list;head)) + (def: (add elem) + (update@Collection (|>. (#;Cons elem)))) - (def: pop - (update! (function [state] (|> state list;tail (default state))))) - (def: size - (|>. get! list;size))) - -(type: Coord [Real Real]) -(type: Angle Real) - -(interface: Geometry - (translate [Coord] @) - (rotate [Coord Angle] @) - (scale [Real Real] @)) - -(class: Point Geometry - {#label Text - #coord Coord} - (def: (translate coord self) self) - (def: (rotate coord angle self) self) - (def: (scale width height self) self)) - -(def: queue0 (|> (new-List-Queue (list)) - (: (Queue Nat)) - (push +123) - (push +456) - (push +789) - pop)) -(def: point0 (new-Point ["YOLO" [123.4 567.8]])) + (|>. get@Collection list;size))) + +(interface: (Iterable a) + #extends (Collection a) + (enumerate [] (List a))) + +(class: (ListI a) (Iterable a) + #inherits (ListC a) + Unit + + (def: enumerate + get@Collection)) + +## Polymorphism +(def: (poly0 counter) + (-> Counter Nat) + (read counter)) + +(def: poly0-0 Nat (poly0 (new@NatC +0))) +(def: poly0-1 Nat (poly0 (new@NatRC +0 []))) + +(def: (poly1 counter) + (-> Resettable-Counter Nat) + (n.+ (read counter) + (read (reset counter)))) + +(def: poly1-0 Nat (poly1 (new@NatRC +0 []))) + +(def: (poly2 counter) + (-> NatC Nat) + (read counter)) + +(def: poly2-0 Nat (poly2 (new@NatC +0))) +(def: poly2-1 Nat (poly2 (new@NatRC +0 []))) + +(def: (poly3 counter) + (-> NatRC Nat) + (n.+ (read counter) + (read (reset counter)))) + +(def: poly3-0 Nat (poly3 (new@NatRC +0 []))) diff --git a/stdlib/test/tests.lux b/stdlib/test/tests.lux index 7bfff1634..7fb6eafb7 100644 --- a/stdlib/test/tests.lux +++ b/stdlib/test/tests.lux @@ -68,7 +68,7 @@ ["_;" type] (type ["_;" check] ["_;" auto]) - ## (paradigm ["_;" object]) + (paradigm ["_;" object]) )) (lux (control [contract]) (data [env] |