Skip to content

[Feat] : Added merge sort #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Sorts/test/MergeSort.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { MergeSort } from "../MergeSort";

describe("Merge Sort", () => {
it("generating array and comparing with sorted array", () => {
it("generating array with length 10 and comparing with sorted array", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't duplicate this code; rather use something like Jest's each, or write your own utility func to test a random sorted array of a given length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if the change works

let arrLen = 10;
let inBuiltSortArr = Array.from(Array(arrLen)).map(x=>Math.random());

let inBuiltSortArr = Array<number>(arrLen)
for (let i = 0; i < arrLen; i++) { inBuiltSortArr[i] = Math.random() }
let mergeSortArray = inBuiltSortArr;

inBuiltSortArr.sort((a, b) => a - b);
expect(MergeSort(mergeSortArray)).toStrictEqual(inBuiltSortArr);
});

it("generating array with length 20000 and comparing with sorted array", () => {
let arrLen = 20000;

let inBuiltSortArr = Array<number>(arrLen)
for (let i = 0; i < arrLen; i++) { inBuiltSortArr[i] = Math.random() }
let mergeSortArray = inBuiltSortArr;

inBuiltSortArr.sort((a,b) => a-b);
inBuiltSortArr.sort((a, b) => a - b);
expect(MergeSort(mergeSortArray)).toStrictEqual(inBuiltSortArr);
});
});