Skip to content

Commit 8c45ad5

Browse files
Move to tests - Round 2
1 parent d4c42ab commit 8c45ad5

9 files changed

+52
-28
lines changed

LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js

-2
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,3 @@ var main = function() {
126126
}
127127

128128
module.exports.main = main;
129-
130-
main();

LeetcodeProblems/Regular_Expression_Matching.js

-1
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,4 @@ var main = function(){
9898
console.log(isMatch("mississippi", "mis*is*p*."));
9999
}
100100

101-
main();
102101
module.exports.main = main;

LeetcodeProblems/Simplify_Path.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ In this case, you should return "/".
1919
Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
2020
In this case, you should ignore redundant slashes and return "/home/foo".
2121
*/
22+
const assert = require('assert');
2223

2324
var simplifyPath = function(path) {
2425
var queue = [];
@@ -66,6 +67,7 @@ var main = function(){
6667
console.log(simplifyPath("/a/./b/../../c/")); // => "/c"
6768
console.log(simplifyPath("/a/../../b/../c//.//")); // => "/c"
6869
console.log(simplifyPath("/a//b////c/d//././/..")) // => "/a/b/c"
70+
6971
}
7072

7173
module.exports.main = main

LeetcodeProblems/Spiral_Matrix.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Input:
2323
]
2424
Output: [1,2,3,4,8,12,11,10,9,5,6,7]
2525
*/
26+
const assert = require('assert');
2627

2728
/**
2829
* @param {number[][]} matrix
@@ -72,8 +73,11 @@ var main = function() {
7273
[ 4, 5, 6 ],
7374
[ 7, 8, 9 ]
7475
]
75-
76-
console.log(spiralOrder(matrix));
76+
77+
assert.deepEqual(
78+
spiralOrder(matrix),
79+
[1, 2, 3, 6, 9, 8, 7, 4, 5]
80+
)
7781
}
7882

7983
module.exports.main = main;

LeetcodeProblems/Subarray_Sum_Equals_K.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Note:
1212
The length of the array is in range [1, 20,000].
1313
The range of numbers in the array is [-1000, 1000] and the range of the integer k is [-1e7, 1e7].
1414
*/
15-
15+
const assert = require('assert');
1616

1717
/**
1818
* @param {number[]} nums
@@ -61,11 +61,14 @@ var subarraySum2 = function(nums, k) {
6161
};
6262

6363
var main = function() {
64-
console.log(subarraySum([1,1,1], 2));
65-
console.log(subarraySum([1], 0));
66-
console.log(subarraySum([0], 0));
67-
console.log(subarraySum([0,0,0,0,0], 0));
64+
test();
6865
}
6966

70-
module.exports.main = main;
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+
}
7173

74+
module.exports.main = main;

LeetcodeProblems/Subsets.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Output:
2222
]
2323
*/
2424

25+
const assert = require('assert');
26+
2527
var subsets = function(nums) {
2628
var ret = [];
2729

@@ -37,7 +39,20 @@ var subsets = function(nums) {
3739
};
3840

3941
function main() {
40-
console.log(subsets([1,2,3]));
42+
test();
4143
}
42-
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+
4358
module.exports.main = main;

LeetcodeProblems/Sum_Of_Square_Numbers.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Input: 3
1414
Output: False
1515
*/
1616

17+
const assert = require('assert');
18+
1719
/**
1820
* @param {number} c
1921
* @return {boolean}
@@ -34,12 +36,17 @@ var judgeSquareSum = function(c) {
3436
};
3537

3638
var main = function() {
37-
console.log(judgeSquareSum(0));
38-
console.log(judgeSquareSum(1));
39-
console.log(judgeSquareSum(5));
40-
console.log(judgeSquareSum(16));
41-
console.log(judgeSquareSum(24));
42-
console.log(judgeSquareSum(25));
39+
test();
40+
}
41+
42+
var test = function() {
43+
assert.strictEqual(judgeSquareSum(0), true);
44+
assert.strictEqual(judgeSquareSum(1), true);
45+
assert.strictEqual(judgeSquareSum(5), true);
46+
assert.strictEqual(judgeSquareSum(16), true);
47+
assert.strictEqual(judgeSquareSum(24), false);
48+
assert.strictEqual(judgeSquareSum(25), true);
4349
}
4450

4551
module.exports.main = main;
52+

LeetcodeProblems/Swap_Nodes_In_Pairs.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,14 @@ var swapPairs = function(head) {
5050
};
5151

5252
var main = function() {
53-
54-
ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([2])), [2, 3]);
5553
test();
5654
}
5755

5856
var test = function () {
59-
// TODOOOOOOOOOO
60-
// ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([1,2,3,4])), [2,1,4,3]);
61-
// ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([])), []);
62-
// ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([1])), [1]);
63-
ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([1,2])), [2, 3]);
57+
ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([1,2,3,4])), [2,1,4,3]);
58+
ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([])), []);
59+
ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([1])), [1]);
60+
ListNodeTestHelper.assertList(swapPairs(ListNode.linkenList([1,2])), [2, 1]);
6461
}
6562

6663
module.exports.main = main;

LeetcodeProblems/Unique_Binary_Search_Trees.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,4 @@ var test = function () {
130130
assert.strictEqual(numTrees3(5), 42);
131131
}
132132

133-
module.exports.main = main
134-
main();
133+
module.exports.main = main

0 commit comments

Comments
 (0)