Skip to content

Commit

Permalink
BinarySearchMCCTesting
Browse files Browse the repository at this point in the history
BinarySearchMCCTesting
  • Loading branch information
nmtuan1612 committed May 22, 2022
1 parent 73b3db5 commit d079c26
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/js/algorithms/search/binary-search.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import { expect } from 'chai';
import { binarySearch } from '../../../../src/js/index';
import { testSearchAlgorithm } from './search-algorithms-tests';

testSearchAlgorithm(binarySearch, 'Binary Search');

describe('binarySearch', () => {
it('search elements in array of numbers', () => {
expect(binarySearch([0, 5, 3], 1)).to.equal(-1);
expect(binarySearch([2, 64, 33, 40, 100], 40)).to.equal(2);
expect(binarySearch([1, 2], 2)).to.equal(1);
expect(binarySearch([10, 20, 15, 40, 65], 40)).to.equal(3);
expect(binarySearch([1, 6, 7, 8, 12, 13, 14, 19, 21, 23, 24, 24, 24, 300], 24)).to.equal(10);
expect(binarySearch([1, 2, 3, 610, 800, 1250, 1360, 1400, 1905], 600)).to.equal(-1);
expect(binarySearch([1, 2, 3, 742, 800, 1250, 1360, 1400, 19550], 2)).to.equal(1);
expect(binarySearch([1, 2, 3, 743, 800, 1000, 1335, 1490, 1800], 743)).to.equal(3);
expect(binarySearch([1, 2, 3, 700, 800, 1233, 1380, 1400, 19678], 800)).to.equal(4);
expect(binarySearch([0, 10, 11, 12, 13, 14, 15], 10)).to.equal(1);
});
});

0 comments on commit d079c26

Please sign in to comment.