Skip to content

Commit

Permalink
SCP-5126 Aligned Gen MList with semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwbush committed Mar 1, 2023
1 parent b65ccfe commit 9e068b6
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions marlowe-test/src/Spec/Marlowe/Plutus/MList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Data.Maybe (fromMaybe, isJust)
import Prelude hiding (lookup)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (Assertion, assertBool, testCase)
import Test.Tasty.QuickCheck (Arbitrary(..), Gen, Property, elements, forAll, property, shuffle, testProperty)
import Test.Tasty.QuickCheck (Arbitrary(..), Gen, Property, elements, forAll, property, testProperty)

import qualified PlutusTx.AssocMap as AM
(Map, delete, empty, fromList, insert, lookup, member, null, singleton, toList, unionWith)
Expand Down Expand Up @@ -185,8 +185,11 @@ type Value = [()]


-- | Generate a sorted `MList` with no duplicate keys.
arbitraryMList :: Gen (MList Key Value)
arbitraryMList = nubBy ((==) `on` fst) . sortBy (compare `on` fst) <$> arbitrary
arbitraryMList :: Gen (MList Key Value, AM.Map Key Value)
arbitraryMList =
do
items <- nubBy ((==) `on` fst) <$> arbitrary
pure (sortBy (compare `on` fst) items, AM.fromList items)


-- | Compare an `MList` to an `AssocMap`, ignoring ordering.
Expand All @@ -207,8 +210,7 @@ checkNull :: Property
checkNull = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
(mlist, assocmap) <- arbitraryMList
pure (mlist, assocmap)
forAll gen
$ \(mlist, assocmap) -> (== empty) mlist == AM.null assocmap
Expand All @@ -231,8 +233,7 @@ checkInsert :: Property
checkInsert = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
(mlist, assocmap) <- arbitraryMList
a <- arbitrary
b <- arbitrary
pure (mlist, assocmap, a, b)
Expand All @@ -245,8 +246,7 @@ checkDelete :: Property
checkDelete = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
(mlist, assocmap) <- arbitraryMList
a <- arbitrary
pure (mlist, assocmap, a)
forAll gen
Expand All @@ -258,8 +258,7 @@ checkLookup :: Property
checkLookup = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
(mlist, assocmap) <- arbitraryMList
a <- arbitrary
pure (mlist, assocmap, a)
forAll gen
Expand All @@ -271,8 +270,7 @@ checkMember :: Property
checkMember = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
(mlist, assocmap) <- arbitraryMList
a <- arbitrary
pure (mlist, assocmap, a)
forAll gen
Expand All @@ -284,10 +282,8 @@ checkUnionWith :: Property
checkUnionWith = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
mlist' <- arbitraryMList
assocmap' <- AM.fromList <$> shuffle mlist'
(mlist, assocmap) <- arbitraryMList
(mlist', assocmap') <- arbitraryMList
function <- elements ["concat", "shortest", "longest", "first", "second"]
pure (mlist, assocmap, mlist', assocmap', function)
forAll gen
Expand All @@ -308,8 +304,7 @@ checkFindWithDefault :: Property
checkFindWithDefault = property $ do
let
gen = do
mlist <- arbitraryMList
assocmap <- AM.fromList <$> shuffle mlist
(mlist, assocmap) <- arbitraryMList
a <- arbitrary
b <- arbitrary
pure (mlist, assocmap, a, b)
Expand Down

0 comments on commit 9e068b6

Please sign in to comment.