Skip to content

Improve documentation for subset_of() #685

@markozagar

Description

@markozagar

I was working through the examples in rust-advanced-testing-workshop/collections, and got stuck at this exercise:

#[googletest::gtest]
fn failed_subset_of() {
    let x = btreeset![1, 2, 3];
    let y = btreeset![3, 4];
    assert!(y.is_subset(&x));
    }

I gave it a solid 30 minutes of trying in various ways, but I couldn't figure out how to write this particular test. This is the closest I'd gotten:

assert_that!(y, subset_of(x.iter().collect::<std::collections::BTreeSet<&i32>>()));

I don't think this is a good way to do this, but I can't figure out how to massage x into an acceptable form.

It would be helpful if the examples in the docs for subset_of() showed usage from variables (of different collection types), rather than just arrays. The test module in subset_of.rs is similarly unhelpful. There isn't a large body of code using googletest-rust, so searching online also led nowhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions