i18n-ai-translate
Version:
AI-powered localization CLI, Node library, and GitHub Action. Translate i18next JSON, Gettext PO, Java .properties, and iOS .strings with ChatGPT, Claude, Gemini, or local Ollama models.
49 lines • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const sharding_1 = require("../sharding");
describe("buildGroupShards", () => {
it("keeps each group whole within a single shard", () => {
const groups = [
{ a: "Hello", b: "Hi" },
{ c: "Goodbye", d: "Bye" },
{ e: "Thanks" },
];
const shards = (0, sharding_1.buildGroupShards)(groups, 2);
// Collect which keys ended up together.
const locate = (key) => shards.findIndex((shard) => key in shard);
// Keys in the same group are in the same shard.
expect(locate("a")).toBe(locate("b"));
expect(locate("c")).toBe(locate("d"));
});
it("balances by item count greedily across shards", () => {
const groups = [
{ a: "1", b: "2", c: "3" }, // 3
{ d: "4" }, // 1
{ e: "5" }, // 1
{ f: "6" }, // 1
];
const shards = (0, sharding_1.buildGroupShards)(groups, 2);
const counts = shards.map((s) => Object.keys(s).length);
counts.sort();
expect(counts).toEqual([3, 3]);
});
it("drops empty shards when groups < concurrency", () => {
const groups = [{ a: "1" }, { b: "2" }];
const shards = (0, sharding_1.buildGroupShards)(groups, 5);
expect(shards).toHaveLength(2);
for (const shard of shards) {
expect(Object.keys(shard).length).toBeGreaterThan(0);
}
});
it("handles concurrency=1 by putting everything in one shard", () => {
const groups = [
{ a: "1" },
{ b: "2" },
{ c: "3" },
];
const shards = (0, sharding_1.buildGroupShards)(groups, 1);
expect(shards).toHaveLength(1);
expect(Object.keys(shards[0])).toEqual(["a", "b", "c"]);
});
});
//# sourceMappingURL=shard.spec.js.map