module MonusWeightedSearch.Internal.TestHelpers where
import Test.QuickCheck
import System.Random
sumsTo :: Int -> Gen [Int]
sumsTo :: Int -> Gen [Int]
sumsTo Int
n = [Int] -> Int -> Gen [Int]
forall {t}. (Ord t, Num t, Random t) => [t] -> t -> Gen [t]
go [] Int
n Gen [Int] -> ([Int] -> Gen [Int]) -> Gen [Int]
forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Int] -> Gen [Int]
forall a. [a] -> Gen [a]
shuffle
where
go :: [t] -> t -> Gen [t]
go [t]
ks t
n
| t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
0 = [t] -> Gen [t]
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure [t]
ks
| Bool
otherwise = do
t
m <- (t, t) -> Gen t
forall a. Random a => (a, a) -> Gen a
choose (t
1, t
n)
[t] -> t -> Gen [t]
go (t
m t -> [t] -> [t]
forall a. a -> [a] -> [a]
: [t]
ks) (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
m)
percentageChance :: Word -> Gen Bool
percentageChance :: Word -> Gen Bool
percentageChance Word
n = (Word -> Bool) -> Gen Word -> Gen Bool
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word
nWord -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>) ((Word, Word) -> Gen Word
forall a. Random a => (a, a) -> Gen a
choose (Word
0,Word
99))
percentageChanceIO :: Word -> IO Bool
percentageChanceIO :: Word -> IO Bool
percentageChanceIO Word
n = (Word -> Bool) -> IO Word -> IO Bool
forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word
nWord -> Word -> Bool
forall a. Ord a => a -> a -> Bool
>) ((Word, Word) -> IO Word
forall a (m :: Type -> Type).
(Random a, MonadIO m) =>
(a, a) -> m a
randomRIO (Word
0,Word
99))
{-# INLINE percentageChanceIO #-}