MCPcopy
hub / github.com/yjs/yjs / testRepeatMergingMultipleIdMaps

Function testRepeatMergingMultipleIdMaps

tests/IdMap.tests.js:79–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77 * @param {t.TestCase} tc
78 */
79export const testRepeatMergingMultipleIdMaps = tc => {
80 const clients = 4
81 const clockRange = 5
82 /**
83 * @type {Array<idmap.IdMap<number>>}
84 */
85 const sets = []
86 for (let i = 0; i < 3; i++) {
87 sets.push(createRandomIdMap(tc.prng, clients, clockRange, [1, 2, 3]))
88 }
89 const merged = idmap.mergeIdMaps(sets)
90 const mergedReverse = idmap.mergeIdMaps(sets.reverse())
91 compareIdMaps(merged, mergedReverse)
92 const composed = idmap.createIdMap()
93 for (let iclient = 0; iclient < clients; iclient++) {
94 for (let iclock = 0; iclock < clockRange + 42; iclock++) {
95 const mergedHas = merged.hasId(new ID(iclient, iclock))
96 const oneHas = sets.some(ids => ids.hasId(new ID(iclient, iclock)))
97 t.assert(mergedHas === oneHas)
98 const mergedAttrs = merged.sliceId(new ID(iclient, iclock), 1)
99 mergedAttrs.forEach(a => {
100 if (a.attrs != null) {
101 composed.add(iclient, a.clock, a.len, a.attrs)
102 }
103 })
104 }
105 }
106 compareIdMaps(merged, composed)
107}
108
109/**
110 * @param {t.TestCase} tc

Callers

nothing calls this directly

Calls 6

createRandomIdMapFunction · 0.90
pushMethod · 0.80
sliceIdMethod · 0.80
hasIdMethod · 0.45
forEachMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…