Spaces:
Running
Running
File size: 1,627 Bytes
d283c04 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { describe, it, expect } from 'vitest';
import { createBuffer2D, dwtForward, dwtInverse, yPlaneToBuffer, bufferToYPlane } from '../core/dwt.js';
describe('DWT', () => {
it('should round-trip a simple buffer (1 level)', () => {
const width = 16;
const height = 16;
const buf = createBuffer2D(width, height);
for (let i = 0; i < buf.data.length; i++) {
buf.data[i] = Math.round(Math.random() * 255);
}
const original = new Float64Array(buf.data);
const { buf: transformed, dims } = dwtForward(buf, 1);
dwtInverse(transformed, dims);
for (let i = 0; i < original.length; i++) {
expect(transformed.data[i]).toBeCloseTo(original[i], 8);
}
});
it('should round-trip a buffer (2 levels)', () => {
const width = 64;
const height = 64;
const buf = createBuffer2D(width, height);
for (let i = 0; i < buf.data.length; i++) {
buf.data[i] = Math.round(Math.random() * 255);
}
const original = new Float64Array(buf.data);
const { buf: transformed, dims } = dwtForward(buf, 2);
dwtInverse(transformed, dims);
for (let i = 0; i < original.length; i++) {
expect(transformed.data[i]).toBeCloseTo(original[i], 8);
}
});
it('should convert Y plane to buffer and back', () => {
const width = 32;
const height = 32;
const yPlane = new Uint8Array(width * height);
for (let i = 0; i < yPlane.length; i++) {
yPlane[i] = Math.floor(Math.random() * 256);
}
const buf = yPlaneToBuffer(yPlane, width, height);
const result = bufferToYPlane(buf);
expect(result).toEqual(yPlane);
});
});
|