Skip to content

Commit 39acb2b

Browse files
committed
Avoid using toBeTruthy() and toBeFalsy() because of type coercion.
1 parent 8da83cd commit 39acb2b

File tree

25 files changed

+367
-367
lines changed

25 files changed

+367
-367
lines changed

src/algorithms/graph/detect-cycle/__test__/detectUndirectedCycleUsingDisjointSet.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ describe('detectUndirectedCycleUsingDisjointSet', () => {
2727
.addEdge(edgeBC)
2828
.addEdge(edgeCD);
2929

30-
expect(detectUndirectedCycleUsingDisjointSet(graph)).toBeFalsy();
30+
expect(detectUndirectedCycleUsingDisjointSet(graph)).toBe(false);
3131

3232
graph.addEdge(edgeDE);
3333

34-
expect(detectUndirectedCycleUsingDisjointSet(graph)).toBeTruthy();
34+
expect(detectUndirectedCycleUsingDisjointSet(graph)).toBe(true);
3535
});
3636
});

src/algorithms/math/is-power-of-two/__test__/isPowerOfTwo.test.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import isPowerOfTwo from '../isPowerOfTwo';
22

33
describe('isPowerOfTwo', () => {
44
it('should check if the number is made by multiplying twos', () => {
5-
expect(isPowerOfTwo(-1)).toBeFalsy();
6-
expect(isPowerOfTwo(0)).toBeFalsy();
7-
expect(isPowerOfTwo(1)).toBeTruthy();
8-
expect(isPowerOfTwo(2)).toBeTruthy();
9-
expect(isPowerOfTwo(3)).toBeFalsy();
10-
expect(isPowerOfTwo(4)).toBeTruthy();
11-
expect(isPowerOfTwo(5)).toBeFalsy();
12-
expect(isPowerOfTwo(6)).toBeFalsy();
13-
expect(isPowerOfTwo(7)).toBeFalsy();
14-
expect(isPowerOfTwo(8)).toBeTruthy();
15-
expect(isPowerOfTwo(10)).toBeFalsy();
16-
expect(isPowerOfTwo(12)).toBeFalsy();
17-
expect(isPowerOfTwo(16)).toBeTruthy();
18-
expect(isPowerOfTwo(31)).toBeFalsy();
19-
expect(isPowerOfTwo(64)).toBeTruthy();
20-
expect(isPowerOfTwo(1024)).toBeTruthy();
21-
expect(isPowerOfTwo(1023)).toBeFalsy();
5+
expect(isPowerOfTwo(-1)).toBe(false);
6+
expect(isPowerOfTwo(0)).toBe(false);
7+
expect(isPowerOfTwo(1)).toBe(true);
8+
expect(isPowerOfTwo(2)).toBe(true);
9+
expect(isPowerOfTwo(3)).toBe(false);
10+
expect(isPowerOfTwo(4)).toBe(true);
11+
expect(isPowerOfTwo(5)).toBe(false);
12+
expect(isPowerOfTwo(6)).toBe(false);
13+
expect(isPowerOfTwo(7)).toBe(false);
14+
expect(isPowerOfTwo(8)).toBe(true);
15+
expect(isPowerOfTwo(10)).toBe(false);
16+
expect(isPowerOfTwo(12)).toBe(false);
17+
expect(isPowerOfTwo(16)).toBe(true);
18+
expect(isPowerOfTwo(31)).toBe(false);
19+
expect(isPowerOfTwo(64)).toBe(true);
20+
expect(isPowerOfTwo(1024)).toBe(true);
21+
expect(isPowerOfTwo(1023)).toBe(false);
2222
});
2323
});

src/algorithms/math/is-power-of-two/__test__/isPowerOfTwoBitwise.test.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ import isPowerOfTwoBitwise from '../isPowerOfTwoBitwise';
22

33
describe('isPowerOfTwoBitwise', () => {
44
it('should check if the number is made by multiplying twos', () => {
5-
expect(isPowerOfTwoBitwise(-1)).toBeFalsy();
6-
expect(isPowerOfTwoBitwise(0)).toBeFalsy();
7-
expect(isPowerOfTwoBitwise(1)).toBeTruthy();
8-
expect(isPowerOfTwoBitwise(2)).toBeTruthy();
9-
expect(isPowerOfTwoBitwise(3)).toBeFalsy();
10-
expect(isPowerOfTwoBitwise(4)).toBeTruthy();
11-
expect(isPowerOfTwoBitwise(5)).toBeFalsy();
12-
expect(isPowerOfTwoBitwise(6)).toBeFalsy();
13-
expect(isPowerOfTwoBitwise(7)).toBeFalsy();
14-
expect(isPowerOfTwoBitwise(8)).toBeTruthy();
15-
expect(isPowerOfTwoBitwise(10)).toBeFalsy();
16-
expect(isPowerOfTwoBitwise(12)).toBeFalsy();
17-
expect(isPowerOfTwoBitwise(16)).toBeTruthy();
18-
expect(isPowerOfTwoBitwise(31)).toBeFalsy();
19-
expect(isPowerOfTwoBitwise(64)).toBeTruthy();
20-
expect(isPowerOfTwoBitwise(1024)).toBeTruthy();
21-
expect(isPowerOfTwoBitwise(1023)).toBeFalsy();
5+
expect(isPowerOfTwoBitwise(-1)).toBe(false);
6+
expect(isPowerOfTwoBitwise(0)).toBe(false);
7+
expect(isPowerOfTwoBitwise(1)).toBe(true);
8+
expect(isPowerOfTwoBitwise(2)).toBe(true);
9+
expect(isPowerOfTwoBitwise(3)).toBe(false);
10+
expect(isPowerOfTwoBitwise(4)).toBe(true);
11+
expect(isPowerOfTwoBitwise(5)).toBe(false);
12+
expect(isPowerOfTwoBitwise(6)).toBe(false);
13+
expect(isPowerOfTwoBitwise(7)).toBe(false);
14+
expect(isPowerOfTwoBitwise(8)).toBe(true);
15+
expect(isPowerOfTwoBitwise(10)).toBe(false);
16+
expect(isPowerOfTwoBitwise(12)).toBe(false);
17+
expect(isPowerOfTwoBitwise(16)).toBe(true);
18+
expect(isPowerOfTwoBitwise(31)).toBe(false);
19+
expect(isPowerOfTwoBitwise(64)).toBe(true);
20+
expect(isPowerOfTwoBitwise(1024)).toBe(true);
21+
expect(isPowerOfTwoBitwise(1023)).toBe(false);
2222
});
2323
});

src/algorithms/math/primality-test/__test__/trialDivision.test.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ import trialDivision from '../trialDivision';
44
* @param {function(n: number)} testFunction
55
*/
66
function primalityTest(testFunction) {
7-
expect(testFunction(1)).toBeFalsy();
8-
expect(testFunction(2)).toBeTruthy();
9-
expect(testFunction(3)).toBeTruthy();
10-
expect(testFunction(5)).toBeTruthy();
11-
expect(testFunction(11)).toBeTruthy();
12-
expect(testFunction(191)).toBeTruthy();
13-
expect(testFunction(191)).toBeTruthy();
14-
expect(testFunction(199)).toBeTruthy();
7+
expect(testFunction(1)).toBe(false);
8+
expect(testFunction(2)).toBe(true);
9+
expect(testFunction(3)).toBe(true);
10+
expect(testFunction(5)).toBe(true);
11+
expect(testFunction(11)).toBe(true);
12+
expect(testFunction(191)).toBe(true);
13+
expect(testFunction(191)).toBe(true);
14+
expect(testFunction(199)).toBe(true);
1515

16-
expect(testFunction(-1)).toBeFalsy();
17-
expect(testFunction(0)).toBeFalsy();
18-
expect(testFunction(4)).toBeFalsy();
19-
expect(testFunction(6)).toBeFalsy();
20-
expect(testFunction(12)).toBeFalsy();
21-
expect(testFunction(14)).toBeFalsy();
22-
expect(testFunction(25)).toBeFalsy();
23-
expect(testFunction(192)).toBeFalsy();
24-
expect(testFunction(200)).toBeFalsy();
25-
expect(testFunction(400)).toBeFalsy();
16+
expect(testFunction(-1)).toBe(false);
17+
expect(testFunction(0)).toBe(false);
18+
expect(testFunction(4)).toBe(false);
19+
expect(testFunction(6)).toBe(false);
20+
expect(testFunction(12)).toBe(false);
21+
expect(testFunction(14)).toBe(false);
22+
expect(testFunction(25)).toBe(false);
23+
expect(testFunction(192)).toBe(false);
24+
expect(testFunction(200)).toBe(false);
25+
expect(testFunction(400)).toBe(false);
2626

2727
// It should also deal with floats.
28-
expect(testFunction(0.5)).toBeFalsy();
29-
expect(testFunction(1.3)).toBeFalsy();
30-
expect(testFunction(10.5)).toBeFalsy();
28+
expect(testFunction(0.5)).toBe(false);
29+
expect(testFunction(1.3)).toBe(false);
30+
expect(testFunction(10.5)).toBe(false);
3131
}
3232

