Skip to content

Commit 142a6a4

Browse files
Move tests to its own files Round 7
1 parent d3a1949 commit 142a6a4

33 files changed

+81
-262
lines changed

LeetcodeProblems/Best_Time_To_Buy_And_Sell_Stock_II.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,4 @@ var maxProfit = function(prices) {
5555
return profit;
5656
};
5757

58-
var main = function() {
59-
test();
60-
}
61-
62-
function test() {
63-
assert.equal(maxProfit([7,1,5,3,6,4]), 7);
64-
assert.equal(maxProfit([7,1,5,3320,6,4]), 3319);
65-
}
66-
6758
module.exports.maxProfit = maxProfit;

LeetcodeProblems/Escape_The_Ghosts.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,4 @@ var getDistance = function(a, b) {
5959
return horizontalMoves + verticalMoves;
6060
}
6161

62-
var main = function() {
63-
test();
64-
}
65-
66-
function test() {
67-
assert.equal(escapeGhosts([[1, 0], [0, 3]], [0, 1]), true);
68-
assert.equal(escapeGhosts([[1, 0]], [2, 0]), false);
69-
assert.equal(escapeGhosts([[2, 0]], [1, 0]), true);
70-
}
71-
72-
module.exports.main = main
62+
module.exports.escapeGhosts = escapeGhosts;

LeetcodeProblems/SearchIng_Rotated_Sorted_Array.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,4 @@ var searchAux = function(nums, target, start, end) {
5454
}
5555
}
5656

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

LeetcodeProblems/Search_a_2D_Matrix.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ target = 13
2828
Output: false
2929
*/
3030

31-
3231
/**
3332
* @param {number[][]} matrix
3433
* @param {number} target
@@ -58,17 +57,5 @@ var searchMatrixAux = function(matrix, firstRow, lastRow, target) {
5857

5958
return false;
6059
};
61-
62-
var main = function(){
63-
test();
64-
}
65-
66-
var test = function() {
67-
assert.equal(searchMatrix([], 0), false);
68-
assert.equal(searchMatrix([[1], [3]], 3), true);
69-
assert.equal(searchMatrix([[1], [3]], 1), true);
70-
const matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,50]];
71-
assert.equal(searchMatrix(matrix, 3), true);
72-
}
7360

74-
module.exports.main = main;
61+
module.exports.searchMatrix = searchMatrix;

LeetcodeProblems/Search_a_2D_Matrix_II.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Given target = 5, return true.
1818
Given target = 20, return false.
1919
*/
2020

21-
2221
/**
2322
* @param {number[][]} matrix
2423
* @param {number} target
@@ -43,22 +42,4 @@ var searchMatrix = function(matrix, target) {
4342
return false;
4443
};
4544

46-
const matrix1 = [
47-
[1,4,7, 11,15],
48-
[2,5,8, 12,19],
49-
[3,6,9, 16,22],
50-
[10,13,14, 17,24],
51-
[18,21,23, 26,30]
52-
];
53-
54-
var main = function(n) {
55-
test();
56-
}
57-
58-
var test = function() {
59-
assert.equal(searchMatrix(matrix1, 5), true);
60-
assert.equal(searchMatrix(matrix1, 0), false);
61-
assert.equal(searchMatrix(matrix1, 15), true);
62-
}
63-
64-
module.exports.main = main;
45+
module.exports.searchMatrix = searchMatrix;

LeetcodeProblems/Set_Matrix_Zeroes.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ 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-
43-
4442
/**
4543
* @param {number[][]} matrix
4644
* @return {void} Do not return anything, modify matrix in-place instead.
@@ -110,15 +108,4 @@ var fillCol = function(matrix, col) {
110108
matrix[i][col] = 0;
111109
}
112110

113-
var main = function() {
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-
);
122-
}
123-
124-
module.exports.main = main;
111+
module.exports.setZeroes = setZeroes;

LeetcodeProblems/Simplify_Path.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,4 @@ var simplifyPath = function(path) {
6060
return (ret.length == 0) ? "/" : ret;
6161
};
6262

63-
var main = function(){
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"
74-
}
75-
76-
module.exports.main = main
63+
module.exports.simplifyPath = simplifyPath;

LeetcodeProblems/Spiral_Matrix.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,4 @@ var printRect = function(matrix, i, rowLength, colLength, retArray) {
6767
}
6868
}
6969

70-
var main = function() {
71-
const matrix = [
72-
[ 1, 2, 3 ],
73-
[ 4, 5, 6 ],
74-
[ 7, 8, 9 ]
75-
]
76-
77-
assert.deepEqual(
78-
spiralOrder(matrix),
79-
[1, 2, 3, 6, 9, 8, 7, 4, 5]
80-
)
81-
}
82-
83-
module.exports.main = main;
70+
module.exports.spiralOrder = spiralOrder;

LeetcodeProblems/Subarray_Sum_Equals_K.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,4 @@ var subarraySum2 = function(nums, k) {
6060
return ret;
6161
};
6262

63-
var main = function() {
64-
test();
65-
}
66-
67-
var test = function() {
68-
assert.strictEqual(subarraySum([1,1,1], 2), 2);
69-
assert.strictEqual(subarraySum([1], 0), 0);
70-
assert.strictEqual(subarraySum([0], 0), 1);
71-
assert.strictEqual(subarraySum([0,0,0,0,0], 0), 15);
72-
}
73-
74-
module.exports.main = main;
63+
module.exports.subarraySum = subarraySum;

LeetcodeProblems/Subsets.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,4 @@ var subsets = function(nums) {
3838
return subsetByPosition(nums, 0, []);
3939
};
4040

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

0 commit comments

Comments
 (0)