-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
139 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
import { bench, describe } from "vitest"; | ||
|
||
import type { InputTestData } from "@typings/input-data"; | ||
import { twoSum } from ".."; | ||
import { leetcodeProblem } from ".."; | ||
import { TEST_DATA } from "./test-data"; | ||
|
||
const TEST_DATA: InputTestData<{ nums: number[]; target: number }, number[]> = { | ||
input: { nums: [2, 7, 11, 15], target: 9 }, | ||
expected: [0, 1], | ||
}; | ||
const { name, solutions } = leetcodeProblem; | ||
|
||
describe("Two Sum (benchmark)", () => { | ||
const { | ||
input: { nums, target }, | ||
} = TEST_DATA; | ||
|
||
bench(`should find the indices of two numbers that add up to ${target}`, () => { | ||
twoSum(nums, target); | ||
}); | ||
describe(name, () => { | ||
for (const { name, implementation } of solutions) { | ||
bench(name, () => { | ||
for (const { | ||
input: { nums, target }, | ||
} of TEST_DATA) { | ||
implementation(nums, target); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { twoSum } from ".."; | ||
import { leetcodeProblem } from ".."; | ||
import { TEST_DATA } from "./test-data"; | ||
|
||
describe("Two Sum", () => { | ||
for (const { | ||
input: { nums, target }, | ||
expected, | ||
} of TEST_DATA) { | ||
it(`should find the indices of two numbers that add up to ${target}`, () => { | ||
// Validate inputs | ||
expect(nums).toBeDefined(); | ||
expect(target).toBeDefined(); | ||
// Validate output | ||
expect(twoSum(nums, target)).toEqual(expected); | ||
describe(leetcodeProblem.name, () => { | ||
for (const { name, implementation } of leetcodeProblem.solutions) { | ||
describe(name, () => { | ||
for (const { | ||
input: { nums, target }, | ||
expected, | ||
} of TEST_DATA) { | ||
it("should find the indices of two numbers that add up to target", () => { | ||
// Validate inputs | ||
expect(nums).toBeDefined(); | ||
expect(target).toBeDefined(); | ||
// Validate output | ||
expect(implementation(nums, target)).toEqual(expected); | ||
}); | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/arrays/121-best-time-to-buy-and-sell-stock/tests/index.bench.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/arrays/121-best-time-to-buy-and-sell-stock/tests/test-data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/arrays/238-product-of-array-except-self/tests/index.bench.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* Represents a solution to a problem, containing its name and implementation. | ||
*/ | ||
type Solution = { | ||
/** The name of the solution. */ | ||
name: string; | ||
/** The implementation of the solution, which is a function taking any arguments and returning any value. */ | ||
// biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
implementation: (...args: any[]) => any; | ||
}; | ||
|
||
/** | ||
* Represents a problem on LeetCode, containing its name, code, tags, and available solutions. | ||
*/ | ||
export type LeetcodeProblem = { | ||
/** The name of the problem. */ | ||
name: string; | ||
/** The code identifier of the problem on LeetCode. */ | ||
code: string; | ||
/** An array of tags describing the problem. */ | ||
tags: string[]; | ||
/** An array of available solutions for the problem. */ | ||
solutions: Solution[]; | ||
}; |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters