Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/containers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
rust_library(
name = "containers",
srcs = glob(["**/*.rs"]),
edition = "2024",
edition = "2021",
visibility = ["//visibility:public"],
)

Expand Down
2 changes: 1 addition & 1 deletion src/containers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name = "containers"
description = "Fixed-capacity and inline-storage containers"
version = "0.1.0"
authors = ["Contributors to the Eclipse Foundation"]
edition = "2024"
edition = "2021"
license-file = "../../LICENSE.md"

[lib]
Expand Down
43 changes: 43 additions & 0 deletions src/containers/fixed_capacity/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,49 @@ mod tests {
elements
}

#[test]
fn front_and_back() {
fn check_front_and_back(queue: &mut FixedCapacityQueue<i64>, control: &mut VecDeque<i64>) {
assert_eq!(queue.front(), control.front());
assert_eq!(queue.front_mut(), control.front_mut());
assert_eq!(queue.back(), control.back());
assert_eq!(queue.back_mut(), control.back_mut());
}

fn run_test(n: usize) {
let mut queue = FixedCapacityQueue::<i64>::new(n);
let mut control = VecDeque::new();

// Completely fill and empty the queue n times, but move the internal start point
// ahead by one each time
for _ in 0..n {
check_front_and_back(&mut queue, &mut control);

for i in 0..n {
let value = i as i64 * 123 + 456;
queue.push_back(value).unwrap();
control.push_back(value);
check_front_and_back(&mut queue, &mut control);
}

for _ in 0..n {
control.pop_front().unwrap();
queue.pop_front().unwrap();
check_front_and_back(&mut queue, &mut control);
}

// One push and one pop to move the internal start point ahead
queue.push_back(987).unwrap();
queue.pop_front().unwrap();
check_front_and_back(&mut queue, &mut control);
}
}

for i in 0..6 {
run_test(i);
}
}

#[test]
fn push_back_and_pop_front() {
fn run_test(n: usize) {
Expand Down
Loading
Loading