CardParts icon indicating copy to clipboard operation
CardParts copied to clipboard

Fix Array `safeValue(at:)`

Open mak-s opened this issue 4 years ago • 0 comments

Array extension safaValue(at:) method would crash if a negative index is used. https://github.com/intuit/CardParts/blob/3234eda81697e4a2e9e91f0a3673119dca996846/CardParts/src/Extensions/Array.swift#L11-L17

Though it does not introduce any bug at present as there is only one occurrence of safeValue 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

Could we add a add a check for negative value to ensure that method work for all index values. (fix available in branch: https://github.com/mak-s/CardParts/tree/array_index_out_of_range)

Also, CardParts code coverage is less. I'd like to add some Unit tests for existing classes available in CardParts.

  • Could you please let me know if I should create a new Issue for adding Unit tests.

mak-s avatar Oct 25 '21 10:10 mak-s