stride
stride copied to clipboard
feat: Add more unit tests in Core to increase coverage
PR Details
Improve the code coverage of Stride.Core.AssemblyProcessor, Stride.Core.Yaml, Stride.Core and Stride.Core.IO.
Related PR
#2967
Details
A few bugs were identified during testing and fixed.
MultiValueSortedList<TKey, TValue>
Bug 1: Binary search in Add() method failed to maintain sorted order
- Cause: Loop condition
while (greater - lower > 1)prevented proper sorting for lists with 0-1 elements - Impact: Items were not inserted in sorted order (e.g., adding 5,2,8,1 resulted in [5,2,8,1] instead of [1,2,5,8])
- Fix: Replaced with standard binary search algorithm using
while (lower < upper)pattern
Bug 2: Indexer returned incomplete results for duplicate keys
- Cause:
BinarySearchreturns an arbitrary matching index, not necessarily the first occurrence - Impact: When multiple values shared the same key, only a subset was returned (e.g., 1-2 values instead of all 3)
- Fix: Added backward scan to find first occurrence before returning values:
while (index > 0 && keys[index - 1].Equals(key)) index--;
Types of changes
- [ ] Docs change / refactoring / dependency upgrade
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [ ] My change requires a change to the documentation.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [ ] I have built and run the editor to try this change out.