Skip to content

Commit ec5c781

Browse files
committed
Set up Deno testing
1 parent 24ae46c commit ec5c781

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

Medium/LongestPalindromicSubstring.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
/*
2-
* Problem: Longest Palindromic Substring
2+
* Problem: 5. Longest Palindromic Substring
33
* Acceptance Rate: 31.0%
44
* URL: https://leetcode.com/problems/longest-palindromic-substring/
55
*
66
* Runtime: 96 ms, faster than 96.82% of TypeScript online submissions for Longest Palindromic Substring.
77
* Memory Usage: 41.9 MB, less than 65.68% of TypeScript online submissions for Longest Palindromic Substring.
88
*/
99

10-
export default class Solution {
10+
export default function longestPalindromeIn(s: string): string {
11+
// let result = Solution.findLongestPalindrome(s);
12+
// console.log(s, "->", result);
13+
// return result;
14+
15+
return Solution.findLongestPalindrome(s);
16+
};
17+
18+
class Solution {
1119

1220
private static startIndex: number;
1321
private static palindromeLength: number;
@@ -26,13 +34,13 @@ export default class Solution {
2634
return s.substring(Solution.startIndex, Solution.startIndex + Solution.palindromeLength);
2735
};
2836

29-
private static extendPalindromeEvenLength(s: string, startingIndex: number) {
30-
let left = startingIndex, right = startingIndex+1;
37+
private static extendPalindromeOddLength(s: string, startingIndex: number) {
38+
let left = startingIndex, right = startingIndex;
3139
Solution.extendPalindrome(s, left, right);
3240
}
3341

34-
private static extendPalindromeOddLength(s: string, startingIndex: number) {
35-
let left = startingIndex, right = startingIndex;
42+
private static extendPalindromeEvenLength(s: string, startingIndex: number) {
43+
let left = startingIndex, right = startingIndex+1;
3644
Solution.extendPalindrome(s, left, right);
3745
}
3846

@@ -65,14 +73,6 @@ export default class Solution {
6573
}
6674
}
6775

68-
function longestPalindromeIn(s: string): string {
69-
let result = Solution.findLongestPalindrome(s);
70-
71-
console.log(s, "->", result);
72-
73-
return result;
74-
};
75-
7676
//---------------------------------------------------------------------
7777
// ---------- MAIN PROGRAM ----------
7878
//---------------------------------------------------------------------
@@ -82,7 +82,7 @@ if(import.meta.main) {
8282
longestPalindromeIn("cbbd");
8383
longestPalindromeIn("weloveracecars");
8484

85-
// RUN: deno run Medium/LongestPalindromicSubstring.ts
85+
// RUN: deno run medium/LongestPalindromicSubstring.ts
8686
}
8787

8888
// --------------------------- Terminal Output: ---------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { assertEquals, assertNotEquals } from '../../test_deps.ts';
2+
3+
import longestPalindromeIn from "../LongestPalindromicSubstring.ts";
4+
5+
6+
// RUN: deno test medium/test/LongestPalindromicSubstring.test.ts
7+
8+
//---------------------------------------------------------------------
9+
// ---------- UNIT TESTS ----------
10+
//---------------------------------------------------------------------
11+
12+
Deno.test({
13+
name: "babad -> bab",
14+
fn() {
15+
assertEquals(longestPalindromeIn("babad"), "bab");
16+
}
17+
});
18+
19+
20+
Deno.test({
21+
name: "babad -> !aba",
22+
fn() {
23+
assertNotEquals(longestPalindromeIn("babad"), "aba");
24+
}
25+
});
26+
27+
Deno.test({
28+
name: "cbbd -> bb",
29+
fn() {
30+
assertEquals(longestPalindromeIn("cbbd"), "bb");
31+
}
32+
});
33+
34+
Deno.test({
35+
name: "weloveracecars -> racecar",
36+
fn() {
37+
assertEquals(longestPalindromeIn("weloveracecars"), "racecar");
38+
}
39+
});

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Leetcode Solutions in TypeScript
2+
3+
## Environment
4+
- <span title="July 2021">Deno 1.12.0</span>
5+
- V8 9.2.230.14
6+
- TypeScript 4.3.2
7+
8+
## Problems Completed
9+
10+
### Medium
11+
- <span title="Acceptance Rate: 31.0%">5. Longest Palindromic Substring</span>

test_deps.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// ----------------------- Testing Library -----------------------
2+
export {
3+
assert,
4+
assertEquals,
5+
assertNotEquals,
6+
} from "https://deno.land/std@0.101.0/testing/asserts.ts";

0 commit comments

Comments
 (0)