Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Polochon-street committed Sep 28, 2024
1 parent ddb3df3 commit eb6d73a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
submodules: recursive
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2024-01-16
toolchain: nightly-2024-07-21
override: false
- name: Packages
run: sudo apt-get update && sudo apt-get install build-essential yasm libavutil-dev libavcodec-dev libavformat-dev libavfilter-dev libavfilter-dev libavdevice-dev libswresample-dev libfftw3-dev ffmpeg
Expand All @@ -33,7 +33,7 @@ jobs:
- name: Run tests
run: cargo test --verbose
- name: Build benches
run: cargo +nightly-2024-01-16 bench --verbose --features=bench --no-run
run: cargo +nightly-2024-07-21 bench --verbose --features=bench --no-run
- name: Run example tests
run: cargo test --verbose --examples
- name: Build examples with library
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions src/chroma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions src/song/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ fn main() -> BlissResult<()> {
number_cores: NonZeroUsize,
) -> mpsc::IntoIter<(PathBuf, BlissResult<Song>)> {
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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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!(<PreAnalyzedSong as TryInto<Song>>::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::<Vec<_>>();
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::<Vec<_>>();
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::<Vec<_>>();
assert_eq!(analysis, vec![]);
}
}

#[cfg(all(feature = "bench", feature = "ffmpeg", test))]
Expand Down

0 comments on commit eb6d73a

Please sign in to comment.