Skip to content

Commit e4ac62a

Browse files
authored
Merge pull request #1555 from hkBst/main
Additional tests for straights
2 parents ecbc931 + dc682a4 commit e4ac62a

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

exercises/practice/poker/tests/poker.rs

+38-3
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,21 @@ fn test_aces_can_end_a_straight_high() {
144144

145145
#[test]
146146
#[ignore]
147-
fn test_aces_can_end_a_straight_low() {
147+
fn test_aces_can_start_a_straight_low() {
148148
// aces can start a straight (A 2 3 4 5)
149149
test(&["4S 5H 4C 8D 4H", "4D AH 3S 2D 5C"], &["4D AH 3S 2D 5C"])
150150
}
151151

152152
#[test]
153153
#[ignore]
154-
fn test_straight_cascade() {
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+
159+
#[test]
160+
#[ignore]
161+
fn test_straight_ranks() {
155162
// both hands with a straight, tie goes to highest ranked card
156163
test(&["4S 6C 7S 8D 5H", "5S 7H 8S 9D 6H"], &["5S 7H 8S 9D 6H"])
157164
}
@@ -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)