Fixed spacing
This commit is contained in:
parent
6518ed8a4d
commit
a8f20af75d
236
src/test.rs
236
src/test.rs
|
|
@ -1,128 +1,128 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use assert_approx_eq::assert_approx_eq;
|
use assert_approx_eq::assert_approx_eq;
|
||||||
|
|
||||||
fn simple_symmetric_tree() -> Tree<String, f64> {
|
fn simple_symmetric_tree() -> Tree<String, f64> {
|
||||||
let a = Alternative {
|
let a = Alternative {
|
||||||
name: "A".to_owned()
|
name: "A".to_owned()
|
||||||
};
|
};
|
||||||
let b = Alternative {
|
let b = Alternative {
|
||||||
name: "B".to_owned()
|
name: "B".to_owned()
|
||||||
};
|
};
|
||||||
let edge_a = Edge {
|
let edge_a = Edge {
|
||||||
weight: 1.0,
|
weight: 1.0,
|
||||||
destination: Tree {root: Vertex::Terminal(a)}
|
destination: Tree {root: Vertex::Terminal(a)}
|
||||||
};
|
};
|
||||||
let edge_b = Edge {
|
let edge_b = Edge {
|
||||||
weight: 1.0,
|
weight: 1.0,
|
||||||
destination: Tree {root: Vertex::Terminal(b)}
|
destination: Tree {root: Vertex::Terminal(b)}
|
||||||
};
|
};
|
||||||
let root = Vertex::NonTerminal(Box::new(edge_a), Box::new(edge_b));
|
let root = Vertex::NonTerminal(Box::new(edge_a), Box::new(edge_b));
|
||||||
Tree {root: root}
|
Tree {root: root}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn simple_asymmetric_tree() -> Tree<String, f64> {
|
fn simple_asymmetric_tree() -> Tree<String, f64> {
|
||||||
let a = Alternative {
|
let a = Alternative {
|
||||||
name: "A".to_owned()
|
name: "A".to_owned()
|
||||||
};
|
};
|
||||||
let b = Alternative {
|
let b = Alternative {
|
||||||
name: "B".to_owned()
|
name: "B".to_owned()
|
||||||
};
|
};
|
||||||
let edge_a = Edge {
|
let edge_a = Edge {
|
||||||
weight: 3.0,
|
weight: 3.0,
|
||||||
destination: Tree {root: Vertex::Terminal(a)}
|
destination: Tree {root: Vertex::Terminal(a)}
|
||||||
};
|
};
|
||||||
let edge_b = Edge {
|
let edge_b = Edge {
|
||||||
weight: 1.0,
|
weight: 1.0,
|
||||||
destination: Tree {root: Vertex::Terminal(b)}
|
destination: Tree {root: Vertex::Terminal(b)}
|
||||||
};
|
};
|
||||||
let root = Vertex::NonTerminal(Box::new(edge_a), Box::new(edge_b));
|
let root = Vertex::NonTerminal(Box::new(edge_a), Box::new(edge_b));
|
||||||
Tree {root: root}
|
Tree {root: root}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complex_tree() -> Tree<String, f64> {
|
fn complex_tree() -> Tree<String, f64> {
|
||||||
let a = Alternative {
|
let a = Alternative {
|
||||||
name: "A".to_owned()
|
name: "A".to_owned()
|
||||||
};
|
};
|
||||||
let b = Alternative {
|
let b = Alternative {
|
||||||
name: "B".to_owned()
|
name: "B".to_owned()
|
||||||
};
|
};
|
||||||
let c = Alternative {
|
let c = Alternative {
|
||||||
name: "C".to_owned()
|
name: "C".to_owned()
|
||||||
};
|
};
|
||||||
let edge_a = Edge {
|
let edge_a = Edge {
|
||||||
weight: 2.5,
|
weight: 2.5,
|
||||||
destination: Tree {root: Vertex::Terminal(a)}
|
destination: Tree {root: Vertex::Terminal(a)}
|
||||||
};
|
};
|
||||||
let edge_b = Edge {
|
let edge_b = Edge {
|
||||||
weight: 1.0,
|
weight: 1.0,
|
||||||
destination: Tree {root: Vertex::Terminal(b)}
|
destination: Tree {root: Vertex::Terminal(b)}
|
||||||
};
|
};
|
||||||
let edge_ab = Edge{
|
let edge_ab = Edge{
|
||||||
weight: 0.5,
|
weight: 0.5,
|
||||||
destination: Tree {
|
destination: Tree {
|
||||||
root: Vertex::NonTerminal(Box::new(edge_a), Box::new(edge_b))
|
root: Vertex::NonTerminal(Box::new(edge_a), Box::new(edge_b))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let edge_c = Edge{
|
let edge_c = Edge{
|
||||||
weight: 1.0,
|
weight: 1.0,
|
||||||
destination: Tree {root: Vertex::Terminal(c)}
|
destination: Tree {root: Vertex::Terminal(c)}
|
||||||
};
|
};
|
||||||
let root = Vertex::NonTerminal(Box::new(edge_ab), Box::new(edge_c));
|
let root = Vertex::NonTerminal(Box::new(edge_ab), Box::new(edge_c));
|
||||||
Tree {root: root}
|
Tree {root: root}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// A test for the simplest symmetric case
|
// A test for the simplest symmetric case
|
||||||
#[test]
|
#[test]
|
||||||
fn choice_probability_test_1() {
|
fn choice_probability_test_1() {
|
||||||
assert_eq!(simple_symmetric_tree().choice_probability(&("A".to_owned())), 0.5);
|
assert_eq!(simple_symmetric_tree().choice_probability(&("A".to_owned())), 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A test for the simplest asymmetric case
|
// A test for the simplest asymmetric case
|
||||||
#[test]
|
#[test]
|
||||||
fn choice_probability_test_2() {
|
fn choice_probability_test_2() {
|
||||||
assert_eq!(simple_asymmetric_tree().choice_probability(&("A".to_owned())), 0.75);
|
assert_eq!(simple_asymmetric_tree().choice_probability(&("A".to_owned())), 0.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A test for depth higher than 1
|
// A test for depth higher than 1
|
||||||
#[test]
|
#[test]
|
||||||
fn choice_probability_test_3() {
|
fn choice_probability_test_3() {
|
||||||
assert_approx_eq!(
|
assert_approx_eq!(
|
||||||
complex_tree().choice_probability(&("A".to_owned())),
|
complex_tree().choice_probability(&("A".to_owned())),
|
||||||
(2.5/(2.5+1.0))*((2.5+1.0+0.5)/(2.5+1.0+0.5+1.0))
|
(2.5/(2.5+1.0))*((2.5+1.0+0.5)/(2.5+1.0+0.5+1.0))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A test for parsing the simplest symmetric case
|
// A test for parsing the simplest symmetric case
|
||||||
#[test]
|
#[test]
|
||||||
fn parser_test_1() {
|
fn parser_test_1() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
{
|
{
|
||||||
let (_, b) = parser::subtree("([1.0]A[1.0]B)").unwrap();
|
let (_, b) = parser::subtree("([1.0]A[1.0]B)").unwrap();
|
||||||
b
|
b
|
||||||
},
|
},
|
||||||
simple_symmetric_tree()
|
simple_symmetric_tree()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parser_test_2() {
|
fn parser_test_2() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
{
|
{
|
||||||
let (_, b) = parser::subtree("([3.0]A[1.0]B)").unwrap();
|
let (_, b) = parser::subtree("([3.0]A[1.0]B)").unwrap();
|
||||||
b
|
b
|
||||||
},
|
},
|
||||||
simple_asymmetric_tree()
|
simple_asymmetric_tree()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parser_test_3() {
|
fn parser_test_3() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
{
|
{
|
||||||
let (_, b) = parser::subtree("([0.5]([2.5]A[1.0]B)[1.0]C)").unwrap();
|
let (_, b) = parser::subtree("([0.5]([2.5]A[1.0]B)[1.0]C)").unwrap();
|
||||||
b
|
b
|
||||||
},
|
},
|
||||||
complex_tree()
|
complex_tree()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue