Skip to content

Instantly share code, notes, and snippets.

@hawaijar
Created August 21, 2022 06:53
Show Gist options
  • Save hawaijar/e5be308261b30955feb45ce7134b1bad to your computer and use it in GitHub Desktop.
Save hawaijar/e5be308261b30955feb45ce7134b1bad to your computer and use it in GitHub Desktop.
Test cases for Quick, Merge sorts
import { quickSort, mergeSort } from "../index";
describe("QuickSort Testing", () => {
it("should sort array[1,3,4,5,2,1]", () => {
const array = [1, 3, 4, 5, 2, 1];
const sortedArray = array.sort((a, b) => a - b);
quickSort(array);
expect(array).toEqual(sortedArray);
});
it("should sort array[5, 4, 3, 2, 1, 0]", () => {
const array = [5, 4, 3, 2, 1, 0];
const sortedArray = array.sort((a, b) => a - b);
quickSort(array);
expect(array).toEqual(sortedArray);
});
it("should sort array[-5, -4, -13, -2, -1, 10]", () => {
const array = [-5, -4, -13, -2, -1, 10];
const sortedArray = array.sort((a, b) => a - b);
quickSort(array);
expect(array).toEqual(sortedArray);
});
});
describe("MergeSort Testing", () => {
it("should sort array[1,3,4,5,2,1]", () => {
const array = [1, 3, 4, 5, 2, 1];
const sortedArray = array.sort((a, b) => a - b);
mergeSort(array);
expect(array).toEqual(sortedArray);
});
it("should sort array[5, 4, 3, 2, 1, 0]", () => {
const array = [5, 4, 3, 2, 1, 0];
const sortedArray = array.sort((a, b) => a - b);
mergeSort(array);
expect(array).toEqual(sortedArray);
});
it("should sort array[-5, -4, -13, -2, -1, 10]", () => {
const array = [-5, -4, -13, -2, -1, 10];
const sortedArray = array.sort((a, b) => a - b);
mergeSort(array);
expect(array).toEqual(sortedArray);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment