aboutsummaryrefslogtreecommitdiff
path: root/lvc/src/bin/test.rs
blob: 0f630d34d815bedb55533a47041f460f44508123 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#[cfg(test)]
mod test {

    use lvc::huff::{read_huffman, write_huffman, BitIO};
    use std::io::Cursor;

    #[test]
    fn test_bitio() {
        let mut buf = Vec::<u8>::new();

        {
            let mut b = BitIO::new(Cursor::new(&mut buf));
            b.wbit(true).unwrap();
            b.wbit(true).unwrap();
            b.wbit(true).unwrap();
            b.wbit(true).unwrap();
            b.wbit(false).unwrap();
            b.wbit(true).unwrap();
            b.wbit(true).unwrap();
            b.wbit(true).unwrap();
            b.wbit(true).unwrap();
            b.flush().unwrap();
        }
        {
            let mut b = BitIO::new(Cursor::new(&mut buf));
            for _ in 0..9 {
                eprintln!("{:?}", b.rbit().unwrap())
            }
        }
    }

    #[test]
    fn test_huff() {
        let a = vec![1; 10000];
        let mut b = vec![];

        let mut buf = Vec::<u8>::new();
        write_huffman(&a, &mut Cursor::new(&mut buf)).unwrap();
        eprintln!("out {buf:x?}");
        read_huffman(&mut Cursor::new(&mut buf), &mut b).unwrap();

        assert_eq!(a, b)
    }
}

fn main() {}