(results: Array<any>, expectedOrder: Array<string>)
| 42 | |
| 43 | // Helper function to verify the expected order of elements |
| 44 | function verifyOrder(results: Array<any>, expectedOrder: Array<string>) { |
| 45 | // Extract values in the order they appear in the results |
| 46 | const actualOrder = results.map(([[_, [value, __]]]) => value.value) |
| 47 | |
| 48 | // Sort both arrays to ensure consistent comparison |
| 49 | const sortedActual = [...actualOrder].sort() |
| 50 | const sortedExpected = [...expectedOrder].sort() |
| 51 | |
| 52 | // First check that we have the same elements |
| 53 | expect(sortedActual).toEqual(sortedExpected) |
| 54 | |
| 55 | // Now check that the indices result in the correct order |
| 56 | const valueToIndex = new Map() |
| 57 | for (const [[_key, [value, index]]] of results) { |
| 58 | valueToIndex.set(value.value, index) |
| 59 | } |
| 60 | |
| 61 | // Sort the values by their indices |
| 62 | const sortedByIndex = [...valueToIndex.entries()] |
| 63 | .sort((a, b) => (a[1] < b[1] ? -1 : 1)) |
| 64 | .map(([value]) => value) |
| 65 | |
| 66 | // The order should match the expected order |
| 67 | expect(sortedByIndex).toEqual(expectedOrder) |
| 68 | } |
| 69 | |
| 70 | beforeAll(async () => { |
| 71 | await loadBTree() |
no test coverage detected