From 119a45310daf5a04320155278cd47969e313e68a Mon Sep 17 00:00:00 2001 From: Marrub Date: Tue, 12 Mar 2019 16:28:08 -0400 Subject: [PATCH] rearrange tests --- source/durandal/crc.rs | 3 +- tests/data/{ => defl}/Shapes.in | Bin tests/data/{ => defl}/Shapes.out | Bin tests/data/{ => defl}/alice.out | 0 tests/data/{ => defl}/alice1.in | Bin tests/data/{ => defl}/alice2.in | Bin tests/data/{gzbad1.bin => gz/bad1.in} | Bin tests/data/{gzbad2.bin => gz/bad2.in} | Bin tests/data/{gzbad3.bin => gz/bad3.in} | Bin tests/data/{gzbad4.bin => gz/bad4.in} | Bin tests/data/{gzbad5.bin => gz/bad5.in} | Bin tests/data/{gzbad6.bin => gz/bad6.in} | Bin tests/data/{gzbad7.bin => gz/bad7.in} | Bin tests/data/{gzipok1.bin => gz/ok1.in} | Bin tests/data/{gzipok2.bin => gz/ok2.in} | Bin tests/data/{gzipok3.bin => gz/ok3.in} | Bin tests/data/{ => map}/epnt.in | Bin tests/data/{ => map}/epnt.out | 0 tests/data/{ => map}/minf.in | Bin tests/data/{ => misc}/macbin.in | Bin tests/data/{ => pict}/clut.in | Bin tests/data/{ => pict}/clut.out | 0 tests/data/rand.rs | 14 ++--- tests/data/{random1.bin => rand/random1.in} | Bin tests/data/{random2.bin => rand/random2.in} | Bin tests/data/{random3.bin => rand/random3.in} | Bin tests/data/{random4.bin => rand/random4.in} | 0 tests/data/{random5.bin => rand/random5.in} | 0 tests/data/{random6.bin => rand/random6.in} | Bin tests/data/{random7.bin => rand/random7.in} | Bin tests/data/{ => trm}/term.in | Bin tests/data/{ => trm}/term.out | 0 tests/defl.rs | 66 +++++++++++--------- tests/map.rs | 6 +- tests/misc.rs | 2 +- tests/pict.rs | 4 +- tests/trm.rs | 4 +- 37 files changed, 54 insertions(+), 45 deletions(-) rename tests/data/{ => defl}/Shapes.in (100%) rename tests/data/{ => defl}/Shapes.out (100%) rename tests/data/{ => defl}/alice.out (100%) rename tests/data/{ => defl}/alice1.in (100%) rename tests/data/{ => defl}/alice2.in (100%) rename tests/data/{gzbad1.bin => gz/bad1.in} (100%) rename tests/data/{gzbad2.bin => gz/bad2.in} (100%) rename tests/data/{gzbad3.bin => gz/bad3.in} (100%) rename tests/data/{gzbad4.bin => gz/bad4.in} (100%) rename tests/data/{gzbad5.bin => gz/bad5.in} (100%) rename tests/data/{gzbad6.bin => gz/bad6.in} (100%) rename tests/data/{gzbad7.bin => gz/bad7.in} (100%) rename tests/data/{gzipok1.bin => gz/ok1.in} (100%) rename tests/data/{gzipok2.bin => gz/ok2.in} (100%) rename tests/data/{gzipok3.bin => gz/ok3.in} (100%) rename tests/data/{ => map}/epnt.in (100%) rename tests/data/{ => map}/epnt.out (100%) rename tests/data/{ => map}/minf.in (100%) rename tests/data/{ => misc}/macbin.in (100%) rename tests/data/{ => pict}/clut.in (100%) rename tests/data/{ => pict}/clut.out (100%) rename tests/data/{random1.bin => rand/random1.in} (100%) rename tests/data/{random2.bin => rand/random2.in} (100%) rename tests/data/{random3.bin => rand/random3.in} (100%) rename tests/data/{random4.bin => rand/random4.in} (100%) rename tests/data/{random5.bin => rand/random5.in} (100%) rename tests/data/{random6.bin => rand/random6.in} (100%) rename tests/data/{random7.bin => rand/random7.in} (100%) rename tests/data/{ => trm}/term.in (100%) rename tests/data/{ => trm}/term.out (100%) diff --git a/source/durandal/crc.rs b/source/durandal/crc.rs index 3893a53..97ec35d 100644 --- a/source/durandal/crc.rs +++ b/source/durandal/crc.rs @@ -18,7 +18,8 @@ fn crc_init() -> [u32; 256] t } -/// Creates a CRC-32 of all bytes in `b` with the starting sum `s`. +/// Creates a CRC-32 of all bytes in `b` with the starting sum `s`. The +/// polynomial used is the one from ISO-3309. /// /// # Examples /// diff --git a/tests/data/Shapes.in b/tests/data/defl/Shapes.in similarity index 100% rename from tests/data/Shapes.in rename to tests/data/defl/Shapes.in diff --git a/tests/data/Shapes.out b/tests/data/defl/Shapes.out similarity index 100% rename from tests/data/Shapes.out rename to tests/data/defl/Shapes.out diff --git a/tests/data/alice.out b/tests/data/defl/alice.out similarity index 100% rename from tests/data/alice.out rename to tests/data/defl/alice.out diff --git a/tests/data/alice1.in b/tests/data/defl/alice1.in similarity index 100% rename from tests/data/alice1.in rename to tests/data/defl/alice1.in diff --git a/tests/data/alice2.in b/tests/data/defl/alice2.in similarity index 100% rename from tests/data/alice2.in rename to tests/data/defl/alice2.in diff --git a/tests/data/gzbad1.bin b/tests/data/gz/bad1.in similarity index 100% rename from tests/data/gzbad1.bin rename to tests/data/gz/bad1.in diff --git a/tests/data/gzbad2.bin b/tests/data/gz/bad2.in similarity index 100% rename from tests/data/gzbad2.bin rename to tests/data/gz/bad2.in diff --git a/tests/data/gzbad3.bin b/tests/data/gz/bad3.in similarity index 100% rename from tests/data/gzbad3.bin rename to tests/data/gz/bad3.in diff --git a/tests/data/gzbad4.bin b/tests/data/gz/bad4.in similarity index 100% rename from tests/data/gzbad4.bin rename to tests/data/gz/bad4.in diff --git a/tests/data/gzbad5.bin b/tests/data/gz/bad5.in similarity index 100% rename from tests/data/gzbad5.bin rename to tests/data/gz/bad5.in diff --git a/tests/data/gzbad6.bin b/tests/data/gz/bad6.in similarity index 100% rename from tests/data/gzbad6.bin rename to tests/data/gz/bad6.in diff --git a/tests/data/gzbad7.bin b/tests/data/gz/bad7.in similarity index 100% rename from tests/data/gzbad7.bin rename to tests/data/gz/bad7.in diff --git a/tests/data/gzipok1.bin b/tests/data/gz/ok1.in similarity index 100% rename from tests/data/gzipok1.bin rename to tests/data/gz/ok1.in diff --git a/tests/data/gzipok2.bin b/tests/data/gz/ok2.in similarity index 100% rename from tests/data/gzipok2.bin rename to tests/data/gz/ok2.in diff --git a/tests/data/gzipok3.bin b/tests/data/gz/ok3.in similarity index 100% rename from tests/data/gzipok3.bin rename to tests/data/gz/ok3.in diff --git a/tests/data/epnt.in b/tests/data/map/epnt.in similarity index 100% rename from tests/data/epnt.in rename to tests/data/map/epnt.in diff --git a/tests/data/epnt.out b/tests/data/map/epnt.out similarity index 100% rename from tests/data/epnt.out rename to tests/data/map/epnt.out diff --git a/tests/data/minf.in b/tests/data/map/minf.in similarity index 100% rename from tests/data/minf.in rename to tests/data/map/minf.in diff --git a/tests/data/macbin.in b/tests/data/misc/macbin.in similarity index 100% rename from tests/data/macbin.in rename to tests/data/misc/macbin.in diff --git a/tests/data/clut.in b/tests/data/pict/clut.in similarity index 100% rename from tests/data/clut.in rename to tests/data/pict/clut.in diff --git a/tests/data/clut.out b/tests/data/pict/clut.out similarity index 100% rename from tests/data/clut.out rename to tests/data/pict/clut.out diff --git a/tests/data/rand.rs b/tests/data/rand.rs index cb2008b..2af07c5 100644 --- a/tests/data/rand.rs +++ b/tests/data/rand.rs @@ -1,11 +1,11 @@ const RANDOM: [&[u8]; 7] = [ - include_bytes!("random1.bin"), - include_bytes!("random2.bin"), - include_bytes!("random3.bin"), - include_bytes!("random4.bin"), - include_bytes!("random5.bin"), - include_bytes!("random6.bin"), - include_bytes!("random7.bin") + include_bytes!("rand/random1.in"), + include_bytes!("rand/random2.in"), + include_bytes!("rand/random3.in"), + include_bytes!("rand/random4.in"), + include_bytes!("rand/random5.in"), + include_bytes!("rand/random6.in"), + include_bytes!("rand/random7.in") ]; // EOF diff --git a/tests/data/random1.bin b/tests/data/rand/random1.in similarity index 100% rename from tests/data/random1.bin rename to tests/data/rand/random1.in diff --git a/tests/data/random2.bin b/tests/data/rand/random2.in similarity index 100% rename from tests/data/random2.bin rename to tests/data/rand/random2.in diff --git a/tests/data/random3.bin b/tests/data/rand/random3.in similarity index 100% rename from tests/data/random3.bin rename to tests/data/rand/random3.in diff --git a/tests/data/random4.bin b/tests/data/rand/random4.in similarity index 100% rename from tests/data/random4.bin rename to tests/data/rand/random4.in diff --git a/tests/data/random5.bin b/tests/data/rand/random5.in similarity index 100% rename from tests/data/random5.bin rename to tests/data/rand/random5.in diff --git a/tests/data/random6.bin b/tests/data/rand/random6.in similarity index 100% rename from tests/data/random6.bin rename to tests/data/rand/random6.in diff --git a/tests/data/random7.bin b/tests/data/rand/random7.in similarity index 100% rename from tests/data/random7.bin rename to tests/data/rand/random7.in diff --git a/tests/data/term.in b/tests/data/trm/term.in similarity index 100% rename from tests/data/term.in rename to tests/data/trm/term.in diff --git a/tests/data/term.out b/tests/data/trm/term.out similarity index 100% rename from tests/data/term.out rename to tests/data/trm/term.out diff --git a/tests/defl.rs b/tests/defl.rs index 5742b0d..3090833 100644 --- a/tests/defl.rs +++ b/tests/defl.rs @@ -2,58 +2,66 @@ use maraiah::marathon::defl; include!("data/rand.rs"); -#[test] -fn defl_alice() +fn defl_gzip(inp: &[u8], out: &[u8]) { - const IN_1: &[u8] = include_bytes!("data/alice1.in"); - const IN_2: &[u8] = include_bytes!("data/alice2.in"); - const OUT: &[u8] = include_bytes!("data/alice.out"); + let b = &inp[defl::load_gzip_header(inp).unwrap()..]; + assert_eq!(defl::load_deflate(b).unwrap().1, out.to_vec()); +} - let p = defl::load_gzip_header(IN_1).unwrap(); - assert_eq!(p, 0x14); +fn defl_alice(inp: &[u8]) +{ + const OUTPUT: &[u8] = include_bytes!("data/defl/alice.out"); - let b = &IN_1[p..]; - assert_eq!(defl::load_deflate(b).unwrap().1, OUT.to_vec()); + defl_gzip(inp, OUTPUT); +} - let p = defl::load_gzip_header(IN_2).unwrap(); - assert_eq!(p, 0x14); +#[test] +fn defl_alice_1() +{ + const INPUT: &[u8] = include_bytes!("data/defl/alice1.in"); - let b = &IN_2[p..]; - assert_eq!(defl::load_deflate(b).unwrap().1, OUT.to_vec()); + defl_alice(INPUT); +} + +#[test] +fn defl_alice_2() +{ + const INPUT: &[u8] = include_bytes!("data/defl/alice2.in"); + + defl_alice(INPUT); } #[test] fn defl_shapes() { - const INPUT: &[u8] = include_bytes!("data/Shapes.in"); - const OUTPUT: &[u8] = include_bytes!("data/Shapes.out"); + const INPUT: &[u8] = include_bytes!("data/defl/Shapes.in"); + const OUTPUT: &[u8] = include_bytes!("data/defl/Shapes.out"); - let b = &INPUT[defl::load_gzip_header(INPUT).unwrap()..]; - assert_eq!(defl::load_deflate(b).unwrap().1, OUTPUT.to_vec()); + defl_gzip(INPUT, OUTPUT); } #[test] -fn defl_must_succeed() +fn defl_good_gzip_headers() { - assert!(defl::load_gzip_header(include_bytes!("data/gzipok1.bin")).is_ok()); - assert!(defl::load_gzip_header(include_bytes!("data/gzipok2.bin")).is_ok()); - assert!(defl::load_gzip_header(include_bytes!("data/gzipok3.bin")).is_ok()); + defl::load_gzip_header(include_bytes!("data/gz/ok1.in")).unwrap(); + defl::load_gzip_header(include_bytes!("data/gz/ok2.in")).unwrap(); + defl::load_gzip_header(include_bytes!("data/gz/ok3.in")).unwrap(); } #[test] -fn defl_must_not_succeed() +fn defl_bad_gzip_headers() { for inp in &RANDOM { assert!(defl::load_gzip_header(inp).is_err()); } - assert!(defl::load_gzip_header(include_bytes!("data/gzbad1.bin")).is_err()); - assert!(defl::load_gzip_header(include_bytes!("data/gzbad2.bin")).is_err()); - assert!(defl::load_gzip_header(include_bytes!("data/gzbad3.bin")).is_err()); - assert!(defl::load_gzip_header(include_bytes!("data/gzbad4.bin")).is_err()); - assert!(defl::load_gzip_header(include_bytes!("data/gzbad5.bin")).is_err()); - assert!(defl::load_gzip_header(include_bytes!("data/gzbad6.bin")).is_err()); - assert!(defl::load_gzip_header(include_bytes!("data/gzbad7.bin")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad1.in")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad2.in")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad3.in")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad4.in")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad5.in")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad6.in")).is_err()); + assert!(defl::load_gzip_header(include_bytes!("data/gz/bad7.in")).is_err()); } #[test] diff --git a/tests/map.rs b/tests/map.rs index 760a33c..e8e4ce1 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -5,7 +5,7 @@ include!("data/rand.rs"); #[test] fn read_minf_must_process() { - const INPUT: &[u8] = include_bytes!("data/minf.in"); + const INPUT: &[u8] = include_bytes!("data/map/minf.in"); let out = map::Minf{texture_id: 0, physics_id: 1, @@ -21,8 +21,8 @@ fn read_minf_must_process() #[test] fn read_epnt_must_process() { - const INPUT: &[u8] = include_bytes!("data/epnt.in"); - const OUTPUT: [map::Point; 54] = include!("data/epnt.out"); + const INPUT: &[u8] = include_bytes!("data/map/epnt.in"); + const OUTPUT: [map::Point; 54] = include!("data/map/epnt.out"); assert_eq!(bin::rd_array(INPUT, map::read_epnt).unwrap(), OUTPUT.to_vec()); } diff --git a/tests/misc.rs b/tests/misc.rs index 048e7e9..d167be1 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -5,7 +5,7 @@ include!("data/rand.rs"); #[test] fn machdr_must_process() { - const INPUT: &[u8] = include_bytes!("data/macbin.in"); + const INPUT: &[u8] = include_bytes!("data/misc/macbin.in"); assert_eq!(machdr::check_macbin(INPUT), Some(128)); assert_eq!(machdr::try_mac_header(INPUT), 128); diff --git a/tests/pict.rs b/tests/pict.rs index bbf747d..8fb4e7a 100644 --- a/tests/pict.rs +++ b/tests/pict.rs @@ -5,8 +5,8 @@ include!("data/rand.rs"); #[test] fn get_clut_must_process() { - const INPUT: &[u8] = include_bytes!("data/clut.in"); - const OUTPUT: [Color8; 256] = include!("data/clut.out"); + const INPUT: &[u8] = include_bytes!("data/pict/clut.in"); + const OUTPUT: [Color8; 256] = include!("data/pict/clut.out"); assert_eq!(pict::get_clut(INPUT).unwrap(), (OUTPUT.to_vec(), 2056)); } diff --git a/tests/trm.rs b/tests/trm.rs index 28b6b06..6bd57fd 100644 --- a/tests/trm.rs +++ b/tests/trm.rs @@ -5,10 +5,10 @@ include!("data/rand.rs"); #[test] fn read_term_must_process() { - const INPUT: &[u8] = include_bytes!("data/term.in"); + const INPUT: &[u8] = include_bytes!("data/trm/term.in"); let inp = bin::rd_array(INPUT, trm::read_term).unwrap(); - let out = include!("data/term.out"); + let out = include!("data/trm/term.out"); // for better debug output, we iterate over each item assert_eq!(inp.len(), out.len());