(.using [library [lux (.full) ["_" test (.only Test)] ["[0]" meta] [abstract [monad (.only do)]] [control ["[0]" try] ["[0]" exception]] [math ["[0]" random (.only Random)] [number ["i" int]]] [macro [syntax (.only syntax:)] ["[0]" code]]]] [\\library ["[0]" /]]) (syntax: (|divisor| []) (do meta.monad [divisor meta.seed] (in (list (code.int (case divisor 0 +1 _ (.int divisor))))))) (def: .public (random range) (Ex (_ %) (-> Int (Random (/.Modulus %)))) (|> random.int (# random.monad each (i.% range)) (random.one (|>> /.modulus try.maybe)))) (def: .public test Test (<| (_.covering /._) (_.for [/.Modulus]) (do random.monad [divisor random.int modulus (..random +1,000,000) dividend random.int] (all _.and (_.coverage [/.modulus /.divisor] (case (/.modulus divisor) {try.#Success modulus} (i.= divisor (/.divisor modulus)) {try.#Failure error} (i.= +0 divisor))) (_.coverage [/.zero_cannot_be_a_modulus] (case (/.modulus +0) {try.#Failure error} (exception.match? /.zero_cannot_be_a_modulus error) {try.#Success modulus} false)) (_.coverage [/.literal] (with_expansions [ (|divisor|)] (i.= (/.divisor (/.literal ))))) (_.coverage [/.=] (with_expansions [ (|divisor|)] (/.= (/.literal ) (/.literal )))) (_.coverage [/.congruent?] (and (/.congruent? modulus dividend dividend) (or (not (/.congruent? modulus dividend (++ dividend))) (i.= +1 (/.divisor modulus))))) ))))