(.using [library [lux "*" ["_" test {"+" Test}] [abstract [monad {"+" do}] [\\specification ["$[0]" equivalence] ["$[0]" hash]]] [math ["[0]" random {"+" Random} ("[1]#[0]" monad)]] [data ["[0]" text ("[1]#[0]" equivalence) ["[0]" encoding {"+" Encoding}]] [collection ["[0]" list]]]]] ["[0]" / "_" ["[1][0]" language] ["[1][0]" territory]] [\\library ["[0]" / ["[0]" language {"+" Language}] ["[0]" territory {"+" Territory}]]]) (def: random_language (Random Language) (random.either (random#in language.afar) (random#in language.zaza))) (def: random_territory (Random Territory) (random.either (random#in territory.afghanistan) (random#in territory.zimbabwe))) (def: random_encoding (Random Encoding) (random.either (random#in encoding.ascii) (random#in encoding.koi8_u))) (def: random_locale (Random /.Locale) (do random.monad [language ..random_language territory ..random_territory encoding ..random_encoding] (in (/.locale language {.#Some territory} {.#Some encoding})))) (def: .public test Test (<| (_.covering /._) (_.for [/.Locale]) ($_ _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence ..random_locale)) (_.for [/.hash] (do [! random.monad] [fixed_language ..random_language fixed_territory ..random_territory fixed_encoding ..random_encoding] ($_ _.and (|> ..random_language (# ! each (function (_ language) (/.locale language {.#Some fixed_territory} {.#Some fixed_encoding}))) ($hash.spec /.hash)) (|> ..random_territory (# ! each (function (_ territory) (/.locale fixed_language {.#Some territory} {.#Some fixed_encoding}))) ($hash.spec /.hash)) (|> ..random_encoding (# ! each (function (_ encoding) (/.locale fixed_language {.#Some fixed_territory} {.#Some encoding}))) ($hash.spec /.hash)) ))) (do random.monad [language ..random_language territory ..random_territory encoding ..random_encoding .let [l_locale (/.locale language {.#None} {.#None}) lt_locale (/.locale language {.#Some territory} {.#None}) le_locale (/.locale language {.#None} {.#Some encoding}) lte_locale (/.locale language {.#Some territory} {.#Some encoding})] .let [language_check (and (text#= (language.code language) (/.code l_locale)) (list.every? (|>> /.code (text.starts_with? (language.code language))) (list lt_locale le_locale lte_locale))) territory_check (list.every? (|>> /.code (text.contains? (territory.long_code territory))) (list lt_locale lte_locale)) encoding_check (list.every? (|>> /.code (text.ends_with? (encoding.name encoding))) (list le_locale lte_locale))]] (_.cover [/.locale /.code] (and language_check territory_check encoding_check))) /language.test /territory.test )))