(.module: [library [lux #* ["_" test (#+ Test)] [abstract [equivalence (#+ Equivalence)] [monad (#+ do)]] [control [pipe (#+ case>)]] [data ["." text ("#\." equivalence) ["%" format (#+ format)]]] [macro ["." template]] [math ["." random] [number ["n" nat] ["i" int] ["f" frac]]] ["." type ("#\." equivalence)]]] [\\library ["." /]]) (/.import: java/lang/Object) (/.import: java/lang/String) (/.import: java/lang/Exception ["#::." (new [java/lang/String])]) (/.import: (java/lang/Class a) ["#::." (getName [] java/lang/String)]) (/.class: #final (TestClass A) [] ... Fields (#private increase java/lang/Long) (#private counter java/lang/Long) ... Methods (#public [] (new {increase java/lang/Long} {counter java/lang/Long}) [] (exec (:= ::increase increase) (:= ::counter counter) [])) (#public (currentC self) java/lang/Long ::counter) (#public (upC self) void (:= ::counter (i.+ ::increase ::counter))) (#public (downC self) void (:= ::counter (i.- ::increase ::counter)))) (/.import: (test/lux/ffi/TestClass a) ["#::." (new [java/lang/Long java/lang/Long]) (currentC [] java/lang/Long) (upC [] void) (downC [] void)]) (/.interface: TestInterface ([] current [] java/lang/Long #throws [java/lang/Exception]) ([] up [] test/lux/ffi/TestInterface #throws [java/lang/Exception]) ([] down [] test/lux/ffi/TestInterface #throws [java/lang/Exception])) (/.import: test/lux/ffi/TestInterface ["#::." (current [] java/lang/Long) (up [] java/lang/Long) (down [] java/lang/Long)]) (def: (test_object increase counter) (-> Int Int test/lux/ffi/TestInterface) (/.object [] [test/lux/ffi/TestInterface] [] (test/lux/ffi/TestInterface [] (current self) java/lang/Long counter) (test/lux/ffi/TestInterface [] (up self) test/lux/ffi/TestInterface (test_object increase (i.+ increase counter))) (test/lux/ffi/TestInterface [] (down self) test/lux/ffi/TestInterface (test_object increase (i.- increase counter))))) (def: conversions Test (do {! random.monad} [long random.int int (\ ! map (|>> /.long_to_int) random.int) char (\ ! map (|>> /.long_to_int /.int_to_char) random.int) double (|> random.frac (random.only (|>> f.not_a_number? not))) float (|> random.frac (random.only (|>> f.not_a_number? not)) (\ ! map (|>> /.double_to_float)))] (`` ($_ _.and (~~ (template [<=> ] [(_.cover [ ] (or (|> (<=> )) (let [capped (|> )] (|> capped (<=> capped)))))] [i.= long /.long_to_byte /.byte_to_long] [i.= long /.long_to_short /.short_to_long] [i.= long /.long_to_int /.int_to_long] [i.= long /.long_to_float /.float_to_long] [i.= long /.long_to_double /.double_to_long] [f.= double /.double_to_float /.float_to_double] [f.= double /.double_to_int /.int_to_double] )) (~~ (template [ ] [(_.cover [] (or (|> int (i.= (/.int_to_long int))) (let [capped (|> int )] (|> capped /.long_to_int (i.= capped)))))] [/.int_to_byte /.byte_to_long] [/.int_to_short /.short_to_long] [/.int_to_char /.char_to_long] )) (~~ (template [ ] [(_.cover [ ] (or (|> /.float_to_double (f.= (/.float_to_double ))) (let [capped (|> )] (|> capped /.float_to_double (f.= (/.float_to_double capped))))))] [float /.float_to_int /.int_to_float] )) (~~ (template [ ] [(_.cover [] (or (|> char (i.= (|> char /.char_to_int /.int_to_long))) (let [capped (|> char )] (|> capped /.long_to_int /.int_to_char (i.= capped)))))] [/.char_to_byte /.byte_to_long] [/.char_to_short /.short_to_long] )) (_.cover [/.char_to_long] (with_expansions [ /.int_to_char /.char_to_long] (`` (or (|> int (i.= (/.int_to_long int))) (let [capped (|> int )] (|> capped /.long_to_int (i.= capped))))))) (_.cover [/.char_to_int] (with_expansions [ /.int_to_char /.char_to_int] (`` (or (|> int /.int_to_long (i.= (/.int_to_long int))) (let [capped (|> int )] (|> capped /.int_to_long (i.= (/.int_to_long capped)))))))) )))) (def: arrays Test (do {! random.monad} [size (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1)))) idx (|> random.nat (\ ! map (n.% size))) value random.int] ($_ _.and (_.cover [/.array /.length] (n.= size (/.length (/.array java/lang/Long size)))) (_.cover [/.write! /.read!] (|> (/.array java/lang/Long size) (/.write! idx value) (/.read! idx) (i.= value))) ))) (def: null Test (do random.monad [sample (random.ascii 1)] ($_ _.and (_.cover [/.null /.null?] (and (/.null? (/.null)) (not (/.null? sample)))) (_.cover [/.???] (and (|> (: (Maybe java/lang/Object) (/.??? (/.null))) (case> #.None #1 _ #0)) (|> (: (Maybe java/lang/Object) (/.??? sample)) (case> (#.Some _) #1 _ #0)))) (_.cover [/.!!!] (and (/.null? (/.!!! (/.??? (/.null)))) (not (/.null? (/.!!! (/.??? sample)))))) ))) (def: miscellaneous Test (do random.monad [sample (random.ascii 1) counter random.int increase random.int] ($_ _.and (_.cover [/.check] (and (case (/.check java/lang/String sample) (#.Some _) true #.None false) (case (/.check java/lang/Long sample) (#.Some _) false #.None true) (case (/.check java/lang/Object sample) (#.Some _) true #.None false) (case (/.check java/lang/Object (/.null)) (#.Some _) false #.None true))) (_.cover [/.synchronized] (/.synchronized sample #1)) (_.cover [/.class_for /.import:] (|> (/.class_for java/lang/Class) java/lang/Class::getName (text\= "java.lang.Class"))) (_.cover [/.class: /.do_to] (|> (/.do_to (test/lux/ffi/TestClass::new increase counter) (test/lux/ffi/TestClass::upC) (test/lux/ffi/TestClass::upC) (test/lux/ffi/TestClass::downC)) test/lux/ffi/TestClass::currentC (i.= (i.+ increase counter)))) (_.cover [/.interface: /.object] (|> (..test_object increase counter) test/lux/ffi/TestInterface::up test/lux/ffi/TestInterface::up test/lux/ffi/TestInterface::down test/lux/ffi/TestInterface::current (i.= (i.+ increase counter)))) (_.cover [/.type] (and (type\= (primitive "java.lang.Char") (/.type java/lang/Char)) (type\= (primitive "java.util.List" [(primitive "java.lang.Byte")]) (/.type (java/util/List java/lang/Byte))))) ))) (def: .public test (<| (_.covering /._) ($_ _.and ..conversions ..arrays ..null ..miscellaneous )))