Skip to content
Snippets Groups Projects
Commit 91bffb5c authored by frederik stehli's avatar frederik stehli
Browse files

[min_max] fixed new operator and added tests

parent d87f1688
Branches
No related tags found
No related merge requests found
...@@ -94,7 +94,7 @@ impl MinMax { ...@@ -94,7 +94,7 @@ impl MinMax {
} }
} }
} }
if (bit_index + 1) % block_size == 0 { if (bit_index + 1) % block_size == 0 || bit_index + 1 == bits_len {
//check if it is the end of a block //check if it is the end of a block
//save values as Node in a heap //save values as Node in a heap
heap[heap_index].set_values(&excess, &min_excess, &number_min_excess, &max_excess); heap[heap_index].set_values(&excess, &min_excess, &number_min_excess, &max_excess);
...@@ -582,6 +582,31 @@ mod tests { ...@@ -582,6 +582,31 @@ mod tests {
assert_eq!(min_max.heap[0].max_excess, 3); assert_eq!(min_max.heap[0].max_excess, 3);
} }
#[test]
fn test_min_max_construction2() {
let bits = bit_vec![
true, true, true, false, true, false, true, true, false, false, false, true, false,
true, true, true, false, true, false, false, false, false
];
let min_max = MinMax::new(bits, 4);
assert_eq!(min_max.heap[0].excess, 0);
assert_eq!(min_max.heap[1].excess, 4);
assert_eq!(min_max.heap[2].excess, -4);
assert_eq!(min_max.heap[3].excess, 4);
assert_eq!(min_max.heap[4].excess, 0);
assert_eq!(min_max.heap[5].excess, -4);
assert_eq!(min_max.heap[6].excess, 0);
//
assert_eq!(min_max.heap[7].excess, 2);
assert_eq!(min_max.heap[8].excess, 2);
assert_eq!(min_max.heap[9].excess, -2);
assert_eq!(min_max.heap[10].excess, 2);
assert_eq!(min_max.heap[11].excess, -2);
assert_eq!(min_max.heap[12].excess, -2);
assert_eq!(min_max.heap[13].excess, 0);
assert_eq!(min_max.heap[14].excess, 0);
}
#[test] #[test]
fn test_min_max() { fn test_min_max() {
let bits = bit_vec![ let bits = bit_vec![
...@@ -624,7 +649,6 @@ mod tests { ...@@ -624,7 +649,6 @@ mod tests {
} }
#[test] #[test]
#[ignore]
fn test_bwd_search() { fn test_bwd_search() {
let bits = let bits =
bit_vec![true, true, true, false, true, false, false, true, true, false, false, false]; bit_vec![true, true, true, false, true, false, false, true, true, false, false, false];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment