Skip to content

Commit 9b9bf05

Browse files
committed
tests for height
1 parent f80d021 commit 9b9bf05

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

b+tree.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ function testComparison<T>(comparison: (a: T, b: T) => number, inOrder: T[], val
162162
});
163163
}
164164

165+
describe('height calculation', () =>
166+
{
167+
test('Empty tree', () => {
168+
const tree = new BTree<number>();
169+
expect(tree.height).toEqual(0);
170+
});
171+
test('Single node', () => {
172+
const tree = new BTree<number>([[0, 0]]);
173+
expect(tree.height).toEqual(0);
174+
});
175+
test('Multiple node, no internal nodes', () => {
176+
const tree = new BTree<number>([[0, 0], [1, 1]], undefined, 32);
177+
expect(tree.height).toEqual(0);
178+
});
179+
test('Multiple internal nodes', () => {
180+
for (let expectedHeight = 1; expectedHeight < 5; expectedHeight++) {
181+
for (let nodeSize = 4; nodeSize < 10; nodeSize++) {
182+
const numEntries = nodeSize ** expectedHeight;
183+
const entries: [number, number][] = [];
184+
for (let i = 0; i < numEntries; i++) {
185+
entries.push([i, i]);
186+
}
187+
const tree = new BTree<number>(entries, undefined, nodeSize);
188+
expect(tree.height).toEqual(expectedHeight - 1);
189+
}
190+
}
191+
});
192+
});
165193

166194
describe('Simple tests on leaf nodes', () =>
167195
{

0 commit comments

Comments
 (0)