11{-# LANGUAGE TypeFamilies #-}
22
3+ {-# OPTIONS_GHC -Wno-orphans #-}
4+
35module ScheduledMergesTestQLS (tests ) where
46
57import Prelude hiding (lookup )
@@ -144,44 +146,44 @@ instance InLockstep Model where
144146 case findVars ctx (Proxy :: Proxy (LSM RealWorld )) of
145147 [] -> return (Some ANew )
146148 vars ->
147- frequency $
148- -- inserts of potentially fresh keys
149+ let kvars = findVars ctx (Proxy :: Proxy Key )
150+ existingKey = Left <$> elements kvars
151+ freshKey = Right <$> arbitrary @ Key
152+ in frequency $
153+ -- inserts of potentially fresh keys
149154 [ (3 , fmap Some $
150155 AInsert <$> elements vars
151- <*> fmap Right arbitrarySizedNatural -- key
152- <*> arbitrarySizedNatural) -- value
156+ <*> freshKey
157+ <*> arbitrary @ Value )
153158 ]
154- -- inserts of the same keys as used earlier
159+ -- inserts of the same keys as used earlier
155160 ++ [ (1 , fmap Some $
156161 AInsert <$> elements vars
157- <*> fmap Left (elements kvars) -- key var
158- <*> arbitrarySizedNatural) -- value
159- | let kvars = findVars ctx (Proxy :: Proxy Key )
160- , not (null kvars)
162+ <*> existingKey
163+ <*> arbitrary @ Value )
164+ | not (null kvars)
161165 ]
162166 -- deletes of arbitrary keys:
163167 ++ [ (1 , fmap Some $
164168 ADelete <$> elements vars
165- <*> fmap Right arbitrarySizedNatural) -- key value
169+ <*> freshKey)
166170 ]
167171 -- deletes of the same key as inserted earlier:
168172 ++ [ (1 , fmap Some $
169173 ADelete <$> elements vars
170- <*> fmap Left (elements kvars)) -- key var
171- | let kvars = findVars ctx (Proxy :: Proxy Key )
172- , not (null kvars)
174+ <*> existingKey)
175+ | not (null kvars)
173176 ]
174177 -- lookup of arbitrary keys:
175178 ++ [ (1 , fmap Some $
176179 ALookup <$> elements vars
177- <*> fmap Right arbitrarySizedNatural) -- key value
180+ <*> freshKey)
178181 ]
179182 -- lookup of the same key as inserted earlier:
180183 ++ [ (3 , fmap Some $
181184 ALookup <$> elements vars
182- <*> fmap Left (elements kvars)) -- key var
183- | let kvars = findVars ctx (Proxy :: Proxy Key )
184- , not (null kvars)
185+ <*> existingKey)
186+ | not (null kvars)
185187 ]
186188 ++ [ (1 , fmap Some $
187189 ADump <$> elements vars)
@@ -194,13 +196,13 @@ instance InLockstep Model where
194196 [ Some $ AInsert var (Right k') v' | (k', v') <- shrink (k, v) ]
195197
196198 shrinkWithVars _ctx _model (AInsert var (Left _kv) v) =
197- [ Some $ AInsert var (Right k) v | k <- shrink 100 ]
199+ [ Some $ AInsert var (Right k) v | k <- shrink ( K 100 ) ]
198200
199201 shrinkWithVars _ctx _model (ADelete var (Right k)) =
200202 [ Some $ ADelete var (Right k') | k' <- shrink k ]
201203
202204 shrinkWithVars _ctx _model (ADelete var (Left _kv)) =
203- [ Some $ ADelete var (Right k) | k <- shrink 100 ]
205+ [ Some $ ADelete var (Right k) | k <- shrink ( K 100 ) ]
204206
205207 shrinkWithVars _ctx _model _action = []
206208
@@ -289,3 +291,19 @@ runModel action ctx m =
289291
290292 lookUpKeyVar :: ModelVar Model Key -> Key
291293 lookUpKeyVar var = case lookupVar ctx var of MInsert k -> k
294+
295+ -------------------------------------------------------------------------------
296+ -- Instances
297+ --
298+
299+ instance Arbitrary Key where
300+ arbitrary = K <$> arbitrarySizedNatural
301+ shrink (K v) = K <$> shrink v
302+
303+ instance Arbitrary Value where
304+ arbitrary = V <$> arbitrarySizedNatural
305+ shrink (V v) = V <$> shrink v
306+
307+ instance Arbitrary Blob where
308+ arbitrary = B <$> arbitrarySizedNatural
309+ shrink (B v) = B <$> shrink v
0 commit comments