NMFCode / NMF

This repository contains the entire code for the .NET Modeling Framework
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Fixed ObservableTopX when starting with an empty collection #33

Closed LennartH closed 6 years ago

LennartH commented 6 years ago

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.