import { describe, it, expect } from 'vitest'; import { dmqimEmbed, dmqimExtractSoft, dmqimExtractHard } from '../core/dmqim.js'; describe('DM-QIM', () => { it('should embed and extract bit 0 correctly', () => { const coeff = 42.5; const delta = 10; const dither = 3.7; const embedded = dmqimEmbed(coeff, 0, delta, dither); const hard = dmqimExtractHard(embedded, delta, dither); expect(hard).toBe(0); }); it('should embed and extract bit 1 correctly', () => { const coeff = 42.5; const delta = 10; const dither = 3.7; const embedded = dmqimEmbed(coeff, 1, delta, dither); const hard = dmqimExtractHard(embedded, delta, dither); expect(hard).toBe(1); }); it('should produce correct soft decisions', () => { const delta = 20; const dither = 5.0; for (let bit = 0; bit <= 1; bit++) { const embedded = dmqimEmbed(50, bit, delta, dither); const soft = dmqimExtractSoft(embedded, delta, dither); if (bit === 1) { expect(soft).toBeGreaterThan(0); } else { expect(soft).toBeLessThanOrEqual(0); } } }); it('should work with various coefficient values and dithers', () => { const delta = 15; for (let trial = 0; trial < 100; trial++) { const coeff = (Math.random() - 0.5) * 200; const dither = (Math.random() - 0.5) * delta; const bit = Math.random() > 0.5 ? 1 : 0; const embedded = dmqimEmbed(coeff, bit, delta, dither); const extracted = dmqimExtractHard(embedded, delta, dither); expect(extracted).toBe(bit); } }); });