-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07dfe35
commit 626b8ff
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>C Tests (Packaged with emscripten)</title> | ||
<link href="https://npmcdn.com/[email protected]/mocha.css" rel="stylesheet" /> | ||
<script src="https://npmcdn.com/[email protected]/mocha.js"></script> | ||
</head> | ||
<body> | ||
<!-- A container element for the visual Mocha results --> | ||
<div id="mocha"></div> | ||
<!-- Mocha setup and initiation code --> | ||
<script type="module"> | ||
import * as wasm from './dist/c-lib.js'; | ||
mocha.setup('bdd'); | ||
window.onload = function() { | ||
init().then(() => { | ||
for (let p = 1; p < 10000; p++) { | ||
const formattedQuestion = `${p}`.padStart(4, '0'); | ||
const func = wasm[`_p${formattedQuestion}`]; | ||
if (func === undefined) continue; | ||
const expected = wasm._get_answer(p); | ||
describe(`run test ${p}`, function() { | ||
this.timeout(Infinity); | ||
it(`should return ${expected}`, async () => { | ||
const answer = func(); | ||
console.log(p, answer, expected); | ||
if (answer !== expected) { | ||
throw new Error(); | ||
} | ||
}); | ||
}); | ||
} | ||
const runner = mocha.run(); | ||
let failedTests = []; | ||
|
||
runner.on('end', function() { | ||
window.mochaResults = runner.stats; | ||
window.mochaResults.reports = failedTests; | ||
}); | ||
|
||
runner.on('fail', function(test, err){ | ||
const flattenTitles = function(test){ | ||
let titles = []; | ||
while (test.parent.title){ | ||
titles.push(test.parent.title); | ||
test = test.parent; | ||
} | ||
return titles.reverse(); | ||
}; | ||
|
||
failedTests.push({ | ||
name: test.title, | ||
result: false, | ||
message: err.message, | ||
stack: err.stack, | ||
titles: flattenTitles(test) | ||
}); | ||
}); | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>C++ Tests (Packaged with emscripten)</title> | ||
<link href="https://npmcdn.com/[email protected]/mocha.css" rel="stylesheet" /> | ||
<script src="https://npmcdn.com/[email protected]/mocha.js"></script> | ||
</head> | ||
<body> | ||
<!-- A container element for the visual Mocha results --> | ||
<div id="mocha"></div> | ||
<!-- Mocha setup and initiation code --> | ||
<script type="module"> | ||
import * as wasm from './dist/cp-lib.js'; | ||
mocha.setup('bdd'); | ||
window.onload = function() { | ||
init().then(() => { | ||
for (let p = 1; p < 10000; p++) { | ||
const formattedQuestion = `${p}`.padStart(4, '0'); | ||
const func = wasm[`_p${formattedQuestion}`]; | ||
if (func === undefined) continue; | ||
const expected = wasm._get_answer(p); | ||
describe(`run test ${p}`, function() { | ||
this.timeout(Infinity); | ||
it(`should return ${expected}`, async () => { | ||
const answer = func(); | ||
console.log(p, answer, expected); | ||
if (answer !== expected) { | ||
throw new Error(); | ||
} | ||
}); | ||
}); | ||
} | ||
const runner = mocha.run(); | ||
let failedTests = []; | ||
|
||
runner.on('end', function() { | ||
window.mochaResults = runner.stats; | ||
window.mochaResults.reports = failedTests; | ||
}); | ||
|
||
runner.on('fail', function(test, err){ | ||
const flattenTitles = function(test){ | ||
let titles = []; | ||
while (test.parent.title){ | ||
titles.push(test.parent.title); | ||
test = test.parent; | ||
} | ||
return titles.reverse(); | ||
}; | ||
|
||
failedTests.push({ | ||
name: test.title, | ||
result: false, | ||
message: err.message, | ||
stack: err.stack, | ||
titles: flattenTitles(test) | ||
}); | ||
}); | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
</html> |