| 329 | |
| 330 | #[test] |
| 331 | fn basic_push_pop() { |
| 332 | let (mut tx, mut rx) = RingBuffer::channel::<u64>(4); |
| 333 | |
| 334 | tx.try_push(1).unwrap(); |
| 335 | tx.try_push(2).unwrap(); |
| 336 | tx.try_push(3).unwrap(); |
| 337 | tx.try_push(4).unwrap(); |
| 338 | |
| 339 | // Buffer should be full (capacity rounds to 4). |
| 340 | assert!(matches!(tx.try_push(5), Err(BridgeError::Full { .. }))); |
| 341 | |
| 342 | assert_eq!(rx.try_pop().unwrap(), 1); |
| 343 | assert_eq!(rx.try_pop().unwrap(), 2); |
| 344 | |
| 345 | // Now there's room for more. |
| 346 | tx.try_push(5).unwrap(); |
| 347 | tx.try_push(6).unwrap(); |
| 348 | |
| 349 | assert_eq!(rx.try_pop().unwrap(), 3); |
| 350 | assert_eq!(rx.try_pop().unwrap(), 4); |
| 351 | assert_eq!(rx.try_pop().unwrap(), 5); |
| 352 | assert_eq!(rx.try_pop().unwrap(), 6); |
| 353 | |
| 354 | assert!(matches!(rx.try_pop(), Err(BridgeError::Empty))); |
| 355 | } |
| 356 | |
| 357 | #[test] |
| 358 | fn power_of_two_rounding() { |