Skip to content

Commit b12ad93

Browse files
Move to tests - Round 3
1 parent 8c45ad5 commit b12ad93

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

LeetcodeProblems/SearchIng_Rotated_Sorted_Array.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Input: nums = [4,5,6,7,0,1,2], target = 3
2121
Output: -1
2222
2323
*/
24+
const assert = require('assert');
2425

2526
/**
2627
* @param {number[]} nums
@@ -54,7 +55,11 @@ var searchAux = function(nums, target, start, end) {
5455
}
5556

5657
var main = function(n) {
57-
console.log(search([4,5,6,7,0,1,2], 5));
58+
test();
5859
}
5960

60-
module.exports.main = main;
61+
var test = function(n) {
62+
assert.equal(search([4,5,6,7,0,1,2], 5), 1);
63+
}
64+
65+
module.exports.main = main;

LeetcodeProblems/Set_Matrix_Zeroes.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ A simple improvement uses O(m + n) space, but still not the best solution.
3939
Could you devise a constant space solution?
4040
*/
4141

42+
const assert = require('assert');
43+
4244
/**
4345
* @param {number[][]} matrix
4446
* @return {void} Do not return anything, modify matrix in-place instead.
@@ -94,6 +96,8 @@ var setZeroes = function(matrix) {
9496

9597
fillCol(matrix, pivotCol);
9698
fillRow(matrix, pivotRow);
99+
100+
return matrix;
97101
};
98102

99103
var fillRow = function(matrix, row) {
@@ -107,7 +111,14 @@ var fillCol = function(matrix, col) {
107111
}
108112

109113
var main = function() {
110-
console.log(setZeroes([[1,1,1],[1,0,1],[1,1,1]]));
114+
test();
115+
}
116+
117+
var test = function() {
118+
assert.deepEqual(
119+
setZeroes([[1,1,1],[1,0,1],[1,1,1]]),
120+
[[1, 0, 1], [0, 0, 0], [1, 0, 1]]
121+
);
111122
}
112123

113124
module.exports.main = main;

LeetcodeProblems/Simplify_Path.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ var simplifyPath = function(path) {
6161
};
6262

6363
var main = function(){
64-
console.log(simplifyPath("/../c"));
65-
console.log(simplifyPath("/.."));
66-
console.log(simplifyPath("/home/")); // => "/home"
67-
console.log(simplifyPath("/a/./b/../../c/")); // => "/c"
68-
console.log(simplifyPath("/a/../../b/../c//.//")); // => "/c"
69-
console.log(simplifyPath("/a//b////c/d//././/..")) // => "/a/b/c"
70-
64+
test();
65+
}
66+
67+
var test = function() {
68+
assert.equal(simplifyPath("/../c"), "/c");
69+
assert.equal(simplifyPath("/.."), "/");
70+
assert.equal(simplifyPath("/home/"), "/home"); // => "/home"
71+
assert.equal(simplifyPath("/a/./b/../../c/"), "/c"); // => "/c"
72+
assert.equal(simplifyPath("/a/../../b/../c//.//"), "/c"); // => "/c"
73+
assert.equal(simplifyPath("/a//b////c/d//././/.."), "/a/b/c") // => "/a/b/c"
7174
}
7275

7376
module.exports.main = main

0 commit comments

Comments
 (0)