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

Added tests for null key handling in DictionaryExtensions #498

Conversation

gmottajr
Copy link
Contributor

@gmottajr gmottajr commented Nov 26, 2024

This pull request introduces the following changes to the DictionaryExtensions tests:

Test for Null Key Handling: Although an attempt was made to test how the AddMany method handles null keys when the key type is nullable (string?), it was not possible to implement this test. C# dictionaries do not allow null as a key, even for nullable key types like string?, because of the notnull constraint on the TKey parameter in the Dictionary class. The notnull constraint prevents nullable types like string? from being used as dictionary keys, and as a result, this test could not be completed due to the C# language limitation.
Test for Nullable Value Types: Included tests to verify that nullable value types (such as int?) are correctly handled by the AddMany method, ensuring that null can be assigned as a value.
Test for Duplicate Keys: Added a test case to check that an ArgumentException is thrown when attempting to add duplicate keys to the dictionary using AddMany.
Edge Case Coverage: Ensured edge cases, such as adding large collections of key-value pairs, are properly handled.

Motivation and Context:
The existing tests did not adequately cover scenarios involving null keys or nullable value types. This change is necessary to ensure that the AddMany method works as expected in edge cases, improving the overall test coverage.

The additional checks for duplicate keys ensure that the method behaves correctly when invalid inputs (such as duplicate keys) are provided, preventing potential runtime errors.

  • I have performed a self-review of my code
  • My code follows the style guidelines of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Comments in areas I changed are up to date
  • I have added comments to hard-to-understand areas of my code
  • I have made corresponding changes to the README.md

@gmottajr gmottajr requested a review from siriak as a code owner November 26, 2024 02:09
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.12%. Comparing base (c4091c7) to head (21c543b).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #498      +/-   ##
==========================================
- Coverage   95.16%   95.12%   -0.04%     
==========================================
  Files         267      267              
  Lines       10860    10860              
  Branches     1528     1528              
==========================================
- Hits        10335    10331       -4     
- Misses        400      403       +3     
- Partials      125      126       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@siriak siriak merged commit 0184c37 into TheAlgorithms:master Nov 26, 2024
3 of 4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants