(.using [library [lux (.except) ["_" test (.only Test)] ["[0]" meta] [abstract ["[0]" monad (.only) [indexed (.only do)]]] [control ["[0]" io (.only IO)] ["[0]" try] ["[0]" exception (.only Exception)] [concurrency ["[0]" async (.only Async)]] [parser ["<[0]>" code]]] [data ["[0]" identity (.only Identity)] ["[0]" text ("[1]#[0]" equivalence) ["%" format (.only format)]]] ["[0]" macro (.only) [syntax (.only syntax:)] ["[0]" code]] [math ["[0]" random]]]] [\\library ["[0]" / (.only Res)]]) (def: pure Test (monad.do [! random.monad] [pre (# ! each %.nat random.nat) post (# ! each %.nat random.nat) .let [! identity.monad]] (_.for [/.Linear /.run! /.monad] (`` (all _.and (~~ (template [ ] [(_.coverage (<| (text#= (format pre post)) (is (Identity Text)) (/.run! !) (do (/.monad !) (in (format left right)))))] [[/.Affine /.Key /.Res /.Ordered /.ordered /.Relevant /.read] [res|left (/.ordered ! pre) res|right (/.ordered ! post) right (/.read ! res|right) left (/.read ! res|left)]] [[/.Commutative /.commutative /.exchange] [res|left (/.commutative ! pre) res|right (/.commutative ! post) _ ((/.exchange [1 0]) !) left (/.read ! res|left) right (/.read ! res|right)]] [[/.group /.un_group] [res|left (/.commutative ! pre) res|right (/.commutative ! post) _ ((/.group 2) !) _ ((/.un_group 2) !) right (/.read ! res|right) left (/.read ! res|left)]] [[/.lifted] [left (/.lifted ! pre) right (/.lifted ! post)]] )) ))))) (def: sync Test (monad.do [! random.monad] [pre (# ! each %.nat random.nat) post (# ! each %.nat random.nat) .let [! io.monad]] (_.for [/.Linear /.run! /.monad] (`` (all _.and (~~ (template [ ] [(_.coverage (<| (text#= (format pre post)) io.run! (is (IO Text)) (/.run! !) (do (/.monad !) (in (format left right)))))] [[/.Affine /.Key /.Res /.Ordered /.ordered /.Relevant /.read] [res|left (/.ordered ! pre) res|right (/.ordered ! post) right (/.read ! res|right) left (/.read ! res|left)]] [[/.Commutative /.commutative /.exchange] [res|left (/.commutative ! pre) res|right (/.commutative ! post) _ ((/.exchange [1 0]) !) left (/.read ! res|left) right (/.read ! res|right)]] [[/.group /.un_group] [res|left (/.commutative ! pre) res|right (/.commutative ! post) _ ((/.group 2) !) _ ((/.un_group 2) !) right (/.read ! res|right) left (/.read ! res|left)]] [[/.lifted] [left (/.lifted ! (io.io pre)) right (/.lifted ! (io.io post))]] )) ))))) (def: async Test (monad.do [! random.monad] [pre (# ! each %.nat random.nat) post (# ! each %.nat random.nat) .let [! async.monad]] (_.for [/.Linear /.run! /.monad] (`` (all _.and (~~ (template [ ] [(in (monad.do ! [outcome (<| (is (Async Text)) (/.run! !) (do (/.monad !) (in (format left right))))] (_.coverage' (text#= (format pre post) outcome))))] [[/.Affine /.Key /.Res /.Ordered /.ordered /.Relevant /.read] [res|left (/.ordered ! pre) res|right (/.ordered ! post) right (/.read ! res|right) left (/.read ! res|left)]] [[/.Commutative /.commutative /.exchange] [res|left (/.commutative ! pre) res|right (/.commutative ! post) _ ((/.exchange [1 0]) !) left (/.read ! res|left) right (/.read ! res|right)]] [[/.group /.un_group] [res|left (/.commutative ! pre) res|right (/.commutative ! post) _ ((/.group 2) !) _ ((/.un_group 2) !) right (/.read ! res|right) left (/.read ! res|left)]] [[/.lifted] [left (/.lifted ! (async.resolved pre)) right (/.lifted ! (async.resolved post))]] )) ))))) (syntax: (with_error [exception .symbol to_expand .any]) (monad.do meta.monad [[_ _ exception] (meta.export exception)] (function (_ compiler) {.#Right [compiler (list (code.bit (case ((macro.single_expansion to_expand) compiler) {try.#Success _} false {try.#Failure error} true)))]}))) (def: .public test Test (<| (_.covering /._) (_.for [/.Procedure]) (all _.and ..pure ..sync ..async (_.coverage [/.amount_cannot_be_zero] (`` (and (~~ (template [] [(with_error /.amount_cannot_be_zero ( 0))] [/.group] [/.un_group] ))))) (_.coverage [/.index_cannot_be_repeated] (with_error /.index_cannot_be_repeated (/.exchange [0 0]))) )))