From 8667725d5c3b6755c32c3ddafb3aeb9f79ebc934 Mon Sep 17 00:00:00 2001 From: Polochon_street Date: Thu, 19 Sep 2024 20:24:37 +0200 Subject: [PATCH] Add more tests --- README.md | 2 +- TODO.md | 2 +- src/chroma.rs | 6 +++--- src/song/decoder.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 67bc8e6..5c3c6db 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The wheels are compiled used [maturin](https://github.com/PyO3/maturin/); the sources [are available here](https://github.com/Polochon-street/bliss-python) for inspiration. -Note 1: the features bliss-rs outputs is not compatible with the ones +Note: the features bliss-rs outputs is not compatible with the ones used by C-bliss, since it uses different, more accurate values, based on [actual literature](https://lelele.io/thesis.pdf). It is also faster. diff --git a/TODO.md b/TODO.md index 1a09700..4132abe 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,7 @@ ask questions if you want to tackle an item. ## Actual TODO -- Add a list of dependencies / installation guide +- Add a list of dependencies / installation guide for windows and mac - bliss: A way to learn a metric with a "user survey" on their own libraries using code from the thesis (probably reuse the interactive-playlist in blissify?) - Maybe add playlist functions for single songs as convenience methods? diff --git a/src/chroma.rs b/src/chroma.rs index 1ae2351..a007f7e 100644 --- a/src/chroma.rs +++ b/src/chroma.rs @@ -425,10 +425,10 @@ mod test { #[test] fn test_normalize_feature_sequence() { - let array = arr2(&[[0.1, 0.3, 0.4], [1.1, 0.53, 1.01]]); + let array = arr2(&[[0.1, 0.3, 0.4, 0.], [1.1, 0.53, 1.01, 0.]]); let expected_array = arr2(&[ - [0.08333333, 0.36144578, 0.28368794], - [0.91666667, 0.63855422, 0.71631206], + [0.08333333, 0.36144578, 0.28368794, 0.], + [0.91666667, 0.63855422, 0.71631206, 0.], ]); let normalized_array = normalize_feature_sequence(&array); diff --git a/src/song/decoder.rs b/src/song/decoder.rs index 9d7d6b2..f21e18a 100644 --- a/src/song/decoder.rs +++ b/src/song/decoder.rs @@ -237,6 +237,9 @@ fn main() -> BlissResult<()> { number_cores: NonZeroUsize, ) -> mpsc::IntoIter<(PathBuf, BlissResult)> { let mut cores = thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap()); + // If the number of cores that we have is greater than the number of cores + // that the user asked, comply with the user - otherwise we set a number + // that's too great. if cores > number_cores { cores = number_cores; } @@ -654,10 +657,13 @@ pub mod ffmpeg { mod tests { use crate::decoder::ffmpeg::FFmpeg as Decoder; use crate::decoder::Decoder as DecoderTrait; + use crate::decoder::PreAnalyzedSong; use crate::BlissError; + use crate::Song; use crate::SAMPLE_RATE; use adler32::RollingAdler32; use pretty_assertions::assert_eq; + use std::num::NonZero; use std::path::Path; fn _test_decode(path: &Path, expected_hash: u32) { @@ -801,6 +807,44 @@ pub mod ffmpeg { let expected_hash = 0xde831e82; _test_decode(Path::new("data/piano.wav"), expected_hash); } + + #[test] + fn test_try_from() { + let pre_analyzed_song = PreAnalyzedSong::default(); + assert!(>::try_into(pre_analyzed_song).is_err()); + } + + #[test] + fn test_analyze_paths() { + let analysis = Decoder::analyze_paths(["data/nonexistent", "data/piano.flac"]) + .map(|s| s.1.is_ok()) + .collect::>(); + assert_eq!(analysis, vec![false, true]); + } + + #[test] + fn test_analyze_paths_with_cores() { + // Analyze with a number of cores greater than the system's number of cores. + let analysis = Decoder::analyze_paths_with_cores( + [ + "data/nonexistent", + "data/piano.flac", + "data/nonexistent.cue", + ], + NonZero::new(usize::MAX).unwrap(), + ) + .map(|s| s.1.is_ok()) + .collect::>(); + assert_eq!(analysis, vec![false, true, false]); + } + + #[test] + fn test_analyze_paths_with_cores_empty_paths() { + let analysis = + Decoder::analyze_paths_with_cores::<&str, [_; 0]>([], NonZero::new(1).unwrap()) + .collect::>(); + assert_eq!(analysis, vec![]); + } } #[cfg(all(feature = "bench", feature = "ffmpeg", test))]