Add property tests for the Validation type#216
Add property tests for the Validation type#216vrom911 merged 3 commits intokowainik:masterfrom astynax:validaion-props
Conversation
| prop_monoidRightIdentity :: Property | ||
| prop_monoidRightIdentity = property $ do | ||
| x <- forAll $ asValidation genSmallText | ||
| x <> mempty === x |
There was a problem hiding this comment.
Warning: Monoid law, right identity
| x <> mempty === x | |
| x === x |
| prop_monoidLeftIdentity :: Property | ||
| prop_monoidLeftIdentity = property $ do | ||
| x <- forAll $ asValidation genSmallText | ||
| mempty <> x === x |
There was a problem hiding this comment.
Warning: Monoid law, left identity
| mempty <> x === x | |
| x === x |
| prop_applicativeIdentity :: Property | ||
| prop_applicativeIdentity = property $ do | ||
| vx <- forAll $ asValidation genSmallText | ||
| (pure id <*> vx) === vx |
There was a problem hiding this comment.
Suggestion: Use <$>
| (pure id <*> vx) === vx | |
| (id <$> vx) === vx |
| vf <- forAllWith (const "f") $ asValidation genFunction | ||
| vg <- forAllWith (const "g") $ asValidation genFunction | ||
| vx <- forAll $ asValidation genSmallInt | ||
| (pure (.) <*> vf <*> vg <*> vx) === (vf <*> (vg <*> vx)) |
There was a problem hiding this comment.
Suggestion: Use <$>
| (pure (.) <*> vf <*> vg <*> vx) === (vf <*> (vg <*> vx)) | |
| (((.) <$> vf) <*> vg <*> vx) === (vf <*> (vg <*> vx)) |
| prop_applicativeInterchange = property $ do | ||
| vf <- forAllWith (const "f") $ asValidation genFunction | ||
| x <- forAll genSmallInt | ||
| (vf <*> pure x) === (pure ($ x) <*> vf) |
There was a problem hiding this comment.
Suggestion: Use <$>
| (vf <*> pure x) === (pure ($ x) <*> vf) | |
| (vf <*> pure x) === (($ x) <$> vf) |
| prop_alternativeRightIdentity :: Property | ||
| prop_alternativeRightIdentity = property $ do | ||
| x <- forAll $ asValidation genSmallText | ||
| (x <|> empty) === x |
There was a problem hiding this comment.
Warning: Alternative law, right identity
| (x <|> empty) === x | |
| (x) === x |
| prop_alternativeLeftIdentity :: Property | ||
| prop_alternativeLeftIdentity = property $ do | ||
| x <- forAll $ asValidation genSmallText | ||
| (empty <|> x) === x |
There was a problem hiding this comment.
Warning: Alternative law, left identity
| (empty <|> x) === x | |
| (x) === x |
|
@chshersh will I need to suppress such warnings from the bot? In this particular case code contains lines like |
|
@astynax Yeah, I know that this code is on purpose. Ideally, there should be a good library that already implements all required test-suites for laws for the standard typeclasses. Unfortunately, I'm not aware of such library for |
|
We can use HLint |
relude.cabal
Outdated
|
|
||
| other-modules: Test.Relude.Property | ||
|
|
||
| , Test.Relude.Extra.Validation.Property |
There was a problem hiding this comment.
Commas are redundant in module definitions
| , Test.Relude.Extra.Validation.Property | |
| Test.Relude.Extra.Validation.Property |
| Copyright: (c) 2016 Stephen Diehl | ||
| (c) 2016-2018 Serokell | ||
| (c) 2018-2019 Kowainik |
There was a problem hiding this comment.
I believe there's no need to specify everyone here, since it's a brand new module. So this can be just:
Copyright: (c) 2019 Kowainik| validationTestList :: [Group] | ||
| validationTestList = |
There was a problem hiding this comment.
Let's rename List suffix to Laws or Group to have better semantics
| a `op` (b `op` c) === (a `op` b) `op` c | ||
|
|
||
| ---------------------------------------------------------------------------- | ||
| -- Semogroup instance properties |
There was a problem hiding this comment.
Minor typo 🙂
| -- Semogroup instance properties | |
| -- Semigroup instance properties |
| prop_applicativeHomomorphism = property $ do | ||
| f <- forAllWith (const "f") genFunction | ||
| x <- forAll genSmallInt | ||
| (pure f <*> (pure x :: Validation [Text] Int)) === pure (f x) |
There was a problem hiding this comment.
I think this can be written a bit cleaner with type applications
| (pure f <*> (pure x :: Validation [Text] Int)) === pure (f x) | |
| (pure f <*> pure x) === pure @(Validation [Text]) (f x) |
vrom911
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
I will silence the HLint warnings in a separate PR.
Resolves #176
I added property tests for basic laws of
Semigroup/Monoid/Applicative/Alternative.A copule of tests checks that
<*and*>work just like default implementations inApplicativeclass.Checklist:
HLint
hlint.dhallaccordingly to my changes (add new rules for the new imports, remove old ones, when they are outdated, etc.)..hlint.yamlfile (see this instructions).General
stylish-haskellfile.[ci skip]text to the docs-only related commit's name.