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
46 lines (44 loc) • 1.78 kB
JavaScript
import {
compressWithSTK,
decompressWithSTK
} from "../../chunk-EJVZUHIS.js";
import "../../chunk-VACPRHPL.js";
import "../../chunk-BTEEIR3V.js";
import "../../chunk-EKQOSSOR.js";
import "../../chunk-MRISBIOS.js";
// tests/algorithms/stk.test.ts
var defaultConfig = {
preserveWhitespace: true,
targetWeissman: 5
};
describe("STK Compression Algorithm", () => {
it("should compress a typical string using STK", () => {
const input = "The system encountered an unexpected null pointer exception at line 42.";
const result = compressWithSTK(input, defaultConfig);
expect(result).toHaveProperty("compressed");
expect(result.compressed).not.toBe(input);
expect(result.algorithm).toBe("stk");
expect(result.encoded).toMatch(/MO::stk:.+::WEISSMAN::[\d.]+/);
});
it("should fallback to raw string if decoding fails", () => {
expect(() => {
decompressWithSTK("STK::INVALID::CODE");
}).toThrow("Invalid encoded format");
});
it("should preserve whitespaces if specified", () => {
const config = { ...defaultConfig, preserveWhitespace: true };
const input = " Indented Error: This is spaced oddly. ";
const { encoded } = compressWithSTK(input, config);
const output = decompressWithSTK(encoded);
expect(output.startsWith(" ") || output.endsWith(" ")).toBeTruthy();
});
it("should trim whitespaces if config disables preservation", () => {
const config = { ...defaultConfig, preserveWhitespace: false };
const input = " Fatal: Unexpected spacebar usage. ";
const { encoded } = compressWithSTK(input, config);
const output = decompressWithSTK(encoded);
expect(output.startsWith(" ")).toBe(false);
expect(output.endsWith(" ")).toBe(false);
});
});