... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. (.require [library [lux (.except) [abstract [monad (.only do)]] [control ["[0]" try] ["[0]" exception]] [math ["[0]" random (.only Random)] [number ["i" int]]] ["[0]" meta (.only) ["[0]" code] [macro [syntax (.only syntax)]]] [test ["_" property (.only Test)]]]] [\\library ["[0]" /]]) (def |divisor| (syntax (_ []) (do meta.monad [divisor meta.seed] (in (list (code.int (when divisor 0 +1 _ (.int divisor)))))))) (def .public (random range) (Ex (_ %) (-> Int (Random (/.Modulus %)))) (|> random.int (of 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] (when (/.modulus divisor) {try.#Success modulus} (i.= divisor (/.divisor modulus)) {try.#Failure error} (i.= +0 divisor))) (_.coverage [/.zero_cannot_be_a_modulus] (when (/.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))))) ))))