Browse Source

Test set_loop_len

This checks if the loop length is mapped into the
[minimal-loop-length:buffer-size] range and how setting the loop-length
effects the loop end position that is calculated on a length change,
e.g. for wrap-around cases where the loop start position, which is the
read pos (pointer), is less elements away from the end of the buffer
than the length of the loop. Consider this example:

[0,1,2,…,10,11,12,13,14,15]
     ^    ^r_pos
     |loop_end

- buffer b has length 16
- read position is 10
- loop length is set to 8
→ loop end should be set to 2 now (the end is 'exclusive')
implement-loop-buffer
Andreas Linz 2 years ago
parent
commit
a552e5b1d4
Signed by: alinz GPG Key ID: 9BF39809C9DA580C
1 changed files with 27 additions and 0 deletions
  1. +27
    -0
      src/loop_buf.rs

+ 27
- 0
src/loop_buf.rs View File

@ -132,6 +132,33 @@ mod tests {
}
}
#[test]
fn test_set_loop_len() {
let size = 1 << 4;
let mut buf = LoopBuf::new(size);
// read-position, loop-length, expected-loop-length, loop-end
let table = vec![
(0, 8, 8, 8),
(
size - MIN_BUFFER_SIZE - 1,
MIN_BUFFER_SIZE,
MIN_BUFFER_SIZE,
size - 1,
),
(size - 1, 8, 8, 7),
(8, size, size, 8),
(0, 1, MIN_BUFFER_SIZE, MIN_BUFFER_SIZE),
(0, size * 2, size, 0),
];
for (r_pos, loop_len, expected_loop_len, loop_end) in table {
buf.r_pos = r_pos;
buf.set_loop_len(loop_len);
assert_eq!(buf.loop_len(), expected_loop_len);
assert_eq!(buf.loop_end, loop_end);
}
}
#[test]
fn test_read_loop() {
let size = 1 << 4;

Loading…
Cancel
Save