Skip to content

Wrapping and Saturating have the same behavior? #32

@Takashiidobe

Description

@Takashiidobe

I found some oddness in terms of saturating and wrapping:

This test fails, because the vecs are the same ([1,2,3]). I assume saturating means the ArrayDeque should be [1,2,3], and wrapping means it evicts old items, so I assume this should be [4,5,3] (since it fills up to [1,2,3], then evicts [1,2] to make room for [4,5]). If Wrapping and Saturating give the same behavior, is there a reason to have a different types?

#[test]
fn test_bug2_extend_trait_wrapping() {
    let mut wrapping: ArrayDeque<i32, 3, Wrapping> = ArrayDeque::new();
    wrapping.push_back(1);

    wrapping.extend([2, 3, 4, 5]);

    let mut saturating: ArrayDeque<i32, 3, Saturating> = ArrayDeque::new();
    saturating.push_back(1).unwrap();

    saturating.extend([2, 3, 4, 5]);

    let sat_vec: Vec<_> = saturating.iter().collect();
    let wrap_vec: Vec<_> = wrapping.iter().collect();

    assert_ne!(
        sat_vec, wrap_vec,
        "wrapping and saturating should be different, got: {:?}, {:?}",
        sat_vec, wrap_vec
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions