54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
encodeV3Bits,
|
|
V3_CHIPS,
|
|
v3ChipPosition,
|
|
v3ChipRects,
|
|
createV3Tile,
|
|
} from "../src/watermark/v3.js";
|
|
import { createWatermarkTile } from "../src/watermark/render.js";
|
|
const UUID = "ccea506f-d984-4044-824b-62bf0c3dcf86";
|
|
test("WM-v3 symbol count and interleaver is a permutation", () => {
|
|
const bits = encodeV3Bits(UUID);
|
|
assert.equal(bits.length, 340);
|
|
assert.equal(
|
|
new Set(Array.from({ length: V3_CHIPS }, (_, i) => v3ChipPosition(i))).size,
|
|
340,
|
|
);
|
|
assert.ok(bits.every((bit) => bit === 0 || bit === 1));
|
|
});
|
|
test("WM-v3 marks fit their cells without crossing bounds", () => {
|
|
for (let index = 0; index < 340; index++) {
|
|
const pos = v3ChipPosition(index),
|
|
{ left, right } = v3ChipRects(pos);
|
|
for (const rect of [left, right]) {
|
|
assert.ok(
|
|
rect.x >= 0 &&
|
|
rect.x + rect.w <= 240 &&
|
|
rect.y >= 0 &&
|
|
rect.y + rect.h <= 204,
|
|
);
|
|
}
|
|
}
|
|
});
|
|
test("WM-v3 tile default and v2 opt-in remain available", () => {
|
|
globalThis.document = {
|
|
createElement() {
|
|
return {
|
|
width: 0,
|
|
height: 0,
|
|
getContext() {
|
|
return { fillStyle: null, fillRect() {} };
|
|
},
|
|
};
|
|
},
|
|
};
|
|
const v3 = createWatermarkTile(UUID, { version: 3 });
|
|
assert.deepEqual([v3.width, v3.height], [240, 204]);
|
|
const v2 = createWatermarkTile(UUID, { version: 2 });
|
|
assert.deepEqual([v2.width, v2.height], [240, 200]);
|
|
const v3custom = createV3Tile(UUID, { opacity: 0.03 });
|
|
assert.equal(v3custom.height, 204);
|
|
});
|