Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomSet exercise allows creating new CustomSets with duplicated members #1275

Closed
mnquintana opened this issue Jun 5, 2021 · 2 comments
Closed

Comments

@mnquintana
Copy link
Contributor

mnquintana commented Jun 5, 2021

πŸ‘‹πŸ½ I came across an edge case that (I think) currently isn't being caught by the test cases for CustomSet – it's possible to write a CustomSet::new constructor that internally stores set members with duplicates, e.g.:

#[derive(Clone, Debug)]
pub struct CustomSet<T> {
    members: Vec<T>,
}

impl<T: Clone + PartialEq> CustomSet<T> {
    pub fn new(input: &[T]) -> Self {
        let members = input.to_vec();
        Self { members }
    }
}

On the one hand, I don't think the internal representation matters that much as long as the CustomSets methods account for duplicates.

But, after a cursory glance at the test cases, it looks like there aren't any test cases that instantiate a CustomSet from a slice with duplicate elements, which if I'm reading them right means a big chunk of a Set's functionality is currently untested (and the test suite passes solutions that don't actually dedupe members).

Example test case:

#[test]
fn intersection_of_two_sets_with_no_shared_elements_is_an_empty_set() {
    let set1 = CustomSet::new(&[1, 3, 2, 3, 3]);
    let set2 = CustomSet::new(&[4, 5, 6]);
    assert_eq!(set1.intersection(&set2), CustomSet::new(&[]));
    assert_eq!(set2.intersection(&set1), CustomSet::new(&[]));
}

Would y'all be open to a PR that adds test cases that test for CustomSet's deduping ability by passing in slices with duplicate elements?

@coriolinus
Copy link
Member

coriolinus commented Jun 5, 2021 via email

senekor added a commit to exercism/problem-specifications that referenced this issue Sep 16, 2023
senekor added a commit to exercism/problem-specifications that referenced this issue Sep 16, 2023
senekor added a commit to exercism/problem-specifications that referenced this issue Sep 16, 2023
@senekor
Copy link
Contributor

senekor commented Sep 16, 2023

should be fixed by exercism/problem-specifications#2324

@senekor senekor closed this as completed Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants