Sha256: f13cb4ca3c0f80ff5fb28fea96315ef8b0800b682e17c7f50e0cb6aebab2d6f4

Contents?: true

Size: 1.98 KB

Versions: 208

Compression:

Stored size: 1.98 KB

Contents

import BinarySearchTree from './binary-search-tree';

function recordAllData(bst) {
  let out = [];

  bst.each((data) => out.push(data));

  return out;
}

describe('BinarySearchTree', () => {

  it('data is retained', () => {
    expect(new BinarySearchTree(4).data).toEqual(4);
  });

  xit('inserting less', () => {
    let four = new BinarySearchTree(4);
    four.insert(2);

    expect(four.data).toEqual(4);
    expect(four.left.data).toEqual(2);
  });

  xit('inserting same', () => {
    let four = new BinarySearchTree(4);
    four.insert(4);

    expect(four.data).toEqual(4);
    expect(four.left.data).toEqual(4);
  });

  xit('inserting right', () => {
    let four = new BinarySearchTree(4);
    four.insert(5);

    expect(four.data).toEqual(4);
    expect(four.right.data).toEqual(5);
  });

  xit('complex tree', () => {
    let four = new BinarySearchTree(4);
    four.insert(2);
    four.insert(6);
    four.insert(1);
    four.insert(3);
    four.insert(7);
    four.insert(5);

    expect(four.data).toEqual(4);
    expect(four.left.data).toEqual(2);
    expect(four.left.left.data).toEqual(1);
    expect(four.left.right.data).toEqual(3);
    expect(four.right.data).toEqual(6);
    expect(four.right.left.data).toEqual(5);
    expect(four.right.right.data).toEqual(7);
  });

  xit('iterating one element', () => {
    expect(recordAllData(new BinarySearchTree(4))).toEqual([ 4 ]);
  });

  xit('iterating over smaller element', () => {
    let four = new BinarySearchTree(4);
    four.insert(2);

    expect(recordAllData(four)).toEqual([ 2, 4 ]);
  });

  xit('iterating over larger element', () => {
    let four = new BinarySearchTree(4);
    four.insert(5);

    expect(recordAllData(four)).toEqual([ 4, 5 ]);
  });

  xit('iterating over complex tree', () => {
    let four = new BinarySearchTree(4);
    four.insert(2);
    four.insert(1);
    four.insert(3);
    four.insert(6);
    four.insert(7);
    four.insert(5);

    expect(recordAllData(four)).toEqual([ 1, 2, 3, 4, 5, 6, 7 ]);
  });

});

Version data entries

208 entries across 208 versions & 1 rubygems

Version Path
trackler-2.1.0.53 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.52 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.51 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.50 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.49 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.48 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.47 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.46 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.45 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.44 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.43 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.42 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.41 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.40 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.39 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.38 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.37 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.36 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.34 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.1.0.33 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js