Files
FiscusPublic/crates/fiscus-insight/tests/household.rs
T

32 lines
1.1 KiB
Rust

//! Day 2: household duplicates ("you both pay Spotify"), only from names members chose to share.
use fiscus_insight::household::{household_duplicates, Duplicate};
fn names(v: &[&str]) -> Vec<String> {
v.iter().map(|s| s.to_string()).collect()
}
#[test]
fn two_members_paying_the_same_service_is_a_duplicate() {
let shared = vec![
("mark".to_string(), names(&["PAYPAL *SPOTIFY", "Netflix.com", "O2 Czech"])),
("jana".to_string(), names(&["Spotify AB", "Netflix"])),
("kid".to_string(), names(&["Spotify"])),
];
let d = household_duplicates(&shared);
assert_eq!(
d,
vec![
Duplicate { key: "netflix".into(), members: vec!["jana".into(), "mark".into()] },
Duplicate { key: "spotify".into(), members: vec!["jana".into(), "kid".into(), "mark".into()] },
]
);
}
#[test]
fn one_member_alone_or_nobody_sharing_is_nothing() {
assert!(household_duplicates(&[]).is_empty());
let one = vec![("mark".to_string(), names(&["Spotify", "spotify", "PAYPAL *SPOTIFY"]))];
assert!(household_duplicates(&one).is_empty(), "the same member twice is not a duplicate");
}