MCPcopy Create free account
hub / github.com/TanStack/db / verifyOrder

Function verifyOrder

packages/db-ivm/tests/operators/topKWithFractionalIndex.test.ts:44–68  ·  view source on GitHub ↗
(results: Array<any>, expectedOrder: Array<string>)

Source from the content-addressed store, hash-verified

42
43// Helper function to verify the expected order of elements
44function 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
70beforeAll(async () => {
71 await loadBTree()

Callers 1

Calls 4

expectFunction · 0.90
mapMethod · 0.45
setMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected