Skip to content

Tests #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 6, 2020
Prev Previous commit
Next Next commit
Move tests to its own files Round 3
  • Loading branch information
ignacio-chiazzo committed Sep 6, 2020
commit 125ff74590a15093574b865b87e9e72cbf536fbc
22 changes: 0 additions & 22 deletions LeetcodeProblems/Deletion_Distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,6 @@ var min = function(a, b) {
return (a < b) ? a : b;
}

function main() {
test();
}

function test() {
assert.equal(deletionDistance("dog", "frog"), 3);
assert.equal(deletionDistance("some", "some"), 0);
assert.equal(deletionDistance("some", "thing"), 9);
assert.equal(deletionDistance("", ""), 0);

assert.equal(deletionDistance2("dog", "frog"), 3);
assert.equal(deletionDistance2("some", "some"), 0);
assert.equal(deletionDistance2("some", "thing"), 9);
assert.equal(deletionDistance2("", ""), 0);

assert.equal(deletionDistanceDP("dog", "frog"), 3);
assert.equal(deletionDistanceDP("some", "some"), 0);
assert.equal(deletionDistanceDP("some", "thing"), 9);
assert.equal(deletionDistanceDP("", ""), 0);
}

module.exports.deletionDistance = deletionDistance;
module.exports.deletionDistance2 = deletionDistance2;
module.exports.deletionDistanceDP = deletionDistanceDP;

13 changes: 1 addition & 12 deletions LeetcodeProblems/Flood_Fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,4 @@ var floodFill = function(image, sr, sc, newColor) {
return image;
};

function main() {
test();
}

function test() {
assert.deepEqual(
[ [ 2, 2, 2 ], [ 2, 2, 0 ], [ 2, 0, 1 ] ],
floodFill([[1,1,1],[1,1,0],[1,0,1]], 1, 1, 2)
);
}

module.exports.main = main;
module.exports.floodFill = floodFill;
16 changes: 1 addition & 15 deletions LeetcodeProblems/Generate_Parenthesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,4 @@ var insertAt = function(str, position, value) {
return str.slice(0, position) + value + str.slice(position);
}

function main() {
console.log("Approach 1");
[0, 1, 2, 3].forEach(function(elem) {
console.log(`${elem}: ${generateParenthesisApproach2(elem)}`);
})

console.log("-------------");

console.log("Approach 2");
[0, 1, 2, 3].forEach(function(elem) {
console.log(`${elem}: ${generateParenthesisApproach2(elem)}`);
})
}

module.exports.main = main
module.exports.generateParenthesisApproach2 = generateParenthesisApproach2;
14 changes: 1 addition & 13 deletions LeetcodeProblems/Group_Anagrams.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ All inputs will be in lowercase.
The order of your output does not matter.
*/


var groupAnagrams = function(strs) {
var ret = [];
var hashMap = {};
Expand Down Expand Up @@ -48,15 +47,4 @@ var sortString = function(str) {
return str.split("").sort().join("");
}

var main = function() {
test();
}

function test() {
assert.deepEqual(
groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]),
[ [ 'eat', 'tea', 'ate' ], [ 'tan', 'nat' ], [ 'bat' ] ]
)
}

module.exports.main = main;
module.exports.groupAnagrams = groupAnagrams;
2 changes: 1 addition & 1 deletion LeetcodeProblems/Regular_Expression_Matching.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var main = function(){
test();
}

var test = function(n) {
var test = function() {
assert.equal(isMatch("aa", "a"), false);
assert.equal(isMatch("aa", "a*"), true);
assert.equal(isMatch("a","ab*"), true);
Expand Down
2 changes: 1 addition & 1 deletion LeetcodeProblems/Remove_Invalid_Parentheses.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var main = function() {
test();
}

var test = function(n) {
var test = function() {
assert.equal(removeInvalidParentheses("))))(()"), "()");
assert.equal(removeInvalidParentheses("(()"), "()");
assert.equal(removeInvalidParentheses("(d))()"), "(d)()");
Expand Down
2 changes: 1 addition & 1 deletion LeetcodeProblems/Restore_IP_Addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var main = function() {
test();
}

var test = function(n) {
var test = function() {
assert.deepEqual(restoreIpAddresses("010010"), [ '0.10.0.10', '0.100.1.0']);
assert.deepEqual(restoreIpAddresses("25525511135"), [ '255.255.11.135', '255.255.111.35' ]);
}
Expand Down
2 changes: 1 addition & 1 deletion LeetcodeProblems/Reverse_String_II.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var main = function(){
test();
}

var test = function(n) {
var test = function() {
assert.equal(reverseStr("abcdefg", 2), "bacdfeg");
assert.equal(reverseStr("abcdefg", 3), "cbadefg");
assert.equal(reverseStr("abcdefg", 1), "abcdefg");
Expand Down
2 changes: 1 addition & 1 deletion LeetcodeProblems/Search_a_2D_Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var main = function(){
test();
}

var test = function(n) {
var test = function() {
assert.equal(searchMatrix([], 0), false);
assert.equal(searchMatrix([[1], [3]], 3), true);
assert.equal(searchMatrix([[1], [3]], 1), true);
Expand Down
2 changes: 1 addition & 1 deletion LeetcodeProblems/Search_a_2D_Matrix_II.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var main = function(n) {
test();
}

var test = function(n) {
var test = function() {
assert.equal(searchMatrix(matrix1, 5), true);
assert.equal(searchMatrix(matrix1, 0), false);
assert.equal(searchMatrix(matrix1, 15), true);
Expand Down