Skip to content

Commit

Permalink
Add test cases for handling overflows on dequantization and fix size …
Browse files Browse the repository at this point in the history
…of count7x7 (#78)

* work in progress

* improved tests

* add 16bit and 32bit tests

* add toml

* fix tests
  • Loading branch information
mcroomp authored May 22, 2024
1 parent 2e452f2 commit b700f48
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 236 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ thread-priority = "1.0.0"
[dev-dependencies]
rstest = "0.19"
rand = "0.8"
rand_chacha = "0.3"
siphasher = "1"

[[bin]]
Expand Down
8 changes: 8 additions & 0 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ pub fn calc_sign_index(val: i32) -> usize {
}
}

#[cfg(test)]
pub fn get_rand_from_seed(seed: [u8; 32]) -> rand_chacha::ChaCha12Rng {
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::ChaCha12Rng;

ChaCha12Rng::from_seed(seed)
}

/*
better way to update aritmetic encoding without using special division
Expand Down
4 changes: 1 addition & 3 deletions src/structs/bit_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,13 @@ fn roundtrip_bits() {
/// verify the the bits roundtrip correctly with random bits
#[test]
fn roundtrip_randombits() {
use rand::rngs::StdRng;
use rand::Rng;
use rand::SeedableRng;

let mut buf = Vec::new();

const ITERATIONS: usize = 10000;

let mut rng = StdRng::from_seed([0u8; 32]);
let mut rng = crate::helpers::get_rand_from_seed([0u8; 32]);
let mut test_data = Vec::with_capacity(ITERATIONS);

for _ in 0..ITERATIONS {
Expand Down
4 changes: 1 addition & 3 deletions src/structs/idct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,9 @@ pub fn test_idct_with_simple_block() {
/// implemenation from the original scalar C++ code
#[test]
pub fn test_idct_with_random_blocks() {
use rand::rngs::StdRng;
use rand::Rng;
use rand::SeedableRng;

let mut rng = StdRng::from_seed([0u8; 32]);
let mut rng = crate::helpers::get_rand_from_seed([0u8; 32]);
let mut test_data = AlignedBlock::default();
let mut test_q = [0u16; 64];

Expand Down
Loading

0 comments on commit b700f48

Please sign in to comment.