Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
test: Add quickcheck test for round-tripping
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed May 12, 2016
1 parent 4ad4205 commit c0e7b42
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ readme = "README.md"

[dependencies]
clippy = {version = "*", optional = true}
quickcheck = {version = "0.2", optional = true}

[features]
default = []
1 change: 1 addition & 0 deletions src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ fn test_alice_wonderland() {
Err(err) => panic!("Decompression failed with error {:?}", err),
}
}

#[test]
fn easily_compressible() {
// RDB regression
Expand Down
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#![cfg_attr(feature="clippy", feature(plugin))]
#![cfg_attr(feature="clippy", plugin(clippy))]

#[cfg(all(test, feature = "quickcheck"))]
extern crate quickcheck;

use std::fmt;

mod compress;
Expand Down Expand Up @@ -103,3 +106,25 @@ fn test_compress_decompress_lorem_round() {
Err(err) => panic!("Decompression failed with error {:?}", err),
};
}

#[cfg(all(test, feature = "quickcheck"))]
mod quickcheck_test {
use super::*;
use quickcheck::{quickcheck, TestResult};

fn compress_decompress_round(data: Vec<u8>) -> TestResult {
let compr = match compress(&data) {
Ok(compr) => compr,
Err(LzfError::NoCompressionPossible) => return TestResult::discard(),
Err(LzfError::DataCorrupted) => return TestResult::discard(),
e @ _ => panic!(e),
};
let decompr = decompress(&compr, data.len()).unwrap();
TestResult::from_bool(data == decompr)
}

#[test]
fn qc_roundtrip() {
quickcheck(compress_decompress_round as fn(_) -> _);
}
}

0 comments on commit c0e7b42

Please sign in to comment.