Skip to content
This repository has been archived by the owner on Oct 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #92 from purescript/simplify-test-gens-rebase
Browse files Browse the repository at this point in the history
Rebased Simplify test gens
  • Loading branch information
garyb committed Mar 27, 2017
2 parents 001ad45 + a8089de commit 9d74e45
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions test/Test/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log, CONSOLE)
import Control.Monad.Eff.Exception (EXCEPTION)
import Control.Monad.Eff.Random (RANDOM)
import Data.NonEmpty ((:|))
import Data.Foldable (foldl, for_, all)
import Data.Function (on)
import Data.List (List(Cons), groupBy, length, nubBy, singleton, sort, sortBy)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Tuple (Tuple(..), fst)
import Partial.Unsafe (unsafePartial)
import Test.QuickCheck ((<?>), (===), quickCheck, quickCheck')
import Test.QuickCheck.Gen (elements, oneOf)
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary)

newtype TestMap k v = TestMap (M.Map k v)
Expand All @@ -39,19 +41,7 @@ instance showSmallKey :: Show SmallKey where
show J = "J"

instance arbSmallKey :: Arbitrary SmallKey where
arbitrary = do
n <- arbitrary
pure case n of
_ | n < 0.1 -> A
_ | n < 0.2 -> B
_ | n < 0.3 -> C
_ | n < 0.4 -> D
_ | n < 0.5 -> E
_ | n < 0.6 -> F
_ | n < 0.7 -> G
_ | n < 0.8 -> H
_ | n < 0.9 -> I
_ -> J
arbitrary = elements $ A :| [B, C, D, E, F, G, H, I, J]

data Instruction k v = Insert k v | Delete k

Expand All @@ -60,16 +50,7 @@ instance showInstruction :: (Show k, Show v) => Show (Instruction k v) where
show (Delete k) = "Delete (" <> show k <> ")"

instance arbInstruction :: (Arbitrary k, Arbitrary v) => Arbitrary (Instruction k v) where
arbitrary = do
b <- arbitrary
case b of
true -> do
k <- arbitrary
v <- arbitrary
pure (Insert k v)
false -> do
k <- arbitrary
pure (Delete k)
arbitrary = oneOf $ (Insert <$> arbitrary <*> arbitrary) :| [Delete <$> arbitrary]

runInstructions :: forall k v. Ord k => List (Instruction k v) -> M.Map k v -> M.Map k v
runInstructions instrs t0 = foldl step t0 instrs
Expand Down

0 comments on commit 9d74e45

Please sign in to comment.