diff --git a/Cargo.toml b/Cargo.toml index 4a6ab90..9b1753a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "wellen" -version = "0.9.5" +version = "0.9.6" edition = "2021" authors = ["Kevin Laeufer "] description = "Fast VCD and FST library for waveform viewers written in Rust." @@ -33,6 +33,7 @@ vcd = "0.7.0" clap = { version = "4.4.6", features = ["derive"] } criterion = "0.5" indicatif = "0.17.8" +proptest = "1.4.0" [profile.release] debug = true diff --git a/src/ghw/hierarchy.rs b/src/ghw/hierarchy.rs index 62ee614..90bccf6 100644 --- a/src/ghw/hierarchy.rs +++ b/src/ghw/hierarchy.rs @@ -1378,9 +1378,3 @@ impl FloatRange { self_range.start() >= other_range.start() && self_range.end() <= other_range.end() } } - -#[derive(Debug, Copy, Clone, PartialEq)] -struct GhwUnit { - name: StringId, - value: i64, -} diff --git a/src/ghw/signals.rs b/src/ghw/signals.rs index 109eb52..be09091 100644 --- a/src/ghw/signals.rs +++ b/src/ghw/signals.rs @@ -362,8 +362,7 @@ impl VecBuffer { // note, we keep the signal on the change list // return reference to value - let data = &self.data[info.data_range()]; - data + &self.data[info.data_range()] } #[inline] diff --git a/src/wavemem.rs b/src/wavemem.rs index 0204e87..f7b7ea5 100644 --- a/src/wavemem.rs +++ b/src/wavemem.rs @@ -1005,8 +1005,9 @@ fn compress_template( ) { debug_assert!(in_states.bits_in_a_byte() < out_states.bits_in_a_byte()); let mut working_byte = 0u8; + let max_bits = value.len() * in_states.bits_in_a_byte(); for bit in (0..bits).rev() { - let rev_bit = bits - bit - 1; + let rev_bit = max_bits - bit - 1; let in_byte = value[rev_bit / in_states.bits_in_a_byte()]; let in_value = (in_byte >> ((bit % in_states.bits_in_a_byte()) * in_states.bits())) & in_states.mask(); @@ -1180,4 +1181,37 @@ mod tests { } } } + + use proptest::prelude::*; + + fn convert_to_bits(states: States, chars: &str) -> Vec { + let mut out = Vec::new(); + write_n_state(states, chars.as_bytes(), &mut out, None); + out + } + + fn do_test_compress(value: String, max_states: States) { + let min_states = check_states(value.as_bytes()).unwrap(); + let bits = value.len(); + // convert string to bit vector + let max_value = convert_to_bits(max_states, &value); + // compress + let mut out = Vec::new(); + compress(&max_value, max_states, min_states, bits, &mut out); + // check + let direct_conversion = convert_to_bits(min_states, &value); + assert_eq!(direct_conversion, out, "{value} - write_n_states -> {max_value:?} - compress -> {out:?} != {direct_conversion:?}"); + } + + proptest! { + #[test] + fn compress_from_nine_state(value in "[01xz]{0,4}") { + do_test_compress(value, States::Nine); + } + + #[test] + fn compress_from_four_state(value in "[01]{0,4}") { + do_test_compress(value, States::Four); + } + } }