Skip to content
Snippets Groups Projects
Unverified Commit 9769fabb authored by Daniel Rose's avatar Daniel Rose
Browse files

[MinMax] excess: add error handling for invalid index value

parent de7a47c1
No related branches found
No related tags found
No related merge requests found
...@@ -204,6 +204,9 @@ impl MinMax { ...@@ -204,6 +204,9 @@ impl MinMax {
} }
pub fn excess(&self, index: u64) -> Result<u64, NodeError> { pub fn excess(&self, index: u64) -> Result<u64, NodeError> {
if index >= self.bits.len() {
return Err(NodeError::NotANodeError);
}
let block_number = (index / self.block_size); let block_number = (index / self.block_size);
let position_in_block = index % self.block_size; let position_in_block = index % self.block_size;
let mut pre_excess: i64 = 0; let mut pre_excess: i64 = 0;
...@@ -665,7 +668,6 @@ mod tests { ...@@ -665,7 +668,6 @@ mod tests {
let min_max = MinMax::new(bits, 4); let min_max = MinMax::new(bits, 4);
assert_eq!(min_max.excess(21).unwrap(), 0); assert_eq!(min_max.excess(21).unwrap(), 0);
assert_eq!(min_max.excess(7).unwrap(), 4); assert_eq!(min_max.excess(7).unwrap(), 4);
// TODO: Werden schon ungültige index-werte zurückgewiesen?
} }
#[test] #[test]
...@@ -674,6 +676,7 @@ mod tests { ...@@ -674,6 +676,7 @@ mod tests {
let min_max = MinMax::new(bits, 2); let min_max = MinMax::new(bits, 2);
assert_eq!(min_max.excess(0).unwrap(), 1); assert_eq!(min_max.excess(0).unwrap(), 1);
assert_eq!(min_max.excess(1).unwrap(), 0); assert_eq!(min_max.excess(1).unwrap(), 0);
assert_eq!(min_max.excess(2).unwrap_err(), NodeError::NotANodeError);
} }
#[test] #[test]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment