|
| 1 | +import { runLengthEncoding } from "../RunLengthEncoding"; |
| 2 | + |
| 3 | +describe("runLengthEncoding", () => { |
| 4 | + it("should encode a string with consecutive characters correctly", () => { |
| 5 | + const input = "AAABBBCCCDDEE"; |
| 6 | + const expectedOutput = "3A3B3C2D2E"; |
| 7 | + const encodedString = runLengthEncoding(input); |
| 8 | + expect(encodedString).toBe(expectedOutput); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should handle single characters without encoding", () => { |
| 12 | + const input = "aA"; |
| 13 | + const expectedOutput = "1a1A"; |
| 14 | + const encodedString = runLengthEncoding(input); |
| 15 | + expect(encodedString).toBe(expectedOutput); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should handle special characters", () => { |
| 19 | + const input = "!@##$$$"; |
| 20 | + const expectedOutput = "1!1@2#3$"; |
| 21 | + const encodedString = runLengthEncoding(input); |
| 22 | + expect(encodedString).toBe(expectedOutput); |
| 23 | + }); |
| 24 | + |
| 25 | + it("should handle a mix of characters", () => { |
| 26 | + const input = "AABBB!@"; |
| 27 | + const expectedOutput = "2A3B1!1@"; |
| 28 | + const encodedString = runLengthEncoding(input); |
| 29 | + expect(encodedString).toBe(expectedOutput); |
| 30 | + }); |
| 31 | + |
| 32 | + it("should handle a string of consecutive numbers", () => { |
| 33 | + const input = "122333"; |
| 34 | + const expectedOutput = "112233"; |
| 35 | + const encodedString = runLengthEncoding(input); |
| 36 | + expect(encodedString).toBe(expectedOutput); |
| 37 | + }); |
| 38 | + |
| 39 | + it("should handle a string of consecutive special characters", () => { |
| 40 | + const input = "************^^^^^^^$$$$$$%%%%%%%!!!!!!AAAAAAAAAAAAAAAAAAAA"; |
| 41 | + const expectedOutput = "9*3*7^6$7%6!9A9A2A"; |
| 42 | + const encodedString = runLengthEncoding(input); |
| 43 | + expect(encodedString).toBe(expectedOutput); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should handle a mix of lowercase, uppercase, and numbers", () => { |
| 47 | + const input = "aAaAaaaaaAaaaAAAABbbbBBBB"; |
| 48 | + const expectedOutput = "1a1A1a1A5a1A3a4A1B3b4B"; |
| 49 | + const encodedString = runLengthEncoding(input); |
| 50 | + expect(encodedString).toBe(expectedOutput); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should handle an empty string", () => { |
| 54 | + const input = ""; |
| 55 | + const expectedOutput = ""; |
| 56 | + const encodedString = runLengthEncoding(input); |
| 57 | + expect(encodedString).toBe(expectedOutput); |
| 58 | + }); |
| 59 | + |
| 60 | + it("should handle a string with spaces and numbers", () => { |
| 61 | + const input = "1 222 333 444 555"; |
| 62 | + const expectedOutput = "112 321 334 342 35"; |
| 63 | + const encodedString = runLengthEncoding(input); |
| 64 | + expect(encodedString).toBe(expectedOutput); |
| 65 | + }); |
| 66 | +}); |
0 commit comments