diff --git a/Cargo.lock b/Cargo.lock index 912b462a8325c5baee67a6465735e6960cf54c8f..ce52b969520558ed5e04c31b74a25086056a5b31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,7 +107,7 @@ dependencies = [ [[package]] name = "duniter-wotb" -version = "0.6.1" +version = "0.6.2" dependencies = [ "bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/wotb/Cargo.toml b/wotb/Cargo.toml index eb0f10ad90d2d9f7940e90b75a6874f9165934de..213c02a862276a8249dfb1cbd0d5915d4416caae 100644 --- a/wotb/Cargo.toml +++ b/wotb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "duniter-wotb" -version = "0.6.1" +version = "0.6.2" authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@duniter.org>"] description = "Makes Web of Trust computations for the Duniter project." repository = "https://git.duniter.org/nodes/rust/duniter-rs" diff --git a/wotb/legacy.rs b/wotb/legacy.rs index 3cdd3e1b58962a347e117b4f878a02d919f1aec6..f70da9e47aeb2567fce7f3aaa50b860f92aaa784 100644 --- a/wotb/legacy.rs +++ b/wotb/legacy.rs @@ -553,33 +553,6 @@ mod tests { /// This test is a translation of https://github.com/duniter/wotb/blob/master/tests/test.js #[test] fn wot_tests() { - let mut wot = LegacyWebOfTrust::new(3); - let mut wot2 = LegacyWebOfTrust::new(3); - generic_wot_test(&mut wot, &mut wot2); - - // should be able to make a mem copy - { - let wot2 = wot.clone(); - - assert_eq!(wot.size(), wot2.size()); - assert_eq!( - wot.get_non_sentries(1).len(), - wot2.get_non_sentries(1).len() - ); - } - - // serialization - assert_eq!(wot.legacy_to_file("test.wot"), true); - - // deserialization - { - let wot2 = LegacyWebOfTrust::legacy_from_file("test.wot").unwrap(); - - assert_eq!(wot.size(), wot2.size()); - assert_eq!( - wot.get_non_sentries(1).len(), - wot2.get_non_sentries(1).len() - ); - } + generic_wot_test(LegacyWebOfTrust::new); } } diff --git a/wotb/lib.rs b/wotb/lib.rs index b9582366fbd9737331ed5adb6363f404c65c3a86..b0f9af3d5bed6afcebfcbbd2e92d02b794488c3b 100644 --- a/wotb/lib.rs +++ b/wotb/lib.rs @@ -387,7 +387,12 @@ mod tests { /// /// Clone and file tests are not included in this generic test and should be done in /// the implementation test. - pub fn generic_wot_test<T: WebOfTrust>(wot: &mut T, wot2: &mut T) { + pub fn generic_wot_test<T: WebOfTrust, F>(generator: F) + where + F: Fn(usize) -> T, + { + let mut wot = generator(3); + // should have an initial size of 0 assert_eq!(wot.size(), 0); @@ -764,6 +769,8 @@ mod tests { () ); + let mut wot2 = generator(3); + // Read wot from file { assert_eq!( diff --git a/wotb/rusty.rs b/wotb/rusty.rs index 1f8b2ae7f91c68cc9ebdd6c988178f4f3ebae85d..b7ae38b6e8cfe6afa64d0b60bff84bb76446e98c 100644 --- a/wotb/rusty.rs +++ b/wotb/rusty.rs @@ -316,8 +316,6 @@ mod tests { #[test] fn wot_tests() { - let mut wot1 = RustyWebOfTrust::new(3); - let mut wot2 = RustyWebOfTrust::new(3); - generic_wot_test(&mut wot1, &mut wot2); + generic_wot_test(RustyWebOfTrust::new); } }