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

[Roman Numerals] quick.Check test seems to always pass with regular int parameter #697

Open
heygarrett opened this issue Aug 31, 2023 · 0 comments

Comments

@heygarrett
Copy link
Contributor

heygarrett commented Aug 31, 2023

In the chapter Intro to property based tests we use the testing/quick package to create a new test, TestPropertiesOfConversion.

After creating the test:

Try running it; your computer may hang for a while, so kill it when you're bored :)

The test initially failed for me, but then it froze on the second run:

❮ go test ./numeral
--- FAIL: TestPropertiesOfConversion (0.00s)
    numeral_test.go:82: failed checks #1: failed on input -4221796472621171664
FAIL
FAIL    main/numeral    0.216s
FAIL
 
❮ go test ./numeral
^C⏎                                                                                                                                                                     

After adding this to the assertion function:

   if arabic < 0 || arabic > 3999 {
   	log.Println(arabic)
   	return true
   }

The book says:

You should see something like this:

=== RUN   TestPropertiesOfConversion
2019/07/09 14:41:27 6849766357708982977
2019/07/09 14:41:27 -7028152357875163913
2019/07/09 14:41:27 -6752532134903680693
2019/07/09 14:41:27 4051793897228170080
2019/07/09 14:41:27 -1111868396280600429
2019/07/09 14:41:27 8851967058300421387
2019/07/09 14:41:27 562755830018219185

But the test only passes for me after doing this:

❮ go test ./numeral
ok      main/numeral    0.184s
 
❮ go test ./numeral
ok      main/numeral    (cached)
 
❮ go test ./numeral
ok      main/numeral    (cached)
 
❮ go test ./numeral
ok      main/numeral    (cached)

I even tried clearing the cache, but no luck:

❯ go clean -cache
 
❮ go test ./numeral
ok      main/numeral    0.199s

If it matters:

❯ go version
go version go1.21.0 darwin/arm64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant