modes:single:tests: refactor
This commit is contained in:
@@ -46,6 +46,8 @@ impl Display for Single {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use std::convert::identity;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{make_decks, PlayingCard, Rank, Suit},
|
card::{make_decks, PlayingCard, Rank, Suit},
|
||||||
@@ -58,13 +60,8 @@ mod tests {
|
|||||||
assert!(Single::new(Card::make_joker()).is_none());
|
assert!(Single::new(Card::make_joker()).is_none());
|
||||||
|
|
||||||
let deck = make_decks(1);
|
let deck = make_decks(1);
|
||||||
let singles: Vec<Option<Single>> =
|
let singles = deck.iter().map(|&c| Single::new(c)).filter_map(identity);
|
||||||
deck.iter().map(|&c| Single::new(c)).collect();
|
let valid_singles = singles.collect::<Vec<_>>();
|
||||||
let valid_singles: Vec<Single> = singles
|
|
||||||
.iter()
|
|
||||||
.filter(|x| !x.is_none())
|
|
||||||
.map(|x| x.unwrap())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// TEST: Only two cards in a single deck aren't valid singles.
|
// TEST: Only two cards in a single deck aren't valid singles.
|
||||||
assert!(valid_singles.len() == deck.len() - 2);
|
assert!(valid_singles.len() == deck.len() - 2);
|
||||||
@@ -75,10 +72,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn footstool() {
|
fn footstool() {
|
||||||
let deck = make_decks(1);
|
// Make a deck with no jokers.
|
||||||
let deck = &deck[2..]; // skip the jokers
|
let singles = PlayingCard::iter_deck(0)
|
||||||
let singles: Vec<Single> =
|
.map(Card::PlayingCard)
|
||||||
deck.iter().map(|&c| Single::new(c).unwrap()).collect();
|
.filter_map(Single::new)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
singles.windows(3).for_each(|single_slice| {
|
singles.windows(3).for_each(|single_slice| {
|
||||||
let (s1, s2, s3) =
|
let (s1, s2, s3) =
|
||||||
@@ -103,16 +101,14 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for single in &singles {
|
for single in &singles {
|
||||||
let footstool_results: Vec<(Footstool, Footstool)> = singles
|
let footstool_results = singles
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&other_single| {
|
.map(|&other_single| {
|
||||||
// TEST: All footstool results are non-reflexive.
|
// TEST: All footstool results are non-reflexive.
|
||||||
test_non_reflexivity(single, &other_single)
|
test_non_reflexivity(single, &other_single)
|
||||||
})
|
})
|
||||||
.collect();
|
.map(|x| x.0)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
let footstool_results: Vec<Footstool> =
|
|
||||||
footstool_results.iter().map(|x| x.0).collect();
|
|
||||||
|
|
||||||
// TEST: A single is only full-footstooled by itself.
|
// TEST: A single is only full-footstooled by itself.
|
||||||
let full_footstools = footstool_results
|
let full_footstools = footstool_results
|
||||||
|
|||||||
Reference in New Issue
Block a user