Skip to content

Commit

Permalink
more roundtrips
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Oct 13, 2024
1 parent 38bad08 commit f9e05f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/fse/fse_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::dbg;

use crate::decoding::bit_reader::BitReader;
use crate::decoding::bit_reader_reverse::{BitReaderReversed, GetBitsError};
use alloc::vec::Vec;
Expand Down Expand Up @@ -198,7 +196,6 @@ impl<'t> FSEDecoder<'t> {

/// Advance the internal state to decode the next symbol in the bitstream.
pub fn update_state(&mut self, bits: &mut BitReaderReversed<'_>) {
dbg!(self.state);
let num_bits = self.state.num_bits;
let add = bits.get_bits(num_bits);
let base_line = self.state.base_line;
Expand Down
22 changes: 19 additions & 3 deletions src/fse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ fn check_tables(dec_table: &fse_decoder::FSETable, enc_table: &fse_encoder::FSET
#[test]
fn roundtrip() {
round_trip(&(0..64).collect::<alloc::vec::Vec<_>>());
let mut data = alloc::vec![];
data.extend(0..32);
data.extend(0..32);
data.extend(0..32);
data.extend(0..32);
data.extend(0..32);
data.extend(20..32);
data.extend(20..32);
data.extend(0..32);
data.extend(20..32);
data.extend(100..255);
data.extend(20..32);
data.extend(20..32);
round_trip(&data);
}

pub fn round_trip(data: &[u8]) {
Expand Down Expand Up @@ -80,10 +94,12 @@ pub fn round_trip(data: &[u8]) {
let w = decoder.decode_symbol();
assert_eq!(w, *x);
decoded.push(w);
decoder.update_state(&mut br);
if decoded.len() < data.len() {
decoder.update_state(&mut br);
}
}

assert!(br.bits_remaining() == 0);

assert_eq!(&decoded, data);

assert_eq!(br.bits_remaining(), 0);
}

0 comments on commit f9e05f1

Please sign in to comment.