Skip to content

Commit

Permalink
Add test with arbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
da-x committed Sep 5, 2021
1 parent ff73c96 commit 318d845
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ dipa-derive = {optional = true, version = "0.1", path = "./crates/dipa-derive"}

[dev-dependencies]
bincode = "1.3"
serde_derive = "1"
serde = "1"
quickcheck = "0.8"
quickcheck_macros = "0.8"
quickcheck_derive = "0.3"
rand = "0.6"

[workspace]
members = [
Expand Down
32 changes: 32 additions & 0 deletions tests/arbitrary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[cfg(test)]
#[cfg(feature = "derive")]
pub mod with_derive {
use dipa::{DiffPatch, Diffable, Patchable};
use quickcheck::quickcheck;
use quickcheck_derive::Arbitrary;
use serde_derive::{Deserialize, Serialize};
use bincode::Options;
use std::collections::BTreeMap;

#[derive(Clone, Eq, PartialEq, PartialOrd, Ord, Debug, DiffPatch, Serialize, Deserialize, Arbitrary)]
pub struct Basic {
pub items: BTreeMap<u16, Vec<u8>>,
}

fn tester(mut a: Basic, b: Basic) -> bool {
let bin = bincode::options().with_varint_encoding();
let created = a.create_delta_towards(&b);

let serialized = bin.serialize(&created.delta).unwrap();
let deserialized: <Basic as dipa::Diffable<'_, '_, Basic>>::DeltaOwned =
bin.deserialize(&serialized).unwrap();

a.apply_patch(deserialized);
return a == b;
}

#[test]
fn test() {
quickcheck(tester as fn(Basic, Basic) -> bool);
}
}

0 comments on commit 318d845

Please sign in to comment.