diff --git a/shanty-playlist/tests/unit.rs b/shanty-playlist/tests/unit.rs index 2205d0b..0a2f06a 100644 --- a/shanty-playlist/tests/unit.rs +++ b/shanty-playlist/tests/unit.rs @@ -85,13 +85,23 @@ fn test_score_tracks_basic() { let scored = score_tracks(&artists, &tracks_map, &top_map, 5, 0, None); - // Should have 3 tracks (only ones matching top tracks) - assert_eq!(scored.len(), 3); + // All 5 tracks should be included (unmatched get a small base score) + assert_eq!(scored.len(), 5); - // Higher playcount should yield higher score - let scores: Vec = scored.iter().map(|t| t.score).collect(); - let max_score = scores.iter().cloned().fold(f64::NEG_INFINITY, f64::max); - assert!(max_score > 0.0); + // Matched tracks should score higher than unmatched ones + let mut matched: Vec = scored + .iter() + .filter(|t| t.title.as_deref().is_some_and(|n| n.starts_with("Song 1") || n.starts_with("Song 2") || n.starts_with("Song 3"))) + .map(|t| t.score) + .collect(); + let mut unmatched: Vec = scored + .iter() + .filter(|t| t.title.as_deref().is_some_and(|n| n.starts_with("Song 4") || n.starts_with("Song 5"))) + .map(|t| t.score) + .collect(); + matched.sort_by(|a, b| b.partial_cmp(a).unwrap()); + unmatched.sort_by(|a, b| b.partial_cmp(a).unwrap()); + assert!(matched[0] > unmatched[0], "matched tracks should score higher than unmatched"); } #[test]