Relocate the Decoder constructor hacks

The special constructors can be put in an impl block in the test module
instead of hanging out as dead code in the main library chunk.
This commit is contained in:
2024-05-09 15:44:32 -05:00
parent c0778ae887
commit 41d547f3ed

View File

@@ -54,44 +54,6 @@ where
run_len: 0, run_len: 0,
} }
} }
// A hack to unit test the index lookup behavior. A partial test can be done
// to verify the basic indexing principles by preloading a known buffer and
// then extracting back-referenced data out of it. A complete test should
// feed in other valid operations that populate the backbuffer, and then index
// op codes to demonstrate the indexing operations.
fn new_with_backbuffer(bytes: I, back_buffer: [PixelRGBA; 64]) -> Self {
Self {
back_buffer,
prev_pixel: PixelRGBA {
r: 0,
g: 0,
b: 0,
a: 255,
},
bytes,
run_len: 0,
}
}
// A hack to unit test the run behavior. Same idea as the new_with_backbuffer()
// function, but for testing a run of pixels.
fn new_with_previous_pixel(bytes: I, prev_pixel: PixelRGBA) -> Self {
Self {
back_buffer: [PixelRGBA::zero(); 64],
prev_pixel,
bytes,
run_len: 0,
}
}
pub(crate) fn peek_prev_pixel(&self) -> &PixelRGBA {
&self.prev_pixel
}
pub(crate) fn peek_backbuffer(&self, idx: usize) -> &PixelRGBA {
&self.back_buffer[idx]
}
} }
mod codec_utils { mod codec_utils {
@@ -198,6 +160,45 @@ where
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
impl <I> Decoder <I> where I: Iterator<Item=u8> {
// A hack to unit test the index lookup behavior. A partial test can be done
// to verify the basic indexing principles by preloading a known buffer and
// then extracting back-referenced data out of it. A complete test should
// feed in other valid operations that populate the backbuffer, and then index
// op codes to demonstrate the indexing operations.
fn new_with_backbuffer(bytes: I, back_buffer: [PixelRGBA; 64]) -> Self {
Self {
back_buffer,
prev_pixel: PixelRGBA {
r: 0,
g: 0,
b: 0,
a: 255,
},
bytes,
run_len: 0,
}
}
// A hack to unit test the run behavior. Same idea as the new_with_backbuffer()
// function, but for testing a run of pixels.
fn new_with_previous_pixel(bytes: I, prev_pixel: PixelRGBA) -> Self {
Self {
back_buffer: [PixelRGBA::zero(); 64],
prev_pixel,
bytes,
run_len: 0,
}
}
fn peek_prev_pixel(&self) -> &PixelRGBA {
&self.prev_pixel
}
fn peek_backbuffer(&self, idx: usize) -> &PixelRGBA {
&self.back_buffer[idx]
}
}
#[test] // this is mostly just to drive the function. Make sure it wraps or crashes in debug. #[test] // this is mostly just to drive the function. Make sure it wraps or crashes in debug.
fn test_backref_hash_function() { fn test_backref_hash_function() {