{-|
Module      : Generate arbitrary events 
Description : Functions for generating arbitrary events
Copyright   : (c) NoviSci, Inc 2020
License     : BSD3
Maintainer  : bsaul@novisci.com
Stability   : experimental
-}
{-# OPTIONS_HADDOCK hide #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
module EventData.Arbitrary
  ( generateEventsInt
  ) where

import           Control.Monad                  ( Functor(fmap)
                                                , liftM2
                                                )
import           Data.Eq                        ( Eq((==)) )
import           Data.Function                  ( ($) )
import           Data.Int                       ( Int )
import           Data.List                      ( length )
import           Data.Ord                       ( Ord )
import           EventData.Context.Arbitrary    ( )
import           EventData.Core                 ( ConceptEvent
                                                , Event
                                                , event
                                                , toConceptEvent
                                                )
import           GHC.IO                         ( IO )
import           GHC.Show                       ( Show )
import           IntervalAlgebra                ( Interval )
import           IntervalAlgebra.Arbitrary      ( )
import           Test.QuickCheck                ( Arbitrary(arbitrary, shrink)
                                                , Gen
                                                , generate
                                                , orderedList
                                                , resize
                                                , sample
                                                , sample'
                                                , suchThat
                                                )

instance (Arbitrary (Interval a)) => Arbitrary (Event a) where
  arbitrary :: Gen (Event a)
arbitrary = (Interval a -> Context -> Event a)
-> Gen (Interval a) -> Gen Context -> Gen (Event a)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Interval a -> Context -> Event a
forall a. Interval a -> Context -> Event a
event Gen (Interval a)
forall a. Arbitrary a => Gen a
arbitrary Gen Context
forall a. Arbitrary a => Gen a
arbitrary

instance (Ord a, Show a, Arbitrary (Interval a)) => Arbitrary (ConceptEvent a) where
  arbitrary :: Gen (ConceptEvent a)
arbitrary = (Event a -> ConceptEvent a)
-> Gen (Event a) -> Gen (ConceptEvent a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Event a -> ConceptEvent a
forall a. (Show a, Ord a) => Event a -> ConceptEvent a
toConceptEvent Gen (Event a)
forall a. Arbitrary a => Gen a
arbitrary

-- | Generate @n@ @Event Int@
generateEventsInt :: Int -> IO [Event Int]
generateEventsInt :: Int -> IO [Event Int]
generateEventsInt Int
i =
  Gen [Event Int] -> IO [Event Int]
forall a. Gen a -> IO a
generate (Gen [Event Int] -> IO [Event Int])
-> Gen [Event Int] -> IO [Event Int]
forall a b. (a -> b) -> a -> b
$ Gen [Event Int] -> ([Event Int] -> Bool) -> Gen [Event Int]
forall a. Gen a -> (a -> Bool) -> Gen a
suchThat (Gen [Event Int]
forall a. (Ord a, Arbitrary a) => Gen [a]
orderedList :: Gen [Event Int]) (\[Event Int]
x -> [Event Int] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Event Int]
x Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
i)