Skip to content

Commit

Permalink
Merge df31f85 into fa2bcda
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorenesduarte committed Aug 8, 2019
2 parents fa2bcda + df31f85 commit b21c570
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ authors = ["Vitor Enes <vitorenesduarte@gmail.com>"]
edition = "2018"

[dependencies]
quickcheck = "0.8"

[dev-dependencies]
criterion = "0.2"
rand = "0.6"
quickcheck = "0.8"
quickcheck_macros = "0.8"

[[bench]]
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
all: test fmt

test:
cargo test

fmt:
rustfmt src/* tests/* benches/*
rustfmt src/*.rs src/tests/*.rs benches/*

# `cargo install cargo-travis`
coverage:
Expand Down
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
reorder_imports = true
max_width = 80
wrap_comments = true
comment_width = 80
format_code_in_doc_comments = true
use_field_init_shorthand = true
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// traits.
mod traits;

// This module contains implementations of quickcheck::Arbitrary trait.
mod arbitrary;

// This module contains the implementation of a Max Set.
pub mod maxset;

Expand All @@ -21,10 +18,13 @@ pub mod multiset;
pub mod tclock;

// Top-level re-exports.
pub use crate::arbitrary::Musk;
pub use crate::below_exset::BelowExSet;
pub use crate::clock::{BEClock, Clock, Dot, VClock};
pub use crate::maxset::MaxSet;
pub use crate::multiset::MultiSet;
pub use crate::tclock::TClock;
pub use crate::traits::{Actor, Count, EventSet};

// Tests
#[cfg(test)]
mod tests;
23 changes: 13 additions & 10 deletions src/tclock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,21 @@ impl<A: Actor> TClock<A, BelowExSet> {
/// ```
/// use threshold::*;
///
/// let b = String::from("B");
/// let mut clock_a = BEClock::new();
/// clock_a.add_dot(&Dot::new(&Musk::B, 5));
/// clock_a.add_dot(&Dot::new(&Musk::B, 6));
/// clock_a.add_dot(&Dot::new(&b, 5));
/// clock_a.add_dot(&Dot::new(&b, 6));
///
/// let mut clock_b = BEClock::new();
/// clock_b.add_dot(&Dot::new(&Musk::B, 5));
/// clock_b.add_dot(&Dot::new(&Musk::B, 7));
/// clock_b.add_dot(&Dot::new(&b, 5));
/// clock_b.add_dot(&Dot::new(&b, 7));
///
/// let mut tclock = TClock::new();
/// tclock.add(clock_a);
/// tclock.add(clock_b);
///
/// let mut expected = BEClock::new();
/// expected.add_dot(&Dot::new(&Musk::B, 5));
/// expected.add_dot(&Dot::new(&b, 5));
///
/// assert_eq!(tclock.threshold_union(2), expected);
/// ```
Expand Down Expand Up @@ -302,15 +303,17 @@ fn event_count<E: EventSet>(

#[test]
fn regression_test() {
let b = String::from("B");

// Clock { clock: {B: BelowExSet { max: 6, exs: {1, 2, 3, 4} }} }
let mut clock_a = BEClock::new();
clock_a.add_dot(&Dot::new(&Musk::B, 5));
clock_a.add_dot(&Dot::new(&Musk::B, 6));
clock_a.add_dot(&Dot::new(&b, 5));
clock_a.add_dot(&Dot::new(&b, 6));

// Clock { clock: {B: BelowExSet { max: 7, exs: {1, 2, 3, 4, 6} }} }
let mut clock_b = BEClock::new();
clock_b.add_dot(&Dot::new(&Musk::B, 5));
clock_b.add_dot(&Dot::new(&Musk::B, 7));
clock_b.add_dot(&Dot::new(&b, 5));
clock_b.add_dot(&Dot::new(&b, 7));

// add both clocks to the threshold clock
let mut tclock = TClock::new();
Expand All @@ -322,7 +325,7 @@ fn regression_test() {

// create the expected clock
let mut expected = BEClock::new();
expected.add_dot(&Dot::new(&Musk::B, 5));
expected.add_dot(&Dot::new(&b, 5));

assert_eq!(clock, expected);
}
1 change: 0 additions & 1 deletion src/arbitrary.rs → src/tests/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use quickcheck::{Arbitrary, Gen};

/// This enum should allow tests to be more effective since they only work on a
/// small number of actors.
/// TODO move this to a module in `tests/`
#[derive(Clone, Hash, PartialEq, Eq, Debug)]
pub enum Musk {
A,
Expand Down
5 changes: 5 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod arbitrary;
mod prop_beclock;
mod prop_multiset;
mod prop_tclock;
mod prop_vclock;
7 changes: 3 additions & 4 deletions tests/prop_beclock.rs → src/tests/prop_beclock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use(quickcheck)]
extern crate quickcheck_macros;

use threshold::*;
use crate::tests::arbitrary::Musk;
use crate::*;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn next_dot(actor: Musk, beclock: BEClock<Musk>) -> bool {
Expand Down
6 changes: 2 additions & 4 deletions tests/prop_multiset.rs → src/tests/prop_multiset.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#[macro_use(quickcheck)]
extern crate quickcheck_macros;

use crate::MultiSet;
use quickcheck::TestResult;
use threshold::MultiSet;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn singleton(x: String, y: String) -> TestResult {
Expand Down
7 changes: 3 additions & 4 deletions tests/prop_tclock.rs → src/tests/prop_tclock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use(quickcheck)]
extern crate quickcheck_macros;

use threshold::*;
use crate::tests::arbitrary::Musk;
use crate::*;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn vclock_threshold(
Expand Down
7 changes: 3 additions & 4 deletions tests/prop_vclock.rs → src/tests/prop_vclock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use(quickcheck)]
extern crate quickcheck_macros;

use threshold::*;
use crate::tests::arbitrary::Musk;
use crate::*;
use quickcheck_macros::quickcheck;

#[quickcheck]
fn next_dot(actor: Musk, vclock: VClock<Musk>) -> bool {
Expand Down

0 comments on commit b21c570

Please sign in to comment.