Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Monoidal (->) tests #43

Merged
merged 4 commits into from
Oct 22, 2020
Merged

Add Monoidal (->) tests #43

merged 4 commits into from
Oct 22, 2020

Conversation

xplosunn
Copy link
Contributor

Helps with #7

I'm not sure if I understood the laws correctly and how they apply here. Any comments are appreciated.

Copy link

@hint-man hint-man bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why your PR is still not approved? Because I chose not to approve it. But they will.

prismSpecs = describe "Prism" $ do
describe "preview" $ do
xit "preview _Ctor x ≡ case (Ctor _) of" $
$(inspectTest $ 'matchMarkPrism === 'matchMarkManual) `shouldSatisfy` isSuccess
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Redundant do

describe "preview" $
  do xit "preview _Ctor x \8801 case (Ctor _) of" $
       $( inspectTest $ 'matchMarkPrism === 'matchMarkManual )
         `shouldSatisfy` isSuccess

prismSpecs = describe "Prism" $ do
describe "preview" $ do
xit "preview _Ctor x ≡ case (Ctor _) of" $
$(inspectTest $ 'matchMarkPrism === 'matchMarkManual) `shouldSatisfy` isSuccess
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Redundant do

xit "preview _Ctor x \8801 case (Ctor _) of" $
  $( inspectTest $ 'matchMarkPrism === 'matchMarkManual )
    `shouldSatisfy` isSuccess

profunctorsSpec = describe "Profunctor" $ do
describe "(->)" $ do
it "Identity: dimap id id ≡ id" $ hedgehog $ do
f <- forAllWith (const "f") genFunction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Reduce duplication

Suggested change
f <- forAllWith (const "f") genFunction
Combine with out/test/prolens/Test/Prolens/Property.hs:75:13

profunctorsSpec = describe "Profunctor" $ do
describe "(->)" $ do
it "Identity: dimap id id ≡ id" $ hedgehog $ do
f <- forAllWith (const "f") genFunction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Reduce duplication

Suggested change
f <- forAllWith (const "f") genFunction
Combine with out/test/prolens/Test/Prolens/Property.hs:80:13

it "Composition: dimap (ab . bc) (yz . xy) ≡ dimap bc yz . dimap ab xy" $ hedgehog $ do

f <- forAllWith (const "f") genFunction
ab <- forAllWith (const "ab") genFunction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Reduce duplication

Suggested change
ab <- forAllWith (const "ab") genFunction
Combine with out/test/prolens/Test/Prolens/Property.hs:57:13

it "Associativity" $ hedgehog $ do
f <- forAllWith (const "f") genFunction
x <- forAll genInt
dimap id id f x === f x
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Redundant do

describe "(->)" $
  do it "Identity: x -> id \8801 x" $
       hedgehog $
         do f <- forAllWith (const "f") genFunction
            x <- forAll genInt
            dimap id id f x === f x
     it "Associativity" $
       hedgehog $
         do f <- forAllWith (const "f") genFunction
            x <- forAll genInt
            dimap id id f x === f x

test/Test/Prolens/Property.hs Outdated Show resolved Hide resolved
test/Test/Prolens/Property.hs Show resolved Hide resolved
test/Test/Prolens/Property.hs Show resolved Hide resolved
@xplosunn
Copy link
Contributor Author

Should I fix all hint-man comments?

@vrom911 vrom911 added hacktoberfest-accepted tests Testing, property testing, DocTests labels Oct 20, 2020
Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your work @xplosunn ! I have added a few ideas in comments 🙂

And you can ignore "duplication" warnings of hintman, no worries 👌🏼

f <- forAllWith (const "f") genFunction
x <- forAll genInt
y <- forAll genInt
pappend pempty f (x, y) === (x, f y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id can't be used, and you actually check another law here, which is correct 👍🏼
However, we can make it even a bit more elegant and general, if we use the fact that it is Strong. We can check these properties instead:

pappend f pempty  first f
pappend pempty f  second f

x <- forAll genInt
y <- forAll genInt
z <- forAll genInt
pappend f (pappend g h) (x, (y, z)) === (f x, (g y, h z))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right.
I think we could make it even more cooler, if we would check both associativity at once as well:

pappend f (pappend g h) (x, (y, z))  === dimap (\(a, (b, c)) -> ((a, b), c))  (\((a, b), c) -> (a, (b, c)))(pappend (pappend f g) h (x, (y, z)) )

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that line becomes quite long.

My counterproposal is to add two helper functions

untupleRight :: (a, (b, c)) -> (a, b, c)
untupleRight (a, (b, c)) = (a, b, c)

untupleLeft :: ((a, b), c) -> (a, b, c)
untupleLeft ((a, b), c) = (a, b, c)

And the test would become

it "Associativity" $ hedgehog $ do
    f <- forAllWith (const "f") genFunction
    g <- forAllWith (const "g") genFunction
    h <- forAllWith (const "h") genFunction
    x <- forAll genInt
    y <- forAll genInt
    z <- forAll genInt
    untupleRight (pappend f (pappend g h) (x, (y, z))) === untupleLeft (pappend (pappend f g) h ((x, y), z))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the helper functions are way to go.
I don't think that dimap is too long to type, so I don't see why it is a problem..

Copy link
Contributor Author

@xplosunn xplosunn Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I can't get it to compile with dimap. I'm always running into issues like

Couldn't match type ‘Int’ with ‘((Int, b1), c0)’
      Expected type: (Int, (Int, Int))
                     -> (((a0, b0), Int), ((Int, b1), c0))
        Actual type: ((Int, Int), Int) -> ((Int, Int), Int)

Maybe it has something to do with the tuple type parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, no worries. I would look into that separately 🙂

Address identity comment
@xplosunn xplosunn requested a review from vrom911 October 20, 2020 17:51
Co-authored-by: Veronika Romashkina <[email protected]>
x <- forAll genInt
y <- forAll genInt
z <- forAll genInt
pappend f (pappend g h) (x, (y, z)) === (f x, (g y, h z))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, no worries. I would look into that separately 🙂

@vrom911 vrom911 merged commit fdcca86 into kowainik:master Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted tests Testing, property testing, DocTests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants