rearrange tests

png-branch
an 2019-03-12 16:28:08 -04:00
parent 24f22a682c
commit 119a45310d
37 changed files with 54 additions and 45 deletions

View File

@ -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
///

View File

@ -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

View File

@ -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]

View File

@ -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());
}

View File

@ -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);

View File

@ -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));
}

View File

@ -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());