Skip to content

Commit 760bf84

Browse files
authored
Merge pull request #125 from daffl/test-browser
Add a small browser test and automated runner script
2 parents 166c0f5 + 88fba51 commit 760bf84

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"url": "git+ssh://[email protected]/brainjs/brain.js.git"
99
},
1010
"scripts": {
11+
"test-browser": "testee test/browser/index.html --browsers firefox --reporter Spec",
1112
"test-base": "find ./test/base/ -name '*.js' | xargs mocha --compilers js:babel-core/register",
1213
"test-recurrent": "find ./test/recurrent/ -name '*.js' | xargs mocha --compilers js:babel-core/register",
1314
"test-recurrent-matrix": "find ./test/recurrent/matrix -name '*.js' | xargs mocha --compilers js:babel-core/register",
@@ -35,6 +36,7 @@
3536
"licensify": "^3.1.2",
3637
"mocha": "^3.0.2",
3738
"sinon": "^1.17.6",
39+
"testee": "^0.7.0",
3840
"uglifyify": "^3.0.2"
3941
},
4042
"keywords": [

test/browser/browser.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* global describe, it, brain, assert */
2+
describe('Brain.js basic browser test', function () {
3+
it('has the brain global variable with the things we expect', function () {
4+
assert(window.brain);
5+
assert(brain.NeuralNetwork);
6+
assert(brain.NeuralNetworkGPU);
7+
});
8+
9+
it('runs the NeuralNetwork example', function () {
10+
var net = new brain.NeuralNetwork();
11+
12+
net.train([
13+
{ input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 } },
14+
{ input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 } },
15+
{ input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 } }
16+
]);
17+
18+
var output = net.run({ r: 1, g: 0.4, b: 0 });
19+
20+
assert(output.white > output.black);
21+
});
22+
});

test/browser/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Mocha</title>
6+
<script src="//unpkg.com/mocha@^3.2.0/mocha.js"></script>
7+
<script>mocha.setup('bdd');</script>
8+
<link rel="stylesheet" href="//unpkg.com/mocha@^3.2.0/mocha.css">
9+
</head>
10+
<body onload="mocha.run()">
11+
<div id="mocha"></div>
12+
<script>
13+
function assert(expr, msg) {
14+
if (!expr) throw new Error(msg || 'failed');
15+
}
16+
</script>
17+
<script src="../../browser.js"></script>
18+
<script src="./browser.test.js"></script>
19+
</body>
20+
</html>

0 commit comments

Comments
 (0)