All files / trees BPlusTreeNode.test.js

0% Statements 0/36
100% Branches 0/0
0% Functions 0/10
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                                         
import Node from './BPlusTreeNode';
 
describe('BPlusTreNode.js', () => {
  it('Creates a Leaf Node', () => {
    const node = new Node(Node.LEAF_NODE, 4);
    expect(node.type).toEqual(Node.LEAF_NODE);
  });
 
  it('Creates an Internal Node', () => {
    const node = new Node(Node.INTERNAL_NODE, 4);
    expect(node.type).toEqual(Node.INTERNAL_NODE);
  });
 
  it('Creates the correct size value and children arrays', () => {
    const N = 4;
    const node = new Node(Node.INTERNAL_NODE, N);
    expect(node.values.length).toEqual(2 * N);
    expect(node.children.length).toEqual(2 * N + 1);
    node.values.forEach((value) => expect(value).toBeUndefined());
    node.children.forEach((child) => expect(child).toBeUndefined());
  });
 
  it('InternalNode: destructor deletes all child nodes', () => {
    const N = 4;
    const node = new Node(Node.INTERNAL_NODE, N);
    node.used = 2 * N;
    for (let i = 0; i < node.children.length; i += 1) {
      node.children[i] = new Node(Node.LEAF_NODE, N);
    }
    node.destructor();
    node.children.forEach((childNode) => expect(childNode).toBeUndefined());
  });
 
  it('LeafNode: destructor does nothing', () => {
    const N = 4;
    const node = new Node(Node.LEAF_NODE, N);
    node.used = 2 * N;
    for (let i = 0; i < node.children.length; i += 1) {
      node.children[i] = new Node(Node.LEAF_NODE, N);
    }
    node.destructor();
    node.children.forEach((childNode) => expect(childNode).toBeInstanceOf(Node));
  });
});