modes:{pair,triple}:tests: refinement
This commit is contained in:
@@ -130,7 +130,7 @@ mod tests {
|
||||
// TEST: Any card with one joker can be made into a valid pair.
|
||||
let c2 = Card::make_joker();
|
||||
let pair = Pair::new(c1, c2);
|
||||
assert!(pair.is_some(), "Expected ({c1}, {c2}) to be a valid pair",);
|
||||
assert_ne!(pair, None, "Expected ({c1}, {c2}) to be a valid pair");
|
||||
|
||||
let pair = pair.unwrap();
|
||||
|
||||
@@ -157,8 +157,8 @@ mod tests {
|
||||
// TEST: Two cards of similar rank make a valid pair.
|
||||
let pair = {
|
||||
let pair = Pair::new(c1, c2);
|
||||
assert!(
|
||||
pair.is_some(),
|
||||
assert_ne!(
|
||||
pair, None,
|
||||
"Expected {c1} and {c2} to form a valid pair."
|
||||
);
|
||||
pair.unwrap()
|
||||
|
||||
@@ -111,7 +111,10 @@ impl Hash for Triple {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::card::{PlayingCard, Rank};
|
||||
use crate::{
|
||||
card::{PlayingCard, Rank},
|
||||
zipcartesian::ZipCartesianExt,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -129,8 +132,8 @@ mod tests {
|
||||
for card in PlayingCard::iter_all(0).map(Card::PlayingCard) {
|
||||
let trip = Triple::new(card, joker, joker);
|
||||
// TEST: Any card with two jokers is a triple
|
||||
assert!(
|
||||
trip.is_some(),
|
||||
assert_ne!(
|
||||
trip, None,
|
||||
"Expected ({card}, {joker}, {joker}) to make a triple"
|
||||
);
|
||||
let trip = trip.unwrap();
|
||||
@@ -147,8 +150,10 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
for rank in Rank::iter_all() {
|
||||
for (c1, c2) in rank.cards().zip(rank.cards()) {
|
||||
// Iterate over all pairs of cards with similar ranks
|
||||
for (c1, c2) in
|
||||
Rank::iter_all().flat_map(|r| r.cards().zip_cartesian(r.cards()))
|
||||
{
|
||||
let trip = Triple::new(c1, c2, joker);
|
||||
// TEST: Any two similar rank cards with 1 joker are a
|
||||
// Triple.
|
||||
@@ -181,11 +186,29 @@ mod tests {
|
||||
trip.2,
|
||||
);
|
||||
}
|
||||
|
||||
// Iterate over all pairs of cards with differing ranks
|
||||
for (c1, c2) in Rank::iter_all()
|
||||
.flat_map(|r1| {
|
||||
Rank::iter_all()
|
||||
.filter(move |&r2| r2 != r1)
|
||||
.map(move |r2| (r1, r2))
|
||||
})
|
||||
.flat_map(|(r1, r2)| r1.cards().zip_cartesian(r2.cards()))
|
||||
{
|
||||
// TEST: Cannot make a triple out of 1 joker and two different rank
|
||||
// cards
|
||||
let trip = Triple::new(c1, c2, joker);
|
||||
assert_eq!(
|
||||
trip, None,
|
||||
"Expected ({c1}, {c2}, {joker}) to never make a triple."
|
||||
);
|
||||
}
|
||||
|
||||
for (c1, (c2, c3)) in PlayingCard::iter_all(0)
|
||||
.zip(PlayingCard::iter_all(0).zip(PlayingCard::iter_all(0)))
|
||||
{
|
||||
// Iterate over all triples of cards (regardless of rank)
|
||||
for (c1, (c2, c3)) in PlayingCard::iter_all(0).zip_cartesian(
|
||||
PlayingCard::iter_all(0).zip_cartesian(PlayingCard::iter_all(0)),
|
||||
) {
|
||||
let [c1, c2, c3] = [c1, c2, c3].map(Card::PlayingCard);
|
||||
let trip = Triple::new(c1, c2, c3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user