Starting with an empty collection and then adding a new element resulted in an IndexOutOfRangeException, when iterating from 0 to X. Adding a length check fixed that.
This led to sitations where value.Length was not equal to i, but newValue was not null, indicating that a change happened. The behaviour when clearing the collection or starting with an empty collection indicated that the size of the resulting top x array should be equal to X or to the count of the source collection, if X is greater than the number of elements. So simply returning newValue would break this condition. Resizing newValue is sufficient, since all elements to i in value have already been copied to newValue, if newValue is not null.
Added the new test TopX_EmptyMultipleAdd_CorrectResult (which initially failed) to check this behavior.
Starting with an empty collection and then adding a new element resulted in an
IndexOutOfRangeException
, when iterating from 0 toX
. Adding a length check fixed that.This led to sitations where
value.Length
was not equal toi
, butnewValue
was notnull
, indicating that a change happened. The behaviour when clearing the collection or starting with an empty collection indicated that the size of the resulting top x array should be equal toX
or to the count of the source collection, ifX
is greater than the number of elements. So simply returningnewValue
would break this condition. ResizingnewValue
is sufficient, since all elements toi
invalue
have already been copied tonewValue
, ifnewValue
is notnull
.Added the new test
TopX_EmptyMultipleAdd_CorrectResult
(which initially failed) to check this behavior.