|
| 1 | +import { moveElementToEnd } from "../MoveElementToEnd"; |
| 2 | + |
| 3 | +describe("moveElementToEnd", () => { |
| 4 | + it("should move all instances of the specified integer to the end (best case)", () => { |
| 5 | + const array = [1, 2, 3, 4, 5]; |
| 6 | + const toMove = 6; |
| 7 | + const expectedArray = [1, 2, 3, 4, 5]; |
| 8 | + |
| 9 | + const result = moveElementToEnd(array, toMove); |
| 10 | + |
| 11 | + expect(result).toEqual(expectedArray); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should move all instances of the specified integer to the end (average case)", () => { |
| 15 | + const array = [2, 1, 2, 2, 2, 3, 4, 2]; |
| 16 | + const toMove = 2; |
| 17 | + const expectedArray = [4, 1, 3, 2, 2, 2, 2, 2]; |
| 18 | + |
| 19 | + const result = moveElementToEnd(array, toMove); |
| 20 | + |
| 21 | + expect(result).toEqual(expectedArray); |
| 22 | + }); |
| 23 | + |
| 24 | + it("should move all instances of the specified integer to the end (worst case)", () => { |
| 25 | + const array = [3, 3, 3, 3, 3]; |
| 26 | + const toMove = 3; |
| 27 | + const expectedArray = [3, 3, 3, 3, 3]; |
| 28 | + |
| 29 | + const result = moveElementToEnd(array, toMove); |
| 30 | + |
| 31 | + expect(result).toEqual(expectedArray); |
| 32 | + }); |
| 33 | + |
| 34 | + it("should handle an empty array", () => { |
| 35 | + const emptyArray = []; |
| 36 | + const toMove = 5; |
| 37 | + |
| 38 | + const result = moveElementToEnd(emptyArray, toMove); |
| 39 | + |
| 40 | + expect(result).toEqual([]); |
| 41 | + }); |
| 42 | +}); |
0 commit comments