diff --git a/Cargo.lock b/Cargo.lock index a71a918..d02c88f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,4 +1,4 @@ [root] -name = "rust-two-three" +name = "rust_two_three" version = "0.0.1" diff --git a/Cargo.toml b/Cargo.toml index 1bbe782..08e1793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust-two-three" +name = "rust_two_three" version = "0.0.1" authors = ["Corey Farwell "] diff --git a/src/lib.rs b/src/lib.rs index e25da36..cbf4698 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,7 @@ enum Direction { } /// Node -enum Node { +pub enum Node { LeafTwoNode(V), LeafThreeNode(V, V), TwoNode(V, Box>, Box>), @@ -207,7 +207,7 @@ impl Node { /// TTTree pub struct TTTree { - root: Option>, + pub root: Option>, } impl ToString for TTTree { @@ -241,106 +241,7 @@ impl TTTree { } - // TODO: // Collection trait // convert this to Key/Value K/V // remove ToString debugging stuffs - - -#[test] -fn it_works() { - let mut tree: TTTree = TTTree::new(); - - tree.insert(50); - match tree { - TTTree{root: Some(LeafTwoNode(50))} => (), - _ => fail!(), - } - - tree.insert(50); - match tree { - TTTree{root: Some(LeafTwoNode(50))} => (), - _ => fail!(), - } - - tree.insert(60); - match tree { - TTTree{root: Some(LeafThreeNode(50, 60))} => (), - _ => fail!(), - } - - tree.insert(70); - match tree { - TTTree{root: Some( - TwoNode(60, - box LeafTwoNode(50), - box LeafTwoNode(70) - ) - )} => (), - _ => fail!(), - } - - tree.insert(100); - match tree { - TTTree{root: Some( - TwoNode(60, - box LeafTwoNode(50), - box LeafThreeNode(70, 100) - ) - )} => (), - _ => fail!(), - } - - tree.insert(55); - match tree { - TTTree{root: Some( - TwoNode(60, - box LeafThreeNode(50, 55), - box LeafThreeNode(70, 100) - ) - )} => (), - _ => fail!(), - } - - tree.insert(68); - match tree { - TTTree{root: Some( - ThreeNode(60, 70, - box LeafThreeNode(50, 55), - box LeafTwoNode(68), - box LeafTwoNode(100) - ) - )} => (), - _ => fail!(), - } - - tree.insert(75); - match tree { - TTTree{root: Some( - ThreeNode(60, 70, - box LeafThreeNode(50, 55), - box LeafTwoNode(68), - box LeafThreeNode(75, 100) - ) - )} => (), - _ => fail!(), - } - - tree.insert(52); - match tree { - TTTree{root: Some( - TwoNode(60, - box TwoNode(52, - box LeafTwoNode(50), - box LeafTwoNode(55), - ), - box TwoNode(70, - box LeafTwoNode(68), - box LeafThreeNode(75, 100), - ), - ) - )} => (), - _ => fail!(), - } -} diff --git a/tests/test_tree.rs b/tests/test_tree.rs new file mode 100644 index 0000000..8c29d79 --- /dev/null +++ b/tests/test_tree.rs @@ -0,0 +1,101 @@ +extern crate rust_two_three; + +use rust_two_three::{ThreeNode, LeafThreeNode, TwoNode, LeafTwoNode, TTTree}; + + +#[test] +fn it_works() { + let mut tree: TTTree = TTTree::new(); + + tree.insert(50); + match tree { + TTTree{root: Some(LeafTwoNode(50))} => (), + _ => fail!(), + } + + tree.insert(50); + match tree { + TTTree{root: Some(LeafTwoNode(50))} => (), + _ => fail!(), + } + + tree.insert(60); + match tree { + TTTree{root: Some(LeafThreeNode(50, 60))} => (), + _ => fail!(), + } + + tree.insert(70); + match tree { + TTTree{root: Some( + TwoNode(60, + box LeafTwoNode(50), + box LeafTwoNode(70) + ) + )} => (), + _ => fail!(), + } + + tree.insert(100); + match tree { + TTTree{root: Some( + TwoNode(60, + box LeafTwoNode(50), + box LeafThreeNode(70, 100) + ) + )} => (), + _ => fail!(), + } + + tree.insert(55); + match tree { + TTTree{root: Some( + TwoNode(60, + box LeafThreeNode(50, 55), + box LeafThreeNode(70, 100) + ) + )} => (), + _ => fail!(), + } + + tree.insert(68); + match tree { + TTTree{root: Some( + ThreeNode(60, 70, + box LeafThreeNode(50, 55), + box LeafTwoNode(68), + box LeafTwoNode(100) + ) + )} => (), + _ => fail!(), + } + + tree.insert(75); + match tree { + TTTree{root: Some( + ThreeNode(60, 70, + box LeafThreeNode(50, 55), + box LeafTwoNode(68), + box LeafThreeNode(75, 100) + ) + )} => (), + _ => fail!(), + } + + tree.insert(52); + match tree { + TTTree{root: Some( + TwoNode(60, + box TwoNode(52, + box LeafTwoNode(50), + box LeafTwoNode(55), + ), + box TwoNode(70, + box LeafTwoNode(68), + box LeafThreeNode(75, 100), + ), + ) + )} => (), + _ => fail!(), + } +}