Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Last active January 22, 2020 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makoConstruct/414e3706d478b9856a7d3319f5aed35e to your computer and use it in GitHub Desktop.
Save makoConstruct/414e3706d478b9856a7d3319f5aed35e to your computer and use it in GitHub Desktop.
tests whether a graph rank aggregation (referred to as "rank") satisfies some necessary features of large collaborative curation processes
#[cfg(test)]
mod fauns_criteria {
use super::*;
fn mapping(results: Vec<(f32, str&)>)-> HashMap<String, f32> {
results.into_iter().map(|(score, name)| (name.into(), score)).collect()
}
fn equalish(a:f32, b:f32)-> bool {
abs(a - b) < 0.00001
}
/*
a b
b c
c a
a == b
b == c
a b
c b
d a
d c
d < a
a == c
c < b
a b
b c
c a
c a
c < b
b < a
a b
b c
b c
c a
c a
b < c
c < a
b a
b c
d a
d c
a c
b == d
d < a
a < c
a b
b c
c e1
c e2
c e3
c e4
a < b
b < c
c < e1
c < e2
c < e3
c < e4
*/
#[test]
fn test_short() {
let r = mapping(rank(vec!(
("a", "b"),
("b", "c"),
)));
assert!(r["a"] < r["b"]);
assert!(r["b"] < r["c"]);
}
#[test]
fn square() {
let r = mapping(rank(vec!(
("a", "b"),
("c", "b"),
("d", "a"),
("d", "c"),
)));
assert!(r["d"] < r["a"]);
assert!(equalish(r["a"], r["c"]));
assert!(r["c"] < r["b"]);
}
#[test]
fn cycle() {
let r = mapping(rank(vec!(
("a", "b"),
("b", "c"),
("c", "a"),
)));
assert!(equalish(r["a"], r["b"]));
assert!(equalish(r["b"], r["c"]));
}
#[test]
fn one_din_cycle() {
let r = mapping(rank(vec!(
("a", "b"),
("b", "c"),
("c", "a"),
("c", "a"),
)));
assert!(r["c"] < r["b"]);
assert!(r["b"] < r["a"]);
}
#[test]
fn two_din_cycle() {
let r = mapping(rank(vec!(
("a", "b"),
("b", "c"),
("b", "c"),
("c", "a"),
("c", "a"),
)));
assert!(r["b"] < r["c"]);
assert!(r["c"] < r["a"]);
}
#[test]
fn crossed_square() {
let r = mapping(rank(vec!(
("b", "a"),
("b", "c"),
("d", "a"),
("d", "c"),
("a", "c"),
)));
assert!(equalish(r["b"], r["d"]));
assert!(r["d"] < r["a"]);
assert!(r["a"] < r["c"]);
}
#[test]
fn divergence_threat() {
let r = mapping(rank(vec!(
("a", "b"),
("b", "c"),
("c", "e1"),
("c", "e2"),
("c", "e3"),
("c", "e4"),
)));
assert!(r["a"] < r["b"]);
assert!(r["b"] < r["c"]);
assert!(r["c"] < r["e1"]);
assert!(r["c"] < r["e2"]);
assert!(r["c"] < r["e3"]);
assert!(r["c"] < r["e4"]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment