diff --git a/src/main.rs b/src/main.rs index f4f7872..9b241ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,44 +54,6 @@ where 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 { @@ -198,6 +160,45 @@ where #[cfg(test)] mod test { use super::*; + impl Decoder where I: Iterator { + // 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. fn test_backref_hash_function() {