mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-09-28 04:50:34 +00:00
Perform same len fix for iterators
This commit is contained in:
parent
0172082262
commit
84ce6ec159
@ -207,7 +207,7 @@ where
|
||||
let tail = self.tail.load_relaxed().into();
|
||||
|
||||
if head > tail {
|
||||
head - tail
|
||||
self.capacity().into() + 1 - head + tail
|
||||
} else {
|
||||
tail - head
|
||||
}
|
||||
|
@ -172,3 +172,21 @@ fn len_properly_wraps() {
|
||||
rb.enqueue(4).unwrap();
|
||||
assert_eq!(rb.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iterator_properly_wraps() {
|
||||
type N = U3;
|
||||
let mut rb: RingBuffer<u8, N> = RingBuffer::new();
|
||||
|
||||
rb.enqueue(1).unwrap();
|
||||
rb.dequeue();
|
||||
rb.enqueue(2).unwrap();
|
||||
rb.enqueue(3).unwrap();
|
||||
rb.enqueue(4).unwrap();
|
||||
let expected = [2, 3, 4];
|
||||
let mut actual = [0, 0, 0];
|
||||
for (idx, el) in rb.iter().enumerate() {
|
||||
actual[idx] = *el;
|
||||
}
|
||||
assert_eq!(expected, actual)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user