Sha256: 82c7ccf8743bd630ed8db45a4982e0d0a7816e1ba55a2e6e0a772f38d77599e6

Contents?: true

Size: 1.31 KB

Versions: 141

Compression:

Stored size: 1.31 KB

Contents

var BinarySearch = require('./binary-search');

describe('BinarySearch', function () {
  var sortedArray = [1, 2, 3, 4, 5, 6];
  var sortedArrayOfOddLength = [0, 1, 2, 2, 3, 10, 12];
  var unsortedArray = [10, 2, 5, 1];

  it('should require a sorted array', function () {
    var invalidBinarySearch = new BinarySearch(unsortedArray);
    var validBinarySearch = new BinarySearch(sortedArray);

    expect(typeof invalidBinarySearch.array).toEqual('undefined');
    expect(Array.isArray(validBinarySearch.array)).toEqual(true);
  });

  xit('should find the correct index of an included value in the middle of the array', function () {
    expect(new BinarySearch(sortedArray).indexOf(3)).toEqual(2);
  });

  xit('should find the correct index of an included value at the beginning of the array', function () {
    expect(new BinarySearch(sortedArray).indexOf(1)).toEqual(0);
  });

  xit('should find the correct index of an included value at the end of the array', function () {
    expect(new BinarySearch(sortedArray).indexOf(6)).toEqual(5);
  });

  xit('should search the middle of the array', function () {
    expect(new BinarySearch(sortedArrayOfOddLength).indexOf(2)).toEqual(3);
  });

  xit('should return -1 for a value not in the array', function () {
    expect(new BinarySearch(sortedArray).indexOf(10)).toEqual(-1);
  });
});

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.179 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.178 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.177 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.176 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.175 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.174 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.173 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.172 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.171 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.170 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.169 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.167 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.166 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.165 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.164 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.163 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.162 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.161 tracks/javascript/exercises/binary-search/binary-search.spec.js
trackler-2.2.1.160 tracks/javascript/exercises/binary-search/binary-search.spec.js