Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andcards.length
: The test was settingmemoryGame.pairsGuessed = 8
, but it wasn't settingmemoryGame.cards.length
. As a result, the conditionthis.pairsGuessed === this.cards.length / 2
in thecheckIfFinished
method was returning false, causing the test to fail even if the function is correctly implemented. This has been fixed by settingmemoryGame.cards = new Array(16)
in this spec of the test.1.2. Issue with
pairsClicked
: ThecheckIfFinished
method returns false ifpairsClicked
is 0. However, the test wasn't settingpairsClicked
to a non-zero value (which will be the case whenpairsGuessed
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.