Array Extension method to retrieve safeValue could crash if index is negative.
Though it does not pose any issue at present as there is only one occurrence of `safeValue(at:)` usage, in CardPartHistogramView, which does not use a negative index, the extension method would crash if a negative index is used.
https://github.com/intuit/CardParts/blob/27126a702b8011a274d93a6f0ba5cab18d1bab8c/CardParts/src/Classes/Card%20Parts/CardPartHistogramView.swift#L83-L85
What does this fix?
This PR aims to fix Array's `safeValue(at:)` method behaviour for negative index.
If a negative index is used, the method would not crash with `index out of range` exception and return nil, thereby making it safe to use with any Integer value.
How far has it been tested?
Added unit test to test the behaviour of Array `safeValue` method for negative, zero, positive index and positive index out of range.
How Has This Been Tested :mag:
Please let us know if you have tested your PR and if we need to reproduce the issues. Also, please let us know if we need any relevant information for running the tests.
User Interface Testing
Application Testing
Test Configuration :space_invader:
Xcode version:
13.0
Device/Simulator
Simulator
iOS version || MacOSX version
iOS 15.0
Things to check on :dart:
[x] My Pull Request code follows the coding standards and styles of the project
[x] I have worked on unit tests and reviewed my code to the best of my ability
[x] I have used comments to make other coders understand my code better
[x] My changes are good to go without any warnings
[x] I have added unit tests both for the happy and sad path
[x] All of my unit tests pass successfully before pushing the PR
[x] I have made sure all dependent downstream changes impacted by my PR are working
Before you make a Pull Request, read the important guidelines:
Issue Link :link: https://github.com/intuit/CardParts/issues/278
Goals of this PR :tada:
How Has This Been Tested :mag:
Please let us know if you have tested your PR and if we need to reproduce the issues. Also, please let us know if we need any relevant information for running the tests.
Test Configuration :space_invader:
Things to check on :dart: