Skip to content

Commit

Permalink
Pretty print on Wasm test
Browse files Browse the repository at this point in the history
  • Loading branch information
kikuchan committed Feb 17, 2024
1 parent 9dbb7c7 commit f470d0d
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions wasm/Qrean.QR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@ import * as t from "https://deno.land/std/testing/asserts.ts";
import QRCode from 'npm:qrcode';
import { Qrean } from "./Qrean.ts";

Deno.test("QR", async () => {
async function qrean(v: number, e: 'L' | 'M' | 'Q' | 'H', m: number) {
return await Qrean.encode('Hello', {
scale: 1,
eciCode: 'Latin1',
dataType: '8BIT',
qrVersion: String(v) as any,
qrErrorLevel: e,
qrMaskPattern: String(m) as any,
}).then(obj => {
if (!obj) return false;
const w = obj.width;
const stride = 4;
async function qrean(v: number, e: 'L' | 'M' | 'Q' | 'H', m: number) {
return await Qrean.encode('Hello', {
scale: 1,
eciCode: 'Latin1',
dataType: '8BIT',
qrVersion: String(v) as any,
qrErrorLevel: e,
qrMaskPattern: String(m) as any,
}).then(obj => {
if (!obj) return false;
const w = obj.width;
const stride = 4;

const lines = [];
for (let y = 0; y < obj.height; y++) {
const line = [];
for (let x = 0; x < obj.width; x++) {
line.push(obj.data[(y * w + x) * stride + 0] == 0 ? '1' : '0');
}
lines.push(line.join(''));
const lines = [];
for (let y = 0; y < obj.height; y++) {
const line = [];
for (let x = 0; x < obj.width; x++) {
line.push(obj.data[(y * w + x) * stride + 0] == 0 ? '1' : '0');
}
return lines.join('\n');
});
}
lines.push(line.join(''));
}
return lines.join('\n');
});
}

async function reference(v: number, e: string, m: number) {
return await QRCode.toString(
[{ data: 'Hello', mode: 'Byte' }],
{
version: v,
errorCorrectionLevel: e,
maskPattern: m,
}
).then((s: string) => s.split('\n').flatMap((line: string) => {
const odd = (x: string) => Math.floor(" ▄▀█".indexOf(x) / 2);
const even = (x: string) => Math.floor(" ▄▀█".indexOf(x) % 2);
const l = line.split('');
return [l.map(odd).join(''), l.map(even).join('')];
}).slice(0, -1).join('\n'));
}
async function reference(v: number, e: string, m: number) {
return await QRCode.toString(
[{ data: 'Hello', mode: 'Byte' }],
{
version: v,
errorCorrectionLevel: e,
maskPattern: m,
}
).then((s: string) => s.split('\n').flatMap((line: string) => {
const odd = (x: string) => Math.floor(" ▄▀█".indexOf(x) / 2);
const even = (x: string) => Math.floor(" ▄▀█".indexOf(x) % 2);
const l = line.split('');
return [l.map(odd).join(''), l.map(even).join('')];
}).slice(0, -1).join('\n'));
}

for (let v = 1; v <= 40; v++) {
for (let v = 1; v <= 40; v++) {
Deno.test("QR Version " + v, async () => {
for (const e of ['L', 'M', 'Q', 'H'] as ('L' | 'M' | 'Q' | 'H')[]) {
for (let m = 0; m < 8; m++) {
const a = await qrean(v, e, m);
Expand All @@ -53,5 +53,5 @@ Deno.test("QR", async () => {
t.assertEquals(a, b);
}
}
}
});
});
}

0 comments on commit f470d0d

Please sign in to comment.