diff --git a/brro-compressor/src/compressor/mod.rs b/brro-compressor/src/compressor/mod.rs index 0970e62..c94cd72 100644 --- a/brro-compressor/src/compressor/mod.rs +++ b/brro-compressor/src/compressor/mod.rs @@ -25,7 +25,7 @@ impl Compressor { Compressor::Noop => noop(data), Compressor::FFT => fft(data, 8, 0.0, 10.0), // TODO: Remove the placeholders Compressor::Constant => constant(data), - _ => todo!(), + _ => noop(data), } } } diff --git a/brro-compressor/src/data.rs b/brro-compressor/src/data.rs index 74835e8..bba68c8 100644 --- a/brro-compressor/src/data.rs +++ b/brro-compressor/src/data.rs @@ -37,6 +37,7 @@ impl CompressedStream { /// Transforms the whole CompressedStream into bytes to be written to a file pub fn to_bytes(self) -> Vec { + // Will this chain encode?? let config = BinConfig::get(); bincode::encode_to_vec(self, config).unwrap() } @@ -50,3 +51,44 @@ impl CompressedStream { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_compress_chunk() { + let vector1 = vec![1.0, 1.0, 1.0, 1.0, 1.0]; + let mut cs = CompressedStream::new(); + cs.compress_chunk(&vector1); + assert_eq!(cs.data_frames.len(), 1); + } + + #[test] + fn test_compress_chunk_with() { + let vector1 = vec![1.0, 1.0, 1.0, 1.0, 1.0]; + let mut cs = CompressedStream::new(); + cs.compress_chunk_with(&vector1, Compressor::Constant); + assert_eq!(cs.data_frames.len(), 1); + } + + #[test] + fn test_to_bytes() { + let vector1 = vec![1.0; 1024]; + let mut cs = CompressedStream::new(); + cs.compress_chunk_with(&vector1, Compressor::Constant); + let b = cs.to_bytes(); + assert_eq!(b, [66, 82, 82, 79, 0, 1, 37, 0, 3, 3, 0, 2, 0]); + } + + #[test] + fn test_from_bytes() { + let vector1 = vec![1.0; 1024]; + let mut cs = CompressedStream::new(); + cs.compress_chunk_with(&vector1, Compressor::Constant); + let len = cs.data_frames.len(); + let b = cs.to_bytes(); + let cs2 = CompressedStream::from_bytes(&b); + assert_eq!(len, cs2.data_frames.len()); + } +} \ No newline at end of file diff --git a/brro-compressor/src/frame/mod.rs b/brro-compressor/src/frame/mod.rs index 6449108..c379a9e 100644 --- a/brro-compressor/src/frame/mod.rs +++ b/brro-compressor/src/frame/mod.rs @@ -28,6 +28,7 @@ impl CompressorFrame { } /// Calculates the size of the Frame and "closes it" + // TODO this is probably wrong, so we have to use the write stream to dump the bytes writen pub fn close(&mut self) { let size = size_of_val(&self.samples) + size_of_val(&self.compressor) diff --git a/brro-compressor/src/main.rs b/brro-compressor/src/main.rs index af1e1b6..999b6ab 100644 --- a/brro-compressor/src/main.rs +++ b/brro-compressor/src/main.rs @@ -48,7 +48,8 @@ fn process_args(input_path: &str, arguments: &Args) { } } else { // TODO: Make this do something... - compress_file(None, Vec::new()); + let cs = compress_file(None, Vec::new()); + cs.to_bytes(); } }