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

[#26] Property tests: rewind & duplicate #331

Merged
merged 1 commit into from
Nov 1, 2020

Conversation

vrom911
Copy link
Member

@vrom911 vrom911 commented Nov 1, 2020

Part of #26

@vrom911 vrom911 added tests Testing, property testing, DocTests chapter1 chapter2 labels Nov 1, 2020
@vrom911 vrom911 requested a review from chshersh as a code owner November 1, 2020 15:08
@vrom911 vrom911 self-assigned this Nov 1, 2020
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.

xGen <- forAll $ Gen.int (Range.linear (-200) 200)
digit <- forAll $ Gen.int (Range.linear 1 9)
let x = if xGen `rem` 10 == 0 then xGen + digit else xGen
(firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)
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

it "last digit is the first digit of the reversed number" $
  hedgehog $
    do xGen <- forAll $ Gen.int (Range.linear (-200) 200)
       digit <- forAll $ Gen.int (Range.linear 1 9)
       let x = if xGen `rem` 10 == 0 then xGen + digit else xGen
       (firstDigit x :: Int) === (lastDigit (reverseInt x) :: Int)

describe "Task6: duplicate property" $ do
it "length (duplicate xs) = 2 * length xs" $ hedgehog $ do
xs <- forAll $ Gen.list (Range.linear 0 10) Gen.bool
length (duplicate xs) === 2 * length xs
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

it "length (duplicate xs) = 2 * length xs" $
  hedgehog $
    do xs <- forAll $ Gen.list (Range.linear 0 10) Gen.bool
       length (duplicate xs) === 2 * length xs

Copy link
Contributor

@chshersh chshersh left a comment

Choose a reason for hiding this comment

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

Nice properties and extra tests! 👍🏻

@chshersh chshersh merged commit 57fabbb into master Nov 1, 2020
@chshersh chshersh deleted the vrom911/26-Property-testing branch November 1, 2020 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chapter1 chapter2 tests Testing, property testing, DocTests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants