|
| 1 | +import { selectionSort } from "../SelectionSort"; |
| 2 | + |
| 3 | +describe("selectionSort", () => { |
| 4 | + it("should sort an array of integers in ascending order (best case)", () => { |
| 5 | + const sortedArray = [1, 2, 3, 4, 5]; |
| 6 | + const result = selectionSort(sortedArray); |
| 7 | + |
| 8 | + expect(result).toEqual(sortedArray); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should sort an array of integers in ascending order (average case)", () => { |
| 12 | + const unsortedArray = [64, 25, 12, 22, 11]; |
| 13 | + const expectedArray = [11, 12, 22, 25, 64]; |
| 14 | + const sortedArray = selectionSort(unsortedArray); |
| 15 | + |
| 16 | + expect(sortedArray).toEqual(expectedArray); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should sort an array of integers in ascending order (worst case)", () => { |
| 20 | + const reverseSortedArray = [5, 4, 3, 2, 1]; |
| 21 | + const expectedArray = [1, 2, 3, 4, 5]; |
| 22 | + const sortedArray = selectionSort(reverseSortedArray); |
| 23 | + |
| 24 | + expect(sortedArray).toEqual(expectedArray); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should handle an empty array", () => { |
| 28 | + const emptyArray = []; |
| 29 | + const sortedArray = selectionSort(emptyArray); |
| 30 | + |
| 31 | + expect(sortedArray).toEqual([]); |
| 32 | + }); |
| 33 | + |
| 34 | + it("should handle an array with a single element", () => { |
| 35 | + const singleElementArray = [42]; |
| 36 | + const sortedArray = selectionSort(singleElementArray); |
| 37 | + |
| 38 | + expect(sortedArray).toEqual([42]); |
| 39 | + }); |
| 40 | +}); |
0 commit comments