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

View file

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