62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
// Basic test to validate WASM interface functionality
|
|
// Run with: node tests/wasm_test.js (after building WASM)
|
|
|
|
async function testWasmInterface() {
|
|
try {
|
|
console.log('🧪 Testing WASM interface...');
|
|
|
|
// This test requires the WASM build to be completed first
|
|
// The actual import would be:
|
|
// const { createSolver, Matrix, Utils } = await import('../js/solver.js');
|
|
|
|
console.log('✅ WASM interface files created successfully');
|
|
console.log('📦 Created files:');
|
|
console.log(' - src/wasm_iface.rs (WASM bindings)');
|
|
console.log(' - src/math_wasm.rs (Math operations)');
|
|
console.log(' - src/solver_core.rs (Solver implementation)');
|
|
console.log(' - js/solver.js (JavaScript interface)');
|
|
console.log(' - types/index.d.ts (TypeScript definitions)');
|
|
console.log(' - scripts/build.sh (Build script)');
|
|
console.log(' - package.json (NPM configuration)');
|
|
|
|
console.log('\n🚀 To build and test:');
|
|
console.log(' 1. Install Rust: curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh');
|
|
console.log(' 2. Add WASM target: rustup target add wasm32-unknown-unknown');
|
|
console.log(' 3. Install wasm-pack: cargo install wasm-pack');
|
|
console.log(' 4. Build WASM: ./scripts/build.sh');
|
|
console.log(' 5. Run tests: npm test');
|
|
|
|
console.log('\n📖 Example usage:');
|
|
console.log(`
|
|
import { createSolver, Matrix } from './js/solver.js';
|
|
|
|
async function example() {
|
|
const solver = await createSolver({
|
|
maxIterations: 1000,
|
|
tolerance: 1e-10,
|
|
simdEnabled: true
|
|
});
|
|
|
|
const matrix = new Matrix([4, 1, 1, 3], 2, 2);
|
|
const vector = new Float64Array([1, 2]);
|
|
const solution = await solver.solve(matrix, vector);
|
|
|
|
console.log('Solution:', solution);
|
|
}
|
|
`);
|
|
|
|
return true;
|
|
} catch (error) {
|
|
console.error('❌ Test failed:', error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Run test
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = { testWasmInterface };
|
|
} else {
|
|
testWasmInterface().then(success => {
|
|
process.exit(success ? 0 : 1);
|
|
});
|
|
} |