|
6 | 6 | * PROGRAMMER: Peter Geinitz (Wayfarer) |
7 | 7 | */ |
8 | 8 |
|
9 | | -using System; |
10 | 9 | using System.Buffers; |
11 | | -using System.Collections.Generic; |
12 | 10 | using System.Diagnostics; |
13 | 11 | using System.Linq; |
14 | | -using System.Windows.Documents; |
15 | 12 | using ExtendedSystemObjects; |
16 | 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
17 | 14 |
|
@@ -209,7 +206,7 @@ public void PerformanceRemoveCompact() |
209 | 206 | /// Inserts the key1 into empty store should keep arrays in synchronize. |
210 | 207 | /// </summary> |
211 | 208 | [TestMethod] |
212 | | - public void InsertKey1IntoEmptyStoreShouldKeepArraysInSync() |
| 209 | + public void InsertKeyIntoEmptyStoreShouldKeepArraysInSync() |
213 | 210 | { |
214 | 211 | // Arrange |
215 | 212 | var store = new SortedKvStore(); |
@@ -494,7 +491,32 @@ public void BinarySearch() |
494 | 491 | Trace.WriteLine(store.ToString()); |
495 | 492 | var position = store.BinarySearch(9); |
496 | 493 |
|
497 | | - Assert.AreEqual(9, position, "Wrong position."); |
| 494 | + Assert.AreEqual(-10, position, "Wrong position."); |
| 495 | + } |
| 496 | + |
| 497 | + /// <summary> |
| 498 | + /// Binaries the search fails due to unsorted placeholder values. |
| 499 | + /// </summary> |
| 500 | + [TestMethod] |
| 501 | + public void BinarySearchFailsDueToUnsortedPlaceholderValues() |
| 502 | + { |
| 503 | + var store = new SortedKvStore(128); |
| 504 | + |
| 505 | + // Add 10 sorted keys: 1 through 10 |
| 506 | + for (int i = 1; i <= 10; i++) |
| 507 | + { |
| 508 | + store.Add(i, i); |
| 509 | + } |
| 510 | + |
| 511 | + Trace.WriteLine(store.ToString()); |
| 512 | + |
| 513 | + // We now search for 10, which is present |
| 514 | + var result = store.BinarySearch(10); |
| 515 | + |
| 516 | + Trace.WriteLine($"BinarySearch(10) returned: {result}"); |
| 517 | + |
| 518 | + // Expected index is 9 (0-based index of key = 10) |
| 519 | + Assert.AreEqual(9, result, "BinarySearch returned incorrect index due to unsorted placeholder values beyond the valid count."); |
498 | 520 | } |
499 | 521 | } |
500 | 522 | } |
0 commit comments