use arithmetic_coding_adder_dep::{Decoder, Encoder, Model}; use bitstream_io::{BigEndian, BitReader, BitWrite, BitWriter}; pub fn round_trip(model: M, input: &[M::Symbol]) where M: Model + Clone, M::Symbol: PartialEq + std::fmt::Debug + Clone, { let buffer = encode(model.clone(), input.to_owned()); let output = decode(model, &buffer); assert_eq!(input, output.as_slice()); } fn encode(model: M, input: Vec) -> Vec where M: Model, { let mut bitwriter = BitWriter::endian(Vec::new(), BigEndian); let mut encoder = Encoder::new(model); encoder.encode_all(input).unwrap(); bitwriter.byte_align().unwrap(); bitwriter.into_writer() } fn decode(model: M, buffer: &[u8]) -> Vec where M: Model, { let bitreader = BitReader::endian(buffer, BigEndian); let mut decoder = Decoder::new(model, bitreader); decoder.decode_all().map(Result::unwrap).collect() }