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

issue with memory.specs.js (correction submitted in pull request) #1960

Open
CrisRamosLazaro opened this issue May 22, 2024 · 0 comments
Open

Comments

@CrisRamosLazaro
Copy link

Below are the issues. I have created a pull request with the corrections.

1) Correction on last test ('should return true if all pairs are guessed') so the correct implentation passes.

The original test was failing even with a correct implementation of the checkIfFinished method. This was due to two issues:

1.1. Issue with pairsGuessed and cards.length: The test was setting memoryGame.pairsGuessed = 8, but it wasn't setting memoryGame.cards.length. As a result, the condition this.pairsGuessed === this.cards.length / 2 in the checkIfFinished method was returning false, causing the test to fail even if the function is correctly implemented. This has been fixed by setting memoryGame.cards = new Array(16) in this spec of the test.

1.2. Issue with pairsClicked: The checkIfFinished method returns false if pairsClicked is 0. However, the test wasn't setting pairsClicked to a non-zero value (which will be the case when pairsGuessed are larger than 1) in the 'should return true if all pairs are guessed' spec, also causing the test to fail even if the function is correctly implemented.
This has been fixed by setting memoryGame.pairsClicked = 1 in that spec.

2) Correction of 'should return the shuffled (mixed) array of cards'

The test is not correctly implemented. It was simply checking if the returned array is different from the passed array, which could lead to false positives

The new test simulates a more realistic scenario by running the shuffle operation multiple times, and then checking if at least one card has changed its position in the array after the shuffle. This approach is more reliable and increases the likelihood of catching a faulty shuffle operation, as it's statistically improbable for a correctly implemented shuffle to maintain the original order of cards across multiple iterations.

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