-
Notifications
You must be signed in to change notification settings - Fork 34
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
Fix make test (Issue #14) #35
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the function valid_move is correct, so obviously the problem in tests. I wanted to make the same changes, but dont you think, that these modifications will change the sense of these tests? Have you looked on other tests?
Since only the ace of spades was used as source and destination card in all of the failed tests they were all performing the same test (ace clubs to ace clubs = fail). By using different cards, these tests now perform the test intended by their function names. Changing all of the assert() statements to always expect failure would be an easier fix but that would not accomplish the intention of the tests. Other tests could in fact be improved to be more complete but this change only fixes the failed tests. Added a bunch of memory free calls to fix all the numerous memory leaks reported by valgrind. |
Yeah, nice changes! Let's hope, that @mpereira can see them as soon as posible and pull them in new release=) |
Yes, don't worry I'm seeing the recent PRs. I'll be taking a look at them soon 🙂 |
Noticed the first card of the first manoeuvre stack was often an ace of diamonds on startup. It turns out the shuffle_deck() function wasn't shuffling the last position. You can still be lucky and another card gets randomly shuffled to that position but start the game 52 times and you'll see the ace of diamonds too often in the first manoeuvre stack. Removing the -1 insures the entire deck gets shuffled. Also on the following line the adding and subtracting of the variable i was deleted since it does nothing to the result of the modulo calculation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's really cool observation!
Hi @yoyoma2, Thanks for your PR. I had some time today to take a careful look at your changes and they look great! Nice spot with the off-by-one issue in I'll merge this and do a release. |
By the way, would you be able to share the valgrind command you used? I'll add a Makefile target for it, and soon hook this repository with CI. |
I just put valgrind before the non-stripped/debuggable executable as below. Then played the game and a memory report is printed to the terminal on exiting the game. All leaks were gone.
|
If you are automating tests then this command is more useful. It also gave zero memory errors after the pull request but I'm not sure it tests as many code paths as the real game.
|
Yeah, for CI running valgrind on the test executable might be more fitting. Thanks for sharing. |
Oh and the "in use at exit" in the game's case is not ttysolitaire's fault but a normal side effect of using ncurses as explained here. |
Thanks for the context 🙂 |
As the title states, this pull request fixes "make test" thus closing Issue #14. The failing tests were all using the ace of spades as the current card in both the source and destination stacks which can never be a valid move. The valid_move() function actually works fine as long as the test code sends valid cards when it expects a valid return code.
NB: This pull request only touches test code and makes absolutely no changes to game code.