Commit 8a2c6c6c authored by tgerstel's avatar tgerstel
Browse files

halfway testing

parent d6669f88
......@@ -172,7 +172,7 @@ impl<V> Pool<Node<V>> {
self[u].d_depth = 0;
}
pub fn first_ancestor(&mut self, u: Label<Node<V>>, v: Label<Node<V>>) -> Label<Node<V>> {
/* pub fn first_ancestor(&mut self, u: Label<Node<V>>, v: Label<Node<V>>) -> Label<Node<V>> {
self.expose(u);
self.expose(v);
......@@ -186,7 +186,7 @@ impl<V> Pool<Node<V>> {
Parent::Path(y) => y,
Parent::Root => v,
}
}
} */
pub fn depth(&self, u: Label<Node<V>>) -> usize {
let mut label = u;
......@@ -215,8 +215,9 @@ impl<V> Pool<Node<V>> {
}
}
pub fn index_depth(&mut self, u: Label<Node<V>>, i: usize) -> Label<Node<V>> {
self.expose(u);
// always expose before indexing
pub fn index_depth(&self, u: Label<Node<V>>, i: usize) -> Label<Node<V>> {
assert!(i <= self.depth(u));
let mut label = u;
let mut flip = self[u].d_flip;
let mut depth = self[u].d_depth;
......@@ -229,9 +230,9 @@ impl<V> Pool<Node<V>> {
label = self[label].children[ChildType::from(side)].unwrap();
if flip ^ side {
depth -= self[label].d_depth;
} else {
depth += self[label].d_depth;
} else {
depth -= self[label].d_depth;
}
flip ^= self[label].d_flip;
}
......@@ -650,7 +651,7 @@ mod tests {
#[test]
fn random_scan() {
// generate a basic lct
let size = 10;
let size = 3;
let mut lct = Pool::with_capacity(size);
for i in 0..size {
let _ = lct.add_node(i);
......@@ -663,28 +664,36 @@ mod tests {
// randomly mutate lct and check integrity
for _ in 0..(size * size * size) {
if fastrand::bool() {
let label = Label::from(fastrand::usize(0..size));
lct.evert(label);
for i in 0..size {
let u = Label::from(i);
assert_eq!(lct.find_root(u), label);
}
} else {
let label1 = Label::from(fastrand::usize(0..size));
let label2 = Label::from(fastrand::usize(0..size));
if label1 != label2 {
let root = lct.first_ancestor(label1, label2);
lct.evert(root);
let depth1 = lct.depth(label1);
let depth2 = lct.depth(label2);
//todo
}
let label1 = Label::from(fastrand::usize(0..size));
let label2 = Label::from(fastrand::usize(0..size));
if label1 != label2 {
dbg!(&lct);
lct.evert(label1);
dbg!(&lct);
lct.expose(label2);
dbg!(&lct);
dbg!(label1);
dbg!(label2);
let depth = lct.depth(label2);
assert_depth(&lct, label2);
let index = fastrand::usize(0..depth);
let cut = lct.index_depth(label2, index + 1);
lct.cut(cut);
lct.evert(label2);
lct.link(label1, label2);
}
assert_clean(&lct);
}
}
fn assert_depth<V: fmt::Debug>(lct: &Pool<Node<V>>, label: Label<Node<V>>) {
let max_depth = lct.depth(label);
for depth in 0..max_depth {
let x = lct.index_depth(label, depth);
assert_eq!(lct.depth(x), depth);
}
}
fn assert_clean<V>(lct: &Pool<Node<V>>) {
for label in lct.labels() {
// check parent reciprocrity
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment