Skip to content

Commit d3a1949

Browse files
Move tests to its own files Round 6
1 parent b68f155 commit d3a1949

20 files changed

+26
-190
lines changed

LeetcodeProblems/Number_of_Islands.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,4 @@ var colorIsland = function(grid, i, j, rowsCount, columnsCount) {
6161
colorIsland(grid, i, j + 1, rowsCount, columnsCount);
6262
}
6363

64-
var main = function() {
65-
test();
66-
}
67-
68-
function test() {
69-
assert.equal(numIslands([[1]]), 1);
70-
assert.equal(numIslands([]), 0);
71-
assert.equal(numIslands(
72-
[
73-
["1","1","1","1","0"],
74-
["1","1","0","1","0"],
75-
["1","1","0","0","0"],
76-
["0","0","0","0","0"]
77-
],
78-
),
79-
1
80-
);
81-
}
82-
83-
module.exports.main = main;
64+
module.exports.numIslands = numIslands;

LeetcodeProblems/Number_of_Segments_in_a_String.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,4 @@ var countSegments = function(s) {
3333
return count;
3434
};
3535

36-
function main() {
37-
test();
38-
}
39-
40-
function test() {
41-
assert.equal(countSegments(" "), 0);
42-
assert.equal(countSegments(" "), 0);
43-
assert.equal(countSegments("ab cd ef"), 3);
44-
assert.equal(countSegments(" ab cd ef"), 3);
45-
assert.equal(countSegments("ab cd ef "), 3);
46-
assert.equal(countSegments(" ab cd ef "), 3);
47-
}
48-
49-
module.exports.main = main
36+
module.exports.countSegments = countSegments;

LeetcodeProblems/Permutations.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Output:
1818
]
1919
*/
2020

21-
2221
var permute = function(nums) {
2322
return permuteAux(nums, 0, [], new Set());
2423
};
@@ -39,24 +38,4 @@ var permuteAux = function(nums, pos, currentSol, set) {
3938
return ret;
4039
}
4140

42-
var main = function() { test();
43-
}
44-
45-
function test() {
46-
// assert.deepEqual(
47-
assert.deepEqual(permute([]), [ [] ]);
48-
assert.deepEqual(permute([1]), [ [ 1 ] ]);
49-
assert.deepEqual(
50-
permute([1,2,3]),
51-
[
52-
[ 1, 2, 3 ],
53-
[ 1, 3, 2 ],
54-
[ 2, 1, 3 ],
55-
[ 2, 3, 1 ],
56-
[ 3, 1, 2 ],
57-
[ 3, 2, 1 ]
58-
]
59-
);
60-
}
61-
62-
module.exports.main = main;
41+
module.exports.permute = permute;

LeetcodeProblems/Permutations_II.js

+1-32
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,4 @@ var permuteUniqueAux = function(n, map, currentSol) {
4646
return ret;
4747
};
4848

49-
var main = function() {
50-
test();
51-
}
52-
53-
function test() {
54-
assert.deepEqual(
55-
permuteUnique([1,1,2]),
56-
[ [ '1', '1', '2' ], [ '1', '2', '1' ], [ '2', '1', '1' ] ]
57-
);
58-
assert.deepEqual(
59-
permuteUnique([1,3,2,1]),
60-
[
61-
[ '1', '1', '2', '3' ],
62-
[ '1', '1', '3', '2' ],
63-
[ '1', '2', '1', '3' ],
64-
[ '1', '2', '3', '1' ],
65-
[ '1', '3', '1', '2' ],
66-
[ '1', '3', '2', '1' ],
67-
[ '2', '1', '1', '3' ],
68-
[ '2', '1', '3', '1' ],
69-
[ '2', '3', '1', '1' ],
70-
[ '3', '1', '1', '2' ],
71-
[ '3', '1', '2', '1' ],
72-
[ '3', '2', '1', '1' ]
73-
]
74-
);
75-
assert.deepEqual(permuteUnique([]), [ [] ]);
76-
77-
assert.deepEqual(permuteUnique([1,1]), [ [ '1', '1' ] ]);
78-
}
79-
80-
module.exports.main = main;
49+
module.exports.permuteUnique = permuteUnique;

LeetcodeProblems/Permutations_With_Duplicates.js

+1-25
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,4 @@ var subsetWithoutDuplicatesAux = function(nums, current, sol) {
2929
})
3030
}
3131

32-
function main() {
33-
test();
34-
}
35-
36-
var test = function() {
37-
assert.deepEqual(
38-
subsetWithoutDuplicates([1,1,2,3]),
39-
[
40-
[ 1, 1, 2, 3 ],
41-
[ 1, 1, 3, 2 ],
42-
[ 1, 2, 1, 3 ],
43-
[ 1, 2, 3, 1 ],
44-
[ 1, 3, 1, 2 ],
45-
[ 1, 3, 2, 1 ],
46-
[ 2, 1, 1, 3 ],
47-
[ 2, 1, 3, 1 ],
48-
[ 2, 3, 1, 1 ],
49-
[ 3, 1, 1, 2 ],
50-
[ 3, 1, 2, 1 ],
51-
[ 3, 2, 1, 1 ]
52-
]
53-
);
54-
}
55-
main();
56-
module.exports.main = main;
32+
module.exports.subsetWithoutDuplicates = subsetWithoutDuplicates;

LeetcodeProblems/Permutations_Without_Duplicates.js

+6-25
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,26 @@ Output:
1818
]
1919
*/
2020

21-
22-
// Permutations wihto
23-
var subsetWithDuplicates = function(nums) {
21+
// Permutations without Duplicates
22+
var subsetWithoutDuplicates = function(nums) {
2423
if(nums.lenght == 0){
2524
return;
2625
}
2726
var solution = [];
28-
subsetWithDuplicatesAux(nums, [], solution);
27+
subsetWithoutDuplicatesAux(nums, [], solution);
2928
return solution;
3029
}
3130

32-
var subsetWithDuplicatesAux = function(nums, current, sol) {
31+
var subsetWithoutDuplicatesAux = function(nums, current, sol) {
3332
if(nums.length == 0){
3433
sol.push(current);
3534
}
3635

3736
for(var i = 0; i < nums.length; i++) {
3837
var newCurrent = [...current, nums[i]]
3938
var newNums = nums.filter(function(num, index) { return index !== i });
40-
subsetWithDuplicatesAux(newNums, newCurrent, sol);
39+
subsetWithoutDuplicatesAux(newNums, newCurrent, sol);
4140
}
4241
}
43-
44-
function main() {
45-
test();
46-
}
47-
48-
var test = function() {
49-
assert.deepEqual(
50-
subsetWithDuplicates([1,2,3]),
51-
[
52-
[ 1, 2, 3 ],
53-
[ 1, 3, 2 ],
54-
[ 2, 1, 3 ],
55-
[ 2, 3, 1 ],
56-
[ 3, 1, 2 ],
57-
[ 3, 2, 1 ]
58-
]
59-
);
60-
}
6142

62-
module.exports.main = main;
43+
module.exports.subsetWithoutDuplicates = subsetWithoutDuplicates;

LeetcodeProblems/Regular_Expression_Matching.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,4 @@ var canBeZero = function(pattern, posPat) {
9090
return posPat == pattern.length;
9191
}
9292

93-
var main = function(){
94-
test();
95-
}
96-
97-
var test = function() {
98-
assert.equal(isMatch("aa", "a"), false);
99-
assert.equal(isMatch("aa", "a*"), true);
100-
assert.equal(isMatch("a","ab*"), true);
101-
assert.equal(isMatch("ab", ".*"), true);
102-
assert.equal(isMatch("aab", "c*a*b"), true);
103-
assert.equal(isMatch("mississippi", "mis*is*p*."), false);
104-
}
105-
106-
module.exports.main = main;
93+
module.exports.isMatch = isM.isMatch;

LeetcodeProblems/Remove_Invalid_Parentheses.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Input: ")("
2020
Output: [""]
2121
*/
2222

23-
2423
/**
2524
* @param {string} s
2625
* @return {string[]}
@@ -70,15 +69,4 @@ var isValid = function(s) {
7069
return leftCount === 0;
7170
}
7271

73-
var main = function() {
74-
test();
75-
}
76-
77-
var test = function() {
78-
assert.equal(removeInvalidParentheses("))))(()"), "()");
79-
assert.equal(removeInvalidParentheses("(()"), "()");
80-
assert.equal(removeInvalidParentheses("(d))()"), "(d)()");
81-
assert.equal(removeInvalidParentheses("(())"), "(())");
82-
}
83-
84-
module.exports.main = main;
72+
module.exports.removeInvalidParentheses = removeInvalidParentheses;

LeetcodeProblems/Restore_IP_Addresses.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Input: "25525511135"
1010
Output: ["255.255.11.135", "255.255.111.35"]
1111
*/
1212

13-
1413
var restoreIpAddresses = function(s) {
1514
var restore = restoreInputBits("", s, 4);
1615

@@ -41,13 +40,4 @@ var restoreInputBits = function(partial, s, num) {
4140
return [...oneNum, ...twoNums, ...threeNums];
4241
}
4342

44-
var main = function() {
45-
test();
46-
}
47-
48-
var test = function() {
49-
assert.deepEqual(restoreIpAddresses("010010"), [ '0.10.0.10', '0.100.1.0']);
50-
assert.deepEqual(restoreIpAddresses("25525511135"), [ '255.255.11.135', '255.255.111.35' ]);
51-
}
52-
53-
module.exports.main = main
43+
module.exports.restoreIpAddresses = restoreIpAddresses;

LeetcodeProblems/Reverse_String_II.js

+1-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ The string consists of lower English letters only.
1111
Length of the given string and k will in the range [1, 10000]
1212
*/
1313

14-
1514
var reverseStr = function(s, k) {
1615
if(k <= 1)
1716
return s;
@@ -39,15 +38,4 @@ var reverse = function(s, start, end) {
3938
return ret;
4039
}
4140

42-
var main = function(){
43-
test();
44-
}
45-
46-
var test = function() {
47-
assert.equal(reverseStr("abcdefg", 2), "bacdfeg");
48-
assert.equal(reverseStr("abcdefg", 3), "cbadefg");
49-
assert.equal(reverseStr("abcdefg", 1), "abcdefg");
50-
assert.equal(reverseStr("abcdefg", 0), "abcdefg");
51-
}
52-
53-
module.exports.main = main
41+
module.exports.reverseStr = reverseStr;

LeetcodeProblemsTests/Number_of_Islands_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const numIslands = require('../LeetcodeProblems/Number_of_Islands').numIslands;
23

34
function test() {
45
assert.equal(numIslands([[1]]), 1);

LeetcodeProblemsTests/Number_of_Segments_in_a_String_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const countSegments = require('../LeetcodeProblems/Number_of_Segments_in_a_String').countSegments;
23

34
function test() {
45
assert.equal(countSegments(" "), 0);

LeetcodeProblemsTests/Permutations_II_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const permuteUnique = require('../LeetcodeProblems/Permutations_II').permuteUnique;
23

34
function test() {
45
assert.deepEqual(

LeetcodeProblemsTests/Permutations_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const permute = require('../LeetcodeProblems/Permutations').permute;
23

34
function test() {
45
assert.deepEqual(permute([]), [ [] ]);

LeetcodeProblemsTests/Permutations_With_Duplicates_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const subsetWithoutDuplicates = require('../LeetcodeProblems/Permutations_With_Duplicates').subsetWithoutDuplicates;
23

34
var test = function() {
45
assert.deepEqual(

LeetcodeProblemsTests/Permutations_Without_Duplicates_Test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const assert = require('assert');
2+
const subsetWithoutDuplicates = require('../LeetcodeProblems/Permutations_Without_Duplicates').subsetWithoutDuplicates;
23

34
var test = function() {
45
assert.deepEqual(
5-
subsetWithDuplicates([1,2,3]),
6+
subsetWithoutDuplicates([1,2,3]),
67
[
78
[ 1, 2, 3 ],
89
[ 1, 3, 2 ],

LeetcodeProblemsTests/Regular_Expression_Matching_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const isMatch = require('../LeetcodeProblems/Regular_Expression_Matching').isMatch;
23

34
var test = function() {
45
assert.equal(isMatch("aa", "a"), false);

LeetcodeProblemsTests/Remove_Invalid_Parentheses_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const removeInvalidParentheses = require('../LeetcodeProblems/Remove_Invalid_Parentheses').removeInvalidParentheses;
23

34
var test = function() {
45
assert.equal(removeInvalidParentheses("))))(()"), "()");

LeetcodeProblemsTests/Restore_IP_Addresses_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const restoreIpAddresses = require('../LeetcodeProblems/Restore_IP_Addresses').restoreIpAddresses;
23

34
var test = function() {
45
assert.deepEqual(restoreIpAddresses("010010"), [ '0.10.0.10', '0.100.1.0']);

LeetcodeProblemsTests/Reverse_String_II_Test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = require('assert');
2+
const reverseStr = require('../LeetcodeProblems/Reverse_String_II').reverseStr;
23

34
var test = function() {
45
assert.equal(reverseStr("abcdefg", 2), "bacdfeg");

0 commit comments

Comments
 (0)