Adding test cover the write_blk encode function
This commit is contained in:
@@ -15,4 +15,5 @@ anyhow = "1.0.57"
|
||||
thiserror = "1.0.31"
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = "1"
|
||||
quickcheck = "1"
|
||||
quickcheck_macros = "1"
|
||||
@@ -1,7 +1,19 @@
|
||||
#[cfg(test)]
|
||||
extern crate quickcheck;
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use(quickcheck)]
|
||||
extern crate quickcheck_macros;
|
||||
|
||||
use flat_rs::{decode, encode};
|
||||
use quickcheck::{Arbitrary, Gen};
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use core::num;
|
||||
|
||||
use quickcheck::Arbitrary;
|
||||
|
||||
#[test]
|
||||
fn encode_bool() {
|
||||
let bytes = crate::encode(&true).unwrap();
|
||||
@@ -31,4 +43,35 @@ mod test {
|
||||
|
||||
assert_eq!(decoded, 3_u8);
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
fn encode_vec_u8(xs: Vec<u8>) -> bool {
|
||||
let bytes = crate::encode(&xs).unwrap();
|
||||
let decoded: Vec<u8> = crate::decode(&bytes).unwrap();
|
||||
decoded == xs
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct BigChunk(Vec<u8>);
|
||||
|
||||
impl Arbitrary for BigChunk {
|
||||
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
|
||||
let num_of_element = g.choose(&[255, 256, 244, 100]).unwrap();
|
||||
|
||||
let mut vec = Vec::with_capacity(*num_of_element);
|
||||
for _ in 1..*num_of_element {
|
||||
vec.push(u8::arbitrary(g));
|
||||
}
|
||||
|
||||
BigChunk(vec)
|
||||
}
|
||||
}
|
||||
|
||||
#[quickcheck]
|
||||
fn encode_write_blk(xs: BigChunk) -> bool {
|
||||
let xs = xs.0;
|
||||
let bytes = crate::encode(&xs).unwrap();
|
||||
let decoded: Vec<u8> = crate::decode(&bytes).unwrap();
|
||||
decoded == xs
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user