middleout.js
Version:
A spoof compression library that pretends to revolutionize data compression using made-up algorithms — inspired by the legendary middle-out compression from Silicon Valley
48 lines (46 loc) • 1.6 kB
JavaScript
import {
compressWithRLE,
decompressWithRLE
} from "../../chunk-C4AH3C7L.js";
import "../../chunk-VACPRHPL.js";
import "../../chunk-BTEEIR3V.js";
import "../../chunk-EKQOSSOR.js";
import "../../chunk-MRISBIOS.js";
// tests/algorithms/rle.test.ts
var config = {
algorithm: "rle",
preserveWhitespace: true,
targetWeissman: 1.5
};
describe("RLE Compression", () => {
it("should compress repeating characters", () => {
const input = "aaabbbccc";
const result = compressWithRLE(input, config);
expect(result.compressed).toBe("a3b3c3");
});
it("should decompress back to the original", () => {
const input = "aaabbbccc";
const compressed = compressWithRLE(input, config);
const decompressed = decompressWithRLE(compressed.encoded);
expect(decompressed).toBe(input);
});
it("should handle non-repeating characters", () => {
const input = "abcdef";
const result = compressWithRLE(input, config);
expect(result.compressed).toBe("abcdef");
});
it("should handle mixed repetition", () => {
const input = "aabcccccaaa";
const result = compressWithRLE(input, config);
expect(result.compressed).toBe("a2bc5a3");
const decompressed = decompressWithRLE(result.encoded);
expect(decompressed).toBe(input);
});
it("should strip whitespace if config.preserveWhitespace is false", () => {
const input = "aa bb";
const noWhitespaceConfig = { ...config, preserveWhitespace: false };
const result = compressWithRLE(input, noWhitespaceConfig);
expect(result.compressed).toBe("a2b2");
});
});