From 2cfe4069bb9b46778d737f5ca535edcb9993f356 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 12 Jun 2021 21:11:58 -0400 Subject: feat(xanthous): Add a generator for random english syllables Add a new "speech" generator module, with the beginnings of the vague definition of the phonotactics of the language (there's one in here for English based on the wikipedia article for English phonology, but it's less than ideal as it has generated words like "sprurlkt") and the ability to generate random syllables of a language by picking an onset, nucleus, and coda from the list for that language (within a range of the number of allowed of each syllable part). This will be used down the road to automatically generate utterances from various non-english-speaking creatures (so the accuracy is less important, just that it "feels real"). Change-Id: I7b81375ec595239c05c5c800cbde1a2a900e38ac Reviewed-on: https://cl.tvl.fyi/c/depot/+/3202 Reviewed-by: grfn Tested-by: BuildkiteCI --- users/grfn/xanthous/test/Xanthous/RandomSpec.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'users/grfn/xanthous/test/Xanthous') diff --git a/users/grfn/xanthous/test/Xanthous/RandomSpec.hs b/users/grfn/xanthous/test/Xanthous/RandomSpec.hs index 187336f086..c88bd95629 100644 --- a/users/grfn/xanthous/test/Xanthous/RandomSpec.hs +++ b/users/grfn/xanthous/test/Xanthous/RandomSpec.hs @@ -5,7 +5,10 @@ import Test.Prelude -------------------------------------------------------------------------------- import Control.Monad.Random -------------------------------------------------------------------------------- -import Xanthous.Random +import Xanthous.Random +import Xanthous.Orphans () +import qualified Data.Interval as Interval +import Data.Interval (Interval, Extended (Finite), (<=..<=)) -------------------------------------------------------------------------------- main :: IO () @@ -18,6 +21,23 @@ test = testGroup "Xanthous.Random" $ \(l :: [Int]) (Positive (r :: Double)) -> randomTest $ do ss <- chooseSubset r l pure $ all (`elem` l) ss + ] + , testGroup "chooseRange" + [ testProperty "chooses in the range" + $ \(rng :: Interval Int) -> + not (Interval.null rng) + ==> randomTest ( do + chooseRange rng >>= \case + Just r -> pure + . counterexample (show r) + $ r `Interval.member` rng + Nothing -> pure $ property Discard + ) + , testProperty "nonEmpty range is never empty" + $ \ (lower :: Int) (NonZero diff) -> randomTest $ do + let upper = lower + diff + r <- chooseRange (Finite lower <=..<= Finite upper) + pure $ isJust r ] ] -- cgit 1.4.1