Poker: Make high card tests more robust

The tests in the Poker exercise currently pass even when the high cards are checked in the wrong order (lowest value to highest value card). This is an easy mistake to make when collecting spare cards to an array and sorting it (not realizing the array is sorted low → high).

When solving the exercise in Rust, I added two new tests and modified two existing ones to check for this mistake. My mentor suggested to open a PR to make the exercise more robust.

I didn’t know suggestions should be discussed here first, sorry about that, here is the PR anyway if anyone wants to take a look at how I modified the tests.

Thanks! cc @ErikSchierboom and @senekor.

LGTM!

The example solution on the Rust track passes all these test cases.

The tests look good. Is there any concern here about these new tests introducing new requirements and/or breaking existing solutions which currently pass?

I’d say that from an objective point of view, the tests don’t introduce new requirements since they only make high card checking more specific.

Some solutions could become broken if they checked for high cards in the wrong order (which would pass with the old test suite).

E.g. in test 4d90261d-251c-49bd-a468-896bf10133de.
Hands: 4H 7H 8H 9H 6H, 2S 4S 5S 6S 7S.
Spare cards sorted low to high:
["4H", "6H", "7H", "8H", "9H"], ["2S", "4S", "5S", "6S", "7S"]

If the first cards in the lists are compared, the first (correct) hand is identified as winning, but based on an incorrect condition (4>2), the winning hand should be determined by comparing 9>7.

By changing the hands in this test case to these:
2H 7H 8H 9H 6H, 3S 5S 6S 7S 8S,
the same code would no longer pass, since 2<3, identifying the second hand incorrectly as winning.

I imagine some people could make the same mistake, as the exercise is quite complex.

I agree with the above. The new test cases seem to only catch mistakes and not break any valid solutions.

1 Like

PR merged.

3 Likes