mirror of
https://github.com/Lysxia/generic-random.git
synced 2024-09-11 06:35:24 +03:00
Update examples
This commit is contained in:
parent
291f80256a
commit
adb52637ef
24
examples/aeson.hs
Normal file
24
examples/aeson.hs
Normal file
@ -0,0 +1,24 @@
|
||||
{-# LANGUAGE PartialTypeSignatures, ScopedTypeVariables #-}
|
||||
import Data.Aeson
|
||||
import qualified Data.HashMap.Lazy as HashMap
|
||||
import Data.Scientific
|
||||
import qualified Data.Vector as Vector
|
||||
import Data.Text ( Text )
|
||||
import qualified Data.Text as Text
|
||||
import Test.QuickCheck
|
||||
import Data.Random.Generics
|
||||
|
||||
genValue :: Int -> Gen Value
|
||||
genValue = pointedGeneratorWith aliases asGen
|
||||
|
||||
aliases :: [Alias Gen]
|
||||
aliases =
|
||||
[ alias $ return . (HashMap.fromList :: [(Text, Value)] -> _)
|
||||
, alias $ return . (Vector.fromList :: [Value] -> _)
|
||||
, alias $ \ () -> fmap (realToFrac :: Double -> Scientific) arbitrary
|
||||
, alias $ return . Text.pack
|
||||
, alias $ \ ~[()] -> arbitrary :: Gen String
|
||||
]
|
||||
|
||||
main :: IO ()
|
||||
main = sample (sized genValue)
|
@ -20,7 +20,7 @@ instance Show F where
|
||||
show (F f) = "<" ++ show (f True) ++ "," ++ show (f False) ++ ">"
|
||||
|
||||
gen :: Gen [F]
|
||||
gen = pointedGenerator asGen aliases 10
|
||||
gen = sized $ pointedGeneratorWith aliases asGen
|
||||
where
|
||||
aliases = [alias $ \() -> fmap F arbitrary :: Gen F]
|
||||
|
||||
|
36
examples/generic-random-examples.cabal
Normal file
36
examples/generic-random-examples.cabal
Normal file
@ -0,0 +1,36 @@
|
||||
name: generic-random-examples
|
||||
version: 0
|
||||
build-type: Simple
|
||||
cabal-version: >=1.10
|
||||
|
||||
executable aeson
|
||||
main-is: aeson.hs
|
||||
ghc-options: -Wall
|
||||
build-depends:
|
||||
aeson,
|
||||
base,
|
||||
unordered-containers,
|
||||
QuickCheck,
|
||||
scientific,
|
||||
text,
|
||||
vector,
|
||||
generic-random
|
||||
default-language: Haskell2010
|
||||
|
||||
executable functions
|
||||
main-is: functions.hs
|
||||
ghc-options: -Wall
|
||||
build-depends:
|
||||
base,
|
||||
QuickCheck,
|
||||
generic-random
|
||||
default-language: Haskell2010
|
||||
|
||||
executable positive-ints
|
||||
main-is: positive-ints.hs
|
||||
ghc-options: -Wall
|
||||
build-depends:
|
||||
base,
|
||||
MonadRandom,
|
||||
generic-random
|
||||
default-language: Haskell2010
|
@ -8,7 +8,7 @@ import Data.Random.Generics
|
||||
import Control.Monad.Random
|
||||
|
||||
gen :: IO [Int]
|
||||
gen = pointedGenerator asMonadRandom aliases 20
|
||||
gen = pointedGeneratorWith aliases asMonadRandom 20
|
||||
where
|
||||
aliases = [alias $ \() -> getRandomR (0, 100) :: IO Int]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user