From 9d64657fc25682eb6bc84b4d0358d81315d8a6fd Mon Sep 17 00:00:00 2001
From: nanocryk <nanocryk@ifee.fr>
Date: Mon, 5 Mar 2018 11:28:53 +0100
Subject: [PATCH] [enh] replace mut ref wots by a generator closure
---
Cargo.lock | 2 +-
wotb/Cargo.toml | 2 +-
wotb/legacy.rs | 29 +----------------------------
wotb/lib.rs | 9 ++++++++-
wotb/rusty.rs | 4 +---
5 files changed, 12 insertions(+), 34 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 912b462a..ce52b969 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 eb0f10ad..213c02a8 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 3cdd3e1b..f70da9e4 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 b9582366..b0f9af3d 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 1f8b2ae7..b7ae38b6 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);
}
}
--
GitLab