Skip to content

Commit

Permalink
remove tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed May 31, 2024
1 parent 4ab502a commit ee9eed7
Showing 1 changed file with 0 additions and 142 deletions.
142 changes: 0 additions & 142 deletions src/utils/buffers/histogram_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,145 +223,3 @@ impl IndexMut<usize> for HistogramBuffer {
&mut self.data[index]
}
}

#[cfg(test)]
mod tests {
use super::HistogramBuffer;

#[test]
fn basics() {
let mut rb = HistogramBuffer::<i32>::new(4);

// Is the buffer filled with zeroes?
assert_eq!(rb.data, vec![0; 4]);

rb.enqueue(1);
rb.enqueue(2);
rb.enqueue(3);

// Is the value at the tail (before the head) equal to 3?
assert_eq!(rb.data[(rb.head + rb.size - 1) % rb.size], 3);

// Is the value at the head equal to 0?
assert_eq!(rb.data[rb.head], 0);

rb.enqueue(4);
rb.enqueue(5);
rb.enqueue(6);

// Have the earlier values been overwritten?
assert!(!rb.data.contains(&1));
assert!(!rb.data.contains(&2));

// Do the last 4 values exist?
assert!(rb.data.contains(&3));
assert!(rb.data.contains(&4));
assert!(rb.data.contains(&5));
assert!(rb.data.contains(&6));
}

#[test]
fn clear() {
let mut rb = HistogramBuffer::<i32>::new(4);

rb.enqueue(1);
rb.enqueue(2);
rb.enqueue(3);

assert_ne!(rb.data, vec![0; 4]);

rb.clear();

assert_eq!(rb.data, vec![0; 4]);
}

#[test]
fn resize() {
let mut rb = HistogramBuffer::<i32>::new(4);
rb.enqueue(1);
rb.enqueue(2);
rb.enqueue(3);
rb.enqueue(4);
rb.enqueue(5);
rb.enqueue(6);

// Growing HistogramBuffers
{
let mut rb_grown = rb.clone();
rb_grown.grow(6);
let mut rb_resized = rb.clone();
rb_resized.resize(6);
// Is the last inserted datum the same?
assert_eq!(
rb_grown.data[(rb_grown.head + rb_grown.size - 1) % rb_grown.size],
rb_resized.data[(rb_resized.head + rb_resized.size - 1) % rb_resized.size]
);
// Is the buffer zero-padded?
assert_eq!(rb_grown.data[rb_grown.head], 0);
}

// Shrinking HistogramBuffers
{
let mut rb_shrunk = rb.clone();
rb_shrunk.shrink(3);
let mut rb_resized = rb.clone();
rb_resized.resize(3);
// Is the last inserted datum the same?
assert_eq!(
rb_shrunk.data[(rb_shrunk.head + rb_shrunk.size - 1) % rb_shrunk.size],
rb_resized.data[(rb_resized.head + rb_resized.size - 1) % rb_resized.size]
);
}
}

#[test]
fn indexing() {
let mut rb = HistogramBuffer::<i32>::new(4);

rb.enqueue(1);
rb.enqueue(2);
rb.enqueue(3);

// Is the last value still equal to 0?
assert_eq!(rb[0], 0);

// Were the first bunch of values inserted correctly?
assert_eq!(rb[1], 1);
assert_eq!(rb[2], 2);
assert_eq!(rb[3], 3);

rb[1] *= 2;
rb[2] *= 3;
rb[3] *= 4;

// Were the values multiplied correctly?
assert_eq!(rb[1], 2);
assert_eq!(rb[2], 6);
assert_eq!(rb[3], 12);

rb.enqueue(4);
rb.enqueue(5);

// Have the newer values "pushed back" the older ones?
assert_eq!(rb[0], 6);
assert_eq!(rb[1], 12);
assert_eq!(rb[2], 4);
assert_eq!(rb[3], 5);

// Can we set an element of the buffer?
rb[2] = 10;
assert_eq!(rb[2], 10);
}

#[test]
#[should_panic]
fn invalid_access() {
let mut rb = HistogramBuffer::<i32>::new(4);

rb.enqueue(1);
rb.enqueue(2);
rb.enqueue(3);

rb[4];
}
}

0 comments on commit ee9eed7

Please sign in to comment.