{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Data.GenValidity.Mergeful.Collection where import Data.GenValidity import Data.GenValidity.Containers () import Data.GenValidity.Mergeful.Item () import Data.GenValidity.Time () import Data.Map (Map) import qualified Data.Map as M import Data.Mergeful import Data.Set (Set) import qualified Data.Set as S import Data.Traversable import Test.QuickCheck instance GenValid ClientId where genValid :: Gen ClientId genValid = forall a. (Generic a, GGenValid (Rep a)) => Gen a genValidStructurallyWithoutExtraChecking shrinkValid :: ClientId -> [ClientId] shrinkValid = forall a. (Generic a, GValidRecursivelyShrink (Rep a), GValidSubterms (Rep a) a) => a -> [a] shrinkValidStructurallyWithoutExtraFiltering instance (GenValid ci, GenValid si, Show ci, Show si, Ord ci, Ord si, GenValid a) => GenValid (ClientStore ci si a) where genValid :: Gen (ClientStore ci si a) genValid = (forall a. Gen a -> (a -> Bool) -> Gen a `suchThat` forall a. Validity a => a -> Bool isValid) forall a b. (a -> b) -> a -> b $ do Set si identifiers <- forall a. GenValid a => Gen a genValid (Set si s1, Set si s2) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si identifiers (Set si s3, Set si s4) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s1 Map ci a clientStoreAddedItems <- forall a. GenValid a => Gen a genValid Map si (Timed a) clientStoreSyncedItems <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s2 Map si (Timed a) clientStoreSyncedButChangedItems <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s3 Map si ServerTime clientStoreDeletedItems <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s4 forall (f :: * -> *) a. Applicative f => a -> f a pure ClientStore {Map ci a Map si ServerTime Map si (Timed a) clientStoreAddedItems :: Map ci a clientStoreSyncedItems :: Map si (Timed a) clientStoreSyncedButChangedItems :: Map si (Timed a) clientStoreDeletedItems :: Map si ServerTime clientStoreDeletedItems :: Map si ServerTime clientStoreSyncedButChangedItems :: Map si (Timed a) clientStoreSyncedItems :: Map si (Timed a) clientStoreAddedItems :: Map ci a ..} shrinkValid :: ClientStore ci si a -> [ClientStore ci si a] shrinkValid = forall a. (Validity a, Generic a, GValidRecursivelyShrink (Rep a), GValidSubterms (Rep a) a) => a -> [a] shrinkValidStructurally instance (GenValid si, Show si, Ord si, GenValid a) => GenValid (ServerStore si a) where genValid :: Gen (ServerStore si a) genValid = forall a. (Generic a, GGenValid (Rep a)) => Gen a genValidStructurallyWithoutExtraChecking shrinkValid :: ServerStore si a -> [ServerStore si a] shrinkValid = forall a. (Generic a, GValidRecursivelyShrink (Rep a), GValidSubterms (Rep a) a) => a -> [a] shrinkValidStructurallyWithoutExtraFiltering instance (GenValid ci, GenValid si, Show ci, Show si, Ord ci, Ord si, GenValid a) => GenValid (SyncRequest ci si a) where genValid :: Gen (SyncRequest ci si a) genValid = (forall a. Gen a -> (a -> Bool) -> Gen a `suchThat` forall a. Validity a => a -> Bool isValid) forall a b. (a -> b) -> a -> b $ do Set si identifiers <- forall a. GenValid a => Gen a genValid (Set si s1, Set si s2) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si identifiers (Set si s3, Set si s4) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s1 Map ci a syncRequestNewItems <- forall a. GenValid a => Gen a genValid Map si ServerTime syncRequestKnownItems <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s2 Map si (Timed a) syncRequestKnownButChangedItems <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s3 Map si ServerTime syncRequestDeletedItems <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s4 forall (f :: * -> *) a. Applicative f => a -> f a pure SyncRequest {Map ci a Map si ServerTime Map si (Timed a) syncRequestNewItems :: Map ci a syncRequestKnownItems :: Map si ServerTime syncRequestKnownButChangedItems :: Map si (Timed a) syncRequestDeletedItems :: Map si ServerTime syncRequestDeletedItems :: Map si ServerTime syncRequestKnownButChangedItems :: Map si (Timed a) syncRequestKnownItems :: Map si ServerTime syncRequestNewItems :: Map ci a ..} shrinkValid :: SyncRequest ci si a -> [SyncRequest ci si a] shrinkValid = forall a. (Validity a, Generic a, GValidRecursivelyShrink (Rep a), GValidSubterms (Rep a) a) => a -> [a] shrinkValidStructurally instance GenValid si => GenValid (ClientAddition si) where genValid :: Gen (ClientAddition si) genValid = forall a. (Generic a, GGenValid (Rep a)) => Gen a genValidStructurallyWithoutExtraChecking shrinkValid :: ClientAddition si -> [ClientAddition si] shrinkValid = forall a. (Generic a, GValidRecursivelyShrink (Rep a), GValidSubterms (Rep a) a) => a -> [a] shrinkValidStructurallyWithoutExtraFiltering instance (GenValid ci, GenValid si, Show ci, Show si, Ord ci, Ord si, GenValid a) => GenValid (SyncResponse ci si a) where genValid :: Gen (SyncResponse ci si a) genValid = (forall a. Gen a -> (a -> Bool) -> Gen a `suchThat` forall a. Validity a => a -> Bool isValid) forall a b. (a -> b) -> a -> b $ do Set si identifiers <- forall a. (Int -> Int) -> Gen a -> Gen a scale (forall a. Num a => a -> a -> a * Int 2) forall a. GenValid a => Gen a genValid (Set si s01, Set si s02) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si identifiers (Set si s03, Set si s04) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s01 (Set si s05, Set si s06) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s02 (Set si s07, Set si s08) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s03 (Set si s09, Set si s10) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s04 (Set si s11, Set si s12) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s05 (Set si s13, Set si s14) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s06 (Set si s15, Set si s16) <- forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set si s07 Map ci (ClientAddition si) syncResponseClientAdded <- do Map ci () m <- forall a. GenValid a => Gen a genValid :: Gen (Map ci ()) if forall a. Set a -> Bool S.null Set si s08 then forall (f :: * -> *) a. Applicative f => a -> f a pure forall k a. Map k a M.empty else forall (t :: * -> *) (m :: * -> *) a b. (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b) forM Map ci () m forall a b. (a -> b) -> a -> b $ \() -> forall i. i -> ServerTime -> ClientAddition i ClientAddition forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> forall a. [a] -> Gen a elements (forall a. Set a -> [a] S.toList Set si s08) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> forall a. GenValid a => Gen a genValid Map si ServerTime syncResponseClientChanged <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s09 let syncResponseClientDeleted :: Set si syncResponseClientDeleted = Set si s10 Map si (Timed a) syncResponseServerAdded <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s11 Map si (Timed a) syncResponseServerChanged <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s12 let syncResponseServerDeleted :: Set si syncResponseServerDeleted = Set si s13 Map si (Timed a) syncResponseConflicts <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s14 Map si (Timed a) syncResponseConflictsClientDeleted <- forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set si s15 let syncResponseConflictsServerDeleted :: Set si syncResponseConflictsServerDeleted = Set si s16 forall (f :: * -> *) a. Applicative f => a -> f a pure SyncResponse {Map ci (ClientAddition si) Map si ServerTime Map si (Timed a) Set si syncResponseClientAdded :: Map ci (ClientAddition si) syncResponseClientChanged :: Map si ServerTime syncResponseClientDeleted :: Set si syncResponseServerAdded :: Map si (Timed a) syncResponseServerChanged :: Map si (Timed a) syncResponseServerDeleted :: Set si syncResponseConflicts :: Map si (Timed a) syncResponseConflictsClientDeleted :: Map si (Timed a) syncResponseConflictsServerDeleted :: Set si syncResponseConflictsServerDeleted :: Set si syncResponseConflictsClientDeleted :: Map si (Timed a) syncResponseConflicts :: Map si (Timed a) syncResponseServerDeleted :: Set si syncResponseServerChanged :: Map si (Timed a) syncResponseServerAdded :: Map si (Timed a) syncResponseClientDeleted :: Set si syncResponseClientChanged :: Map si ServerTime syncResponseClientAdded :: Map ci (ClientAddition si) ..} shrinkValid :: SyncResponse ci si a -> [SyncResponse ci si a] shrinkValid = forall a. (Validity a, Generic a, GValidRecursivelyShrink (Rep a), GValidSubterms (Rep a) a) => a -> [a] shrinkValidStructurally splitSet :: Ord i => Set i -> Gen (Set i, Set i) splitSet :: forall i. Ord i => Set i -> Gen (Set i, Set i) splitSet Set i s = if forall a. Set a -> Bool S.null Set i s then forall (f :: * -> *) a. Applicative f => a -> f a pure (forall a. Set a S.empty, forall a. Set a S.empty) else do i a <- forall a. [a] -> Gen a elements forall a b. (a -> b) -> a -> b $ forall a. Set a -> [a] S.toList Set i s forall (f :: * -> *) a. Applicative f => a -> f a pure forall a b. (a -> b) -> a -> b $ forall a. Ord a => a -> Set a -> (Set a, Set a) S.split i a Set i s mapWithIds :: (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds :: forall i a. (Ord i, GenValid a) => Set i -> Gen (Map i a) mapWithIds Set i s = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap forall k a. Ord k => [(k, a)] -> Map k a M.fromList forall a b. (a -> b) -> a -> b $ forall (t :: * -> *) (f :: * -> *) a b. (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b) for (forall a. Set a -> [a] S.toList Set i s) forall a b. (a -> b) -> a -> b $ \i i -> (,) i i forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> forall a. GenValid a => Gen a genValid