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

International Calling Connoisseur - Tests should check for correct handling of duplicate Add(). #1845

Open
purringk opened this issue Dec 1, 2021 · 1 comment

Comments

@purringk
Copy link

purringk commented Dec 1, 2021

Add() throws if the key is already in the dictionary. I saw a bunch of passing solutions that don't check for the key before calling Add().

In general, there's lots of ways for dictionaries to throw exceptions when you do naive-but-seemingly-reasonable things, and the "Intro-to-Dictionaries" text might want to call out the common ways to go wrong.

Example test:

var countryCodes = DialingCodes.AddCountryToExistingDictionary(DialingCodes.GetExistingDictionary(), 91, "India");
Assert.Equal("India", countryCodes[91]);

@ErikSchierboom
Copy link
Member

I appreciate the suggestion. While you are correct in noting that Add would throw, having the tests verify this would mean that students would have to know about exceptions, which they'll only learn later on as that requires a fair bit more knowledge. As an alternative, I'd be happy to have this mentioned in the concepts about.md document. Would you be willing to submit a PR?

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

2 participants