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.0.8.28 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.27 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.26 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.24 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.23 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.22 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.21 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.20 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.19 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.18 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.17 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.16 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.15 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.14 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.13 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.12 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.11 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.10 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.9 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js
trackler-2.0.8.8 tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js