Skip to content

Commit dc682a4

Browse files
hkBstpetertseng
authored andcommitted
poker: Add tests for straights
Additional tests for straights with the same tests also for straight flushes. exercism/problem-specifications#2117
1 parent 80ce6b2 commit dc682a4

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

exercises/practice/poker/tests/poker.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ fn test_aces_can_start_a_straight_low() {
149149
test(&["4S 5H 4C 8D 4H", "4D AH 3S 2D 5C"], &["4D AH 3S 2D 5C"])
150150
}
151151

152+
#[test]
153+
#[ignore]
154+
fn test_no_ace_in_middle_of_straight() {
155+
// aces cannot be in the middle of a straight (Q K A 2 3)
156+
test(&["2C 3D 7H 5H 2S", "QS KH AC 2D 3S"], &["2C 3D 7H 5H 2S"])
157+
}
158+
152159
#[test]
153160
#[ignore]
154161
fn test_straight_ranks() {
@@ -222,9 +229,37 @@ fn test_straight_flush_beats_four_of_a_kind() {
222229
test(&["4S 5H 5S 5D 5C", "7S 8S 9S 6S 10S"], &["7S 8S 9S 6S 10S"])
223230
}
224231

232+
#[test]
233+
#[ignore]
234+
fn test_aces_can_end_a_straight_flush_high() {
235+
// aces can end a straight flush (10 J Q K A)
236+
test(&["KC AH AS AD AC", "10C JC QC KC AC"], &["10C JC QC KC AC"])
237+
}
238+
239+
#[test]
240+
#[ignore]
241+
fn test_aces_can_start_a_straight_flush_low() {
242+
// aces can start a straight flush (A 2 3 4 5)
243+
test(&["KS AH AS AD AC", "4H AH 3H 2H 5H"], &["4H AH 3H 2H 5H"])
244+
}
245+
246+
#[test]
247+
#[ignore]
248+
fn test_no_ace_in_middle_of_straight_flush() {
249+
// aces cannot be in the middle of a straight flush (Q K A 2 3)
250+
test(&["2C AC QC 10C KC", "QH KH AH 2H 3H"], &["2C AC QC 10C KC"])
251+
}
252+
225253
#[test]
226254
#[ignore]
227255
fn test_straight_flush_ranks() {
228-
// both hands have straight flush, tie goes to highest-ranked card
256+
// both hands have a straight flush, tie goes to highest-ranked card
229257
test(&["4H 6H 7H 8H 5H", "5S 7S 8S 9S 6S"], &["5S 7S 8S 9S 6S"])
230258
}
259+
260+
#[test]
261+
#[ignore]
262+
fn test_straight_flush_scoring() {
263+
// even though an ace is usually high, a 5-high straight flush is the lowest-scoring straight flush
264+
test(&["2H 3H 4H 5H 6H", "4D AD 3D 2D 5D"], &["2H 3H 4H 5H 6H"])
265+
}

0 commit comments

Comments
 (0)