3333
describe('trialDivision', () => {

src/algorithms/string/regular-expression-matching/__test__/regularExpressionMatching.test.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@ import regularExpressionMatching from '../regularExpressionMatching';
22

33
describe('regularExpressionMatching', () => {
44
it('should match regular expressions in a string', () => {
5-
expect(regularExpressionMatching('', '')).toBeTruthy();
6-
expect(regularExpressionMatching('a', 'a')).toBeTruthy();
7-
expect(regularExpressionMatching('aa', 'aa')).toBeTruthy();
8-
expect(regularExpressionMatching('aab', 'aab')).toBeTruthy();
9-
expect(regularExpressionMatching('aab', 'aa.')).toBeTruthy();
10-
expect(regularExpressionMatching('aab', '.a.')).toBeTruthy();
11-
expect(regularExpressionMatching('aab', '...')).toBeTruthy();
12-
expect(regularExpressionMatching('a', 'a*')).toBeTruthy();
13-
expect(regularExpressionMatching('aaa', 'a*')).toBeTruthy();
14-
expect(regularExpressionMatching('aaab', 'a*b')).toBeTruthy();
15-
expect(regularExpressionMatching('aaabb', 'a*b*')).toBeTruthy();
16-
expect(regularExpressionMatching('aaabb', 'a*b*c*')).toBeTruthy();
17-
expect(regularExpressionMatching('', 'a*')).toBeTruthy();
18-
expect(regularExpressionMatching('xaabyc', 'xa*b.c')).toBeTruthy();
19-
expect(regularExpressionMatching('aab', 'c*a*b*')).toBeTruthy();
20-
expect(regularExpressionMatching('mississippi', 'mis*is*.p*.')).toBeTruthy();
21-
expect(regularExpressionMatching('ab', '.*')).toBeTruthy();
5+
expect(regularExpressionMatching('', '')).toBe(true);
6+
expect(regularExpressionMatching('a', 'a')).toBe(true);
7+
expect(regularExpressionMatching('aa', 'aa')).toBe(true);
8+
expect(regularExpressionMatching('aab', 'aab')).toBe(true);
9+
expect(regularExpressionMatching('aab', 'aa.')).toBe(true);
10+
expect(regularExpressionMatching('aab', '.a.')).toBe(true);
11+
expect(regularExpressionMatching('aab', '...')).toBe(true);
12+
expect(regularExpressionMatching('a', 'a*')).toBe(true);
13+
expect(regularExpressionMatching('aaa', 'a*')).toBe(true);
14+
expect(regularExpressionMatching('aaab', 'a*b')).toBe(true);
15+
expect(regularExpressionMatching('aaabb', 'a*b*')).toBe(true);
16+
expect(regularExpressionMatching('aaabb', 'a*b*c*')).toBe(true);
17+
expect(regularExpressionMatching('', 'a*')).toBe(true);
18+
expect(regularExpressionMatching('xaabyc', 'xa*b.c')).toBe(true);
19+
expect(regularExpressionMatching('aab', 'c*a*b*')).toBe(true);
20+
expect(regularExpressionMatching('mississippi', 'mis*is*.p*.')).toBe(true);
21+
expect(regularExpressionMatching('ab', '.*')).toBe(true);
2222

23-
expect(regularExpressionMatching('', 'a')).toBeFalsy();
24-
expect(regularExpressionMatching('a', '')).toBeFalsy();
25-
expect(regularExpressionMatching('aab', 'aa')).toBeFalsy();
26-
expect(regularExpressionMatching('aab', 'baa')).toBeFalsy();
27-
expect(regularExpressionMatching('aabc', '...')).toBeFalsy();
28-
expect(regularExpressionMatching('aaabbdd', 'a*b*c*')).toBeFalsy();
29-
expect(regularExpressionMatching('mississippi', 'mis*is*p*.')).toBeFalsy();
30-
expect(regularExpressionMatching('ab', 'a*')).toBeFalsy();
31-
expect(regularExpressionMatching('abba', 'a*b*.c')).toBeFalsy();
32-
expect(regularExpressionMatching('abba', '.*c')).toBeFalsy();
23+
expect(regularExpressionMatching('', 'a')).toBe(false);
24+
expect(regularExpressionMatching('a', '')).toBe(false);
25+
expect(regularExpressionMatching('aab', 'aa')).toBe(false);
26+
expect(regularExpressionMatching('aab', 'baa')).toBe(false);
27+
expect(regularExpressionMatching('aabc', '...')).toBe(false);
28+
expect(regularExpressionMatching('aaabbdd', 'a*b*c*')).toBe(false);
29+
expect(regularExpressionMatching('mississippi', 'mis*is*p*.')).toBe(false);
30+
expect(regularExpressionMatching('ab', 'a*')).toBe(false);
31+
expect(regularExpressionMatching('abba', 'a*b*.c')).toBe(false);
32+
expect(regularExpressionMatching('abba', '.*c')).toBe(false);
3333
});
3434
});

src/algorithms/uncategorized/jump-game/__test__/backtrackingJumpGame.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import backtrackingJumpGame from '../backtrackingJumpGame';
22

33
describe('backtrackingJumpGame', () => {
44
it('should solve Jump Game problem in backtracking manner', () => {
5-
expect(backtrackingJumpGame([1, 0])).toBeTruthy();
6-
expect(backtrackingJumpGame([100, 0])).toBeTruthy();
7-
expect(backtrackingJumpGame([2, 3, 1, 1, 4])).toBeTruthy();
8-
expect(backtrackingJumpGame([1, 1, 1, 1, 1])).toBeTruthy();
9-
expect(backtrackingJumpGame([1, 1, 1, 10, 1])).toBeTruthy();
10-
expect(backtrackingJumpGame([1, 5, 2, 1, 0, 2, 0])).toBeTruthy();
5+
expect(backtrackingJumpGame([1, 0])).toBe(true);
6+
expect(backtrackingJumpGame([100, 0])).toBe(true);
7+
expect(backtrackingJumpGame([2, 3, 1, 1, 4])).toBe(true);
8+
expect(backtrackingJumpGame([1, 1, 1, 1, 1])).toBe(true);
9+
expect(backtrackingJumpGame([1, 1, 1, 10, 1])).toBe(true);
10+
expect(backtrackingJumpGame([1, 5, 2, 1, 0, 2, 0])).toBe(true);
1111

12-
expect(backtrackingJumpGame([1, 0, 1])).toBeFalsy();
13-
expect(backtrackingJumpGame([3, 2, 1, 0, 4])).toBeFalsy();
14-
expect(backtrackingJumpGame([0, 0, 0, 0, 0])).toBeFalsy();
15-
expect(backtrackingJumpGame([5, 4, 3, 2, 1, 0, 0])).toBeFalsy();
12+
expect(backtrackingJumpGame([1, 0, 1])).toBe(false);
13+
expect(backtrackingJumpGame([3, 2, 1, 0, 4])).toBe(false);
14+
expect(backtrackingJumpGame([0, 0, 0, 0, 0])).toBe(false);
15+
expect(backtrackingJumpGame([5, 4, 3, 2, 1, 0, 0])).toBe(false);
1616
});
1717
});

src/algorithms/uncategorized/jump-game/__test__/dpBottomUpJumpGame.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import dpBottomUpJumpGame from '../dpBottomUpJumpGame';
22

33
describe('dpBottomUpJumpGame', () => {
44
it('should solve Jump Game problem in bottom-up dynamic programming manner', () => {
5-
expect(dpBottomUpJumpGame([1, 0])).toBeTruthy();
6-
expect(dpBottomUpJumpGame([100, 0])).toBeTruthy();
7-
expect(dpBottomUpJumpGame([2, 3, 1, 1, 4])).toBeTruthy();
8-
expect(dpBottomUpJumpGame([1, 1, 1, 1, 1])).toBeTruthy();
9-
expect(dpBottomUpJumpGame([1, 1, 1, 10, 1])).toBeTruthy();
10-
expect(dpBottomUpJumpGame([1, 5, 2, 1, 0, 2, 0])).toBeTruthy();
5+
expect(dpBottomUpJumpGame([1, 0])).toBe(true);
6+
expect(dpBottomUpJumpGame([100, 0])).toBe(true);
7+
expect(dpBottomUpJumpGame([2, 3, 1, 1, 4])).toBe(true);
8+
expect(dpBottomUpJumpGame([1, 1, 1, 1, 1])).toBe(true);
9+
expect(dpBottomUpJumpGame([1, 1, 1, 10, 1])).toBe(true);
10+
expect(dpBottomUpJumpGame([1, 5, 2, 1, 0, 2, 0])).toBe(true);
1111

12-
expect(dpBottomUpJumpGame([1, 0, 1])).toBeFalsy();
13-
expect(dpBottomUpJumpGame([3, 2, 1, 0, 4])).toBeFalsy();
14-
expect(dpBottomUpJumpGame([0, 0, 0, 0, 0])).toBeFalsy();
15-
expect(dpBottomUpJumpGame([5, 4, 3, 2, 1, 0, 0])).toBeFalsy();
12+
expect(dpBottomUpJumpGame([1, 0, 1])).toBe(false);
13+
expect(dpBottomUpJumpGame([3, 2, 1, 0, 4])).toBe(false);
14+
expect(dpBottomUpJumpGame([0, 0, 0, 0, 0])).toBe(false);
15+
expect(dpBottomUpJumpGame([5, 4, 3, 2, 1, 0, 0])).toBe(false);
1616
});
1717
});

src/algorithms/uncategorized/jump-game/__test__/dpTopDownJumpGame.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import dpTopDownJumpGame from '../dpTopDownJumpGame';
22

33
describe('dpTopDownJumpGame', () => {
44
it('should solve Jump Game problem in top-down dynamic programming manner', () => {
5-
expect(dpTopDownJumpGame([1, 0])).toBeTruthy();
6-
expect(dpTopDownJumpGame([100, 0])).toBeTruthy();
7-
expect(dpTopDownJumpGame([2, 3, 1, 1, 4])).toBeTruthy();
8-
expect(dpTopDownJumpGame([1, 1, 1, 1, 1])).toBeTruthy();
9-
expect(dpTopDownJumpGame([1, 1, 1, 10, 1])).toBeTruthy();
10-
expect(dpTopDownJumpGame([1, 5, 2, 1, 0, 2, 0])).toBeTruthy();
5+
expect(dpTopDownJumpGame([1, 0])).toBe(true);
6+
expect(dpTopDownJumpGame([100, 0])).toBe(true);
7+
expect(dpTopDownJumpGame([2, 3, 1, 1, 4])).toBe(true);
8+
expect(dpTopDownJumpGame([1, 1, 1, 1, 1])).toBe(true);
9+
expect(dpTopDownJumpGame([1, 1, 1, 10, 1])).toBe(true);
10+
expect(dpTopDownJumpGame([1, 5, 2, 1, 0, 2, 0])).toBe(true);
1111

12-
expect(dpTopDownJumpGame([1, 0, 1])).toBeFalsy();
13-
expect(dpTopDownJumpGame([3, 2, 1, 0, 4])).toBeFalsy();
14-
expect(dpTopDownJumpGame([0, 0, 0, 0, 0])).toBeFalsy();
15-
expect(dpTopDownJumpGame([5, 4, 3, 2, 1, 0, 0])).toBeFalsy();
12+
expect(dpTopDownJumpGame([1, 0, 1])).toBe(false);
13+
expect(dpTopDownJumpGame([3, 2, 1, 0, 4])).toBe(false);
14+
expect(dpTopDownJumpGame([0, 0, 0, 0, 0])).toBe(false);
15+
expect(dpTopDownJumpGame([5, 4, 3, 2, 1, 0, 0])).toBe(false);
1616
});
1717
});

src/algorithms/uncategorized/jump-game/__test__/greedyJumpGame.test.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import greedyJumpGame from '../greedyJumpGame';
22

33
describe('greedyJumpGame', () => {
44
it('should solve Jump Game problem in greedy manner', () => {
5-
expect(greedyJumpGame([1, 0])).toBeTruthy();
6-
expect(greedyJumpGame([100, 0])).toBeTruthy();
7-
expect(greedyJumpGame([2, 3, 1, 1, 4])).toBeTruthy();
8-
expect(greedyJumpGame([1, 1, 1, 1, 1])).toBeTruthy();
9-
expect(greedyJumpGame([1, 1, 1, 10, 1])).toBeTruthy();
10-
expect(greedyJumpGame([1, 5, 2, 1, 0, 2, 0])).toBeTruthy();
5+
expect(greedyJumpGame([1, 0])).toBe(true);
6+
expect(greedyJumpGame([100, 0])).toBe(true);
7+
expect(greedyJumpGame([2, 3, 1, 1, 4])).toBe(true);
8+
expect(greedyJumpGame([1, 1, 1, 1, 1])).toBe(true);
9+
expect(greedyJumpGame([1, 1, 1, 10, 1])).toBe(true);
10+
expect(greedyJumpGame([1, 5, 2, 1, 0, 2, 0])).toBe(true);
1111

12-
expect(greedyJumpGame([1, 0, 1])).toBeFalsy();
13-
expect(greedyJumpGame([3, 2, 1, 0, 4])).toBeFalsy();
14-
expect(greedyJumpGame([0, 0, 0, 0, 0])).toBeFalsy();
15-
expect(greedyJumpGame([5, 4, 3, 2, 1, 0, 0])).toBeFalsy();
12+
expect(greedyJumpGame([1, 0, 1])).toBe(false);
13+
expect(greedyJumpGame([3, 2, 1, 0, 4])).toBe(false);
14+
expect(greedyJumpGame([0, 0, 0, 0, 0])).toBe(false);
15+
expect(greedyJumpGame([5, 4, 3, 2, 1, 0, 0])).toBe(false);
1616
});
1717
});

src/data-structures/bloom-filter/__test__/BloomFilter.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ describe('BloomFilter', () => {
5353
it('should insert strings correctly and return true when checking for inserted values', () => {
5454
people.forEach(person => bloomFilter.insert(person));
5555

56-
expect(bloomFilter.mayContain('Bruce Wayne')).toBeTruthy();
57-
expect(bloomFilter.mayContain('Clark Kent')).toBeTruthy();
58-
expect(bloomFilter.mayContain('Barry Allen')).toBeTruthy();
56+
expect(bloomFilter.mayContain('Bruce Wayne')).toBe(true);
57+
expect(bloomFilter.mayContain('Clark Kent')).toBe(true);
58+
expect(bloomFilter.mayContain('Barry Allen')).toBe(true);
5959

60-
expect(bloomFilter.mayContain('Tony Stark')).toBeFalsy();
60+
expect(bloomFilter.mayContain('Tony Stark')).toBe(false);
6161
});
6262
});

0 commit comments

Comments
 (0)