From 36c9c5fd855f015972796132c8b8642672f1d8fa Mon Sep 17 00:00:00 2001 From: n8allan <3095770+n8allan@users.noreply.github.com> Date: Fri, 29 Mar 2024 23:59:39 -0600 Subject: [PATCH] Added 1m entry random test (w/ timing) --- test/b-tree.branching.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/b-tree.branching.test.ts b/test/b-tree.branching.test.ts index afa4209..e92271b 100644 --- a/test/b-tree.branching.test.ts +++ b/test/b-tree.branching.test.ts @@ -138,6 +138,34 @@ describe('Branching BTree', () => { expect(tree.getCount()).toBe(0); }); + it('build a larger tree - randomly', () => { + const count = NodeCapacity * NodeCapacity * NodeCapacity * 4; // ~ 1 million + const randomStart = performance.now(); + for (let i = 0; i !== count; ++i) { + Math.random(); + } + const randomTime = performance.now() - randomStart; + const insertStart = performance.now(); + for (let i = 0; i !== count; ++i) { + tree.insert(Math.random()); + } + const insertTime = performance.now() - insertStart; + console.log(`Random: ${randomTime}ms, Insert: ${insertTime}ms, Net: ${insertTime - randomTime}ms`); + expect(tree.getCount()).toBeCloseTo(count, 2); + // Gut randomly + while (tree.first().on) { + const path = tree.find(Math.random()); + if (!path.on) { + tree.moveNext(path); + } + if (!path.on) { + tree.movePrior(path); + } + tree.deleteAt(path); + } + expect(tree.getCount()).toBe(0); + }); + it('getCount should give the correct number, whether ascending or descending, with a starting path, or not', () => { const count = NodeCapacity * NodeCapacity + 1; addRange(0, count);