Skip to content
Snippets Groups Projects
Commit 9d64657f authored by nanocryk's avatar nanocryk
Browse files

[enh] replace mut ref wots by a generator closure

parent 41cbf9db
Branches
Tags
1 merge request!26Resolve "Improve WoT generic test by providing a generator function instead of multiple `&mut T: WebOfTrust`"
...@@ -107,7 +107,7 @@ dependencies = [ ...@@ -107,7 +107,7 @@ dependencies = [
[[package]] [[package]]
name = "duniter-wotb" name = "duniter-wotb"
version = "0.6.1" version = "0.6.2"
dependencies = [ dependencies = [
"bincode 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package] [package]
name = "duniter-wotb" name = "duniter-wotb"
version = "0.6.1" version = "0.6.2"
authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@duniter.org>"] authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@duniter.org>"]
description = "Makes Web of Trust computations for the Duniter project." description = "Makes Web of Trust computations for the Duniter project."
repository = "https://git.duniter.org/nodes/rust/duniter-rs" repository = "https://git.duniter.org/nodes/rust/duniter-rs"
......
...@@ -553,33 +553,6 @@ mod tests { ...@@ -553,33 +553,6 @@ mod tests {
/// This test is a translation of https://github.com/duniter/wotb/blob/master/tests/test.js /// This test is a translation of https://github.com/duniter/wotb/blob/master/tests/test.js
#[test] #[test]
fn wot_tests() { fn wot_tests() {
let mut wot = LegacyWebOfTrust::new(3); generic_wot_test(LegacyWebOfTrust::new);
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()
);
}
} }
} }
...@@ -387,7 +387,12 @@ mod tests { ...@@ -387,7 +387,12 @@ mod tests {
/// ///
/// Clone and file tests are not included in this generic test and should be done in /// Clone and file tests are not included in this generic test and should be done in
/// the implementation test. /// 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 // should have an initial size of 0
assert_eq!(wot.size(), 0); assert_eq!(wot.size(), 0);
...@@ -764,6 +769,8 @@ mod tests { ...@@ -764,6 +769,8 @@ mod tests {
() ()
); );
let mut wot2 = generator(3);
// Read wot from file // Read wot from file
{ {
assert_eq!( assert_eq!(
......
...@@ -316,8 +316,6 @@ mod tests { ...@@ -316,8 +316,6 @@ mod tests {
#[test] #[test]
fn wot_tests() { fn wot_tests() {
let mut wot1 = RustyWebOfTrust::new(3); generic_wot_test(RustyWebOfTrust::new);
let mut wot2 = RustyWebOfTrust::new(3);
generic_wot_test(&mut wot1, &mut wot2);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment