Skip to content

Commit

Permalink
write test for split edge
Browse files Browse the repository at this point in the history
  • Loading branch information
BramDevlaminck committed Oct 28, 2023
1 parent 6c0711f commit 31de370
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum CursorIterator {
InWord,
}

#[derive(Debug, PartialEq)]
pub struct Cursor<'a> {
pub current_node_index_in_arena: usize,
pub index: usize,
Expand Down Expand Up @@ -171,4 +172,87 @@ impl<'a> Cursor<'a> {
self.index = current_advance;
}
}
}

#[cfg(test)]
mod tests {
use crate::cursor::Cursor;
use crate::tree::{MAX_CHILDREN, Node, NodeIndex, Nullable, Range, Tree};

#[test]
fn test_split_edge() {
let input = "ACAB$";

let mut tree = Tree {
arena: vec![
Node::new(
Range::new(0, 0),
NodeIndex::NULL,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
),
Node::new(
Range::new(0, 5),
0,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
),
Node::new(
Range::new(1, 5),
0,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
),
]
};

tree.arena[0].add_child(b'A', 1);
tree.arena[0].add_child(b'C', 2);

let mut control_tree = Tree {
arena: vec![
Node::new(
Range::new(0, 0),
NodeIndex::NULL,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
),
Node::new(
Range::new(1, 5),
3,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
),
Node::new(
Range::new(1, 5),
0,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
),
Node::new(
Range::new(0, 1),
0,
[NodeIndex::NULL; MAX_CHILDREN],
NodeIndex::NULL,
NodeIndex::NULL,
)
]
};

control_tree.arena[0].add_child(b'A', 3);
control_tree.arena[0].add_child(b'C', 2);
control_tree.arena[3].add_child(b'C', 1);

let mut cursor = Cursor {current_node_index_in_arena: 1, index : 1, tree: &mut tree};
cursor.split_edge(input.as_bytes());

assert_eq!(cursor, Cursor {current_node_index_in_arena: 3 , index: 1, tree: &mut control_tree})
}

}

0 comments on commit 31de370

Please sign in to comment.