From 07b18044de36f33dff9b2ed66a203507bfc7aa82 Mon Sep 17 00:00:00 2001 From: mat ess Date: Mon, 17 Apr 2023 19:17:50 -0400 Subject: [PATCH] Add tests --- src/main.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/main.rs b/src/main.rs index 9648012..12eb334 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,3 +86,63 @@ struct Song { performer: String, composer: String, } + +#[cfg(test)] +mod tests { + use super::*; + + fn bmbmbm() -> Song { + Song { + title: "bmbmbm".to_string(), + performer: "black midi".to_string(), + composer: "black midi".to_string(), + } + } + + fn love_story(performer: &str) -> Song { + Song { + title: "Love Story".to_string(), + performer: performer.to_string(), + composer: "Taylor Swift".to_string(), + } + } + + fn schizoid_man() -> Song { + Song { + title: "21st Century Schizoid Man".to_string(), + performer: "black midi".to_string(), + composer: "Greg Lake, Ian McDonald, Michael Giles, Peter Sinfield & Robert Fripp" + .to_string(), + } + } + + fn bm() -> Artist { + Artist { + name: "black midi".to_string(), + catalog: HashSet::from([bmbmbm(), love_story("black midi"), schizoid_man()]), + } + } + + fn ts() -> Artist { + Artist { + name: "Taylor Swift".to_string(), + catalog: HashSet::from([love_story("Taylor Swift")]), + } + } + + fn library() -> Library { + Library { + artists: HashSet::from([bm(), ts()]), + } + } + + #[test] + fn test_covered_songs() { + assert!(bm().covered_songs() == HashSet::from([&love_story("black midi"), &schizoid_man()])) + } + + #[test] + fn test_find_covers() { + assert!(library().find_covers() == HashSet::from([&love_story("black midi")])) + } +}