Add tests

main
mat ess 2023-04-17 19:17:50 -04:00
parent 3c0df12b50
commit 07b18044de
1 changed files with 60 additions and 0 deletions

View File

@ -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")]))
}
}