Parallel Letter Frequency

This commit is contained in:
Rorik Star Platinum 2025-12-03 16:07:22 +03:00
parent 3ca9867a11
commit af89290bbc
45 changed files with 2862 additions and 0 deletions

View file

@ -0,0 +1,40 @@
import { compileWat, WasmRunner } from "@exercism/wasm-lib";
let wasmModule;
let currentInstance;
beforeAll(async () => {
try {
const watPath = new URL("./hello-world.wat", import.meta.url);
const { buffer } = await compileWat(watPath);
wasmModule = await WebAssembly.compile(buffer);
} catch (err) {
console.log(`Error compiling *.wat: \n${err}`);
process.exit(1);
}
});
describe("Hello World", () => {
beforeEach(async () => {
currentInstance = null;
if (!wasmModule) {
return Promise.reject();
}
try {
currentInstance = await new WasmRunner(wasmModule);
return Promise.resolve();
} catch (err) {
console.log(`Error instantiating WebAssembly module: ${err}`);
return Promise.reject();
}
});
test("Say Hi!", () => {
expect(currentInstance).toBeTruthy();
const [offset, length] = currentInstance.exports.hello();
expect(length).toBe(13);
const greeting = currentInstance.get_mem_as_utf8(offset, length);
expect(greeting).toBe("Hello, World!");
});
});