cleanup query test

This commit is contained in:
Rowan 2024-11-22 05:03:41 -06:00
parent 90972e95e4
commit f0f607c2af
2 changed files with 24 additions and 33 deletions

View file

@ -35,7 +35,7 @@ export const useWith = curry((fn, tfns) =>
)) ))
export const converge = (fn, tfns) => curryN( export const converge = (fn, tfns) => curryN(
max(map(length, tfns)), pipe(length, map, max)(tfns),
(...args) => fn(...map(tfn => tfn(...args), tfns)) (...args) => fn(...map(tfn => tfn(...args), tfns))
) )
@ -68,7 +68,7 @@ export const split = curry((delim, v) => v.split(delim))
export const max = v => Math.max(...v) export const max = v => Math.max(...v)
export const min = v => Math.min(...v) export const min = v => Math.min(...v)
export const inc = v => v + 1 export const inc = v => v + 1
export const dec = v => v + 1 export const dec = v => v - 1
// arrays // arrays
export const map = curry((fn, v) => v.map(fn)) export const map = curry((fn, v) => v.map(fn))
@ -103,21 +103,16 @@ export const assocPath = curry((key, value, obj) => pipe(
mergeRightDeep(obj), mergeRightDeep(obj),
)(key)) )(key))
export const mergeLeftDeep = curry((a, b) => { export const mergeLeftDeep = curry((a, b) =>
return reduce((acc, key) => { reduce((acc, key) => pipe(
const av = acc[key] ifElse(
const bv = b[key] every(is(Object)),
apply(mergeLeftDeep),
return pipe( last
ifElse( ),
every(is(Object)), v => assoc(key, v, acc)
apply(mergeLeftDeep), )([acc[key], b[key]]), a, keys(b))
last )
),
v => assoc(key, v, acc)
)([av, bv])
}, a, keys(b))
})
export const mergeRightDeep = flip(mergeLeftDeep) export const mergeRightDeep = flip(mergeLeftDeep)

View file

@ -29,12 +29,14 @@ describe('query', () => {
return eid return eid
} }
const knows = (a, b) => { const relate = (a, type, ...b) => {
const edge = addEntity(w) return b.map(v => {
addComponent(w, Knows, edge) const edge = addEntity(w)
Knows.from[edge] = a addComponent(w, type, edge)
Knows.to[edge] = b type.from[edge] = a
return edge type.to[edge] = v
return edge
})
} }
const player = create(Player) // 0 const player = create(Player) // 0
@ -42,16 +44,10 @@ describe('query', () => {
const b = create(NPC) // 2 const b = create(NPC) // 2
const c = create(NPC) // 3 const c = create(NPC) // 3
knows(player, a) // 4 relate(player, Knows, a, c) // 4, 5
knows(player, c) // 5 relate(a, Knows, player, b, c) // 6, 7, 8
relate(b, Knows, a) // 9
knows(a, player) // 6 relate(c, Knows, player) // 10
knows(a, b) // 7
knows(a, c) // 8
knows(b, a) // 9
knows(c, player) // 10
assert.deepEqual( assert.deepEqual(
query('MATCH (player:Player) RETURN player', engine).unwrap(), query('MATCH (player:Player) RETURN player', engine).unwrap(),