(.using [library [lux "*" ["_" test {"+" Test}] [abstract [equivalence {"+" Equivalence}] [monad {"+" do}]] [control ["[0]" pipe]] [data ["[0]" text ("[1]#[0]" equivalence) ["%" format {"+" format}]]] [macro ["[0]" template]] [math ["[0]" random] [number ["n" nat] ["i" int] ["f" frac]]] ["[0]" type ("[1]#[0]" equivalence)]]] [\\library ["[0]" /]]) (/.import: java/lang/Object "[1]::[0]") (/.import: java/lang/String "[1]::[0]") (/.import: java/lang/Exception "[1]::[0]" (new [java/lang/String])) (/.import: (java/lang/Class a) "[1]::[0]" (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) "[1]::[0]" (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 "[1]::[0]" (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 (# ! each (|>> /.long_to_int) random.int) char (# ! each (|>> /.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)) (# ! each (|>> /.double_to_float)))] (`` (all _.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 (# ! each (|>> (n.% 100) (n.max 1)))) idx (|> random.nat (# ! each (n.% size))) value random.int] (all _.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)] (all _.and (_.cover [/.null /.null?] (and (/.null? (/.null)) (not (/.null? sample)))) (_.cover [/.???] (and (|> (is (Maybe java/lang/Object) (/.??? (/.null))) (pipe.case {.#None} #1 _ #0)) (|> (is (Maybe java/lang/Object) (/.??? sample)) (pipe.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] (all _.and (_.cover [/.as] (and (case (/.as java/lang/String sample) {.#Some _} true {.#None} false) (case (/.as java/lang/Long sample) {.#Some _} false {.#None} true) (case (/.as java/lang/Object sample) {.#Some _} true {.#None} false) (case (/.as 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 /._) (all _.and ..conversions ..arrays ..null ..miscellaneous )))