Skip to content

Commit 963dafe

Browse files
committed
Move tests to mocha
1 parent 437a50d commit 963dafe

File tree

4 files changed

+121
-119
lines changed

4 files changed

+121
-119
lines changed

.jshintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"predef": [
3-
"define"
3+
"describe",
4+
"it",
5+
"beforeEach"
46
],
57
"browser" : true,
68
"node" : true,

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55
"homepage": "https://github.com/jwagner/simplex-noise.js",
66
"author": "Jonas Wagner <[email protected]> (http://29a.ch/)",
77
"main": "./simplex-noise",
8-
98
"devDependencies": {
9+
"benchmark": "~2.1.0",
1010
"buster": "~0.7.8",
11-
"benchmark": "~2.1.0"
11+
"chai": "^3.5.0"
1212
},
1313
"bugs": {
14-
"url": "https://github.com/jwagner/simplex-noise.js/issues"
14+
"url": "https://github.com/jwagner/simplex-noise.js/issues"
1515
},
1616
"keywords": [
17-
"noise",
18-
"random",
19-
"simplex",
20-
"plasma",
21-
"procedural",
22-
"gfx",
23-
"generative"
17+
"noise",
18+
"random",
19+
"simplex",
20+
"plasma",
21+
"procedural",
22+
"gfx",
23+
"generative"
2424
],
2525
"license": "MIT",
2626
"repository": {
2727
"type": "git",
2828
"url": "https://github.com/jwagner/simplex-noise.js.git"
2929
},
3030
"scripts": {
31-
"test": "./node_modules/buster/bin/buster-test"
31+
"test": "mocha"
3232
}
3333
}

test/buster.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/simplex-noise-test.js

Lines changed: 107 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,114 @@
1-
if(typeof require !== 'undefined'){
2-
var buster = require("buster");
3-
var SimplexNoise = require("../simplex-noise");
4-
}
1+
var SimplexNoise = require('../simplex-noise');
52

6-
var assert = buster.assert,
7-
refute = buster.refute;
3+
var assert = require('chai').assert;
84

9-
var _rnd;
10-
function random(){
11-
return 1.0/(_rnd++);
12-
}
5+
describe('simplex-noise', function() {
6+
function getRandom() {
7+
var rnd = 0;
8+
return function() {
9+
return 1.0 / (rnd++);
10+
};
11+
}
1312

14-
buster.testCase("simplex-noise", {
15-
setUp: function() {_rnd = 0;},
16-
"should initialize with Math.random": function () {
17-
var simplex = new SimplexNoise();
18-
assert.equals(simplex.perm.length, 512);
19-
assert.equals(simplex.permMod12.length, 512);
20-
for(var i = 0; i < 512; i++){
21-
assert(simplex.perm[i] < 256);
22-
assert(simplex.perm[i] >= 0);
23-
assert(simplex.perm[i] >= 0);
24-
assert.equals(simplex.perm[i], simplex.perm[i&255]);
25-
assert.equals(simplex.permMod12[i], simplex.perm[i]%12);
26-
}
27-
},
28-
"should initialize with a custom random function": function () {
29-
var i = 2,
30-
simplex = new SimplexNoise(function(){return 1.0/i++;});
31-
assert.equals(simplex.perm.length, 512);
32-
assert.equals(simplex.permMod12.length, 512);
33-
assert.equals(simplex.perm[0], 128);
34-
assert.equals(simplex.perm[1], 85);
35-
assert.equals(simplex.perm[256], 128);
36-
assert.equals(simplex.perm[257], 85);
37-
assert.equals(simplex.permMod12[0], 128%12);
38-
assert.equals(simplex.permMod12[1], 85%12);
39-
},
40-
'noise': {
41-
setUp: function() {
42-
this.simplex = new SimplexNoise(random);
43-
},
44-
'noise2D': {
45-
'should return the same value for the same input': function() {
46-
assert.equals(this.simplex.noise2D(0.1, 0.2), this.simplex.noise2D(0.1, 0.2));
47-
},
48-
'should return a different value for a different input': function() {
49-
refute.equals(this.simplex.noise2D(0.1, 0.2), this.simplex.noise2D(0.101, 0.202));
50-
},
51-
'should return values between -1 and 1': function () {
52-
for(var x = 0; x < 10; x++) {
53-
for(var y = 0; y < 10; y++) {
54-
assert(this.simplex.noise2D(x/5, y/5) >= -1);
55-
assert(this.simplex.noise2D(x/5, y/5) <= 1);
56-
}
57-
}
58-
},
59-
'should return similar values for similar inputs': function () {
60-
assert(Math.abs(this.simplex.noise2D(0.1, 0.2)-this.simplex.noise2D(0.101, 0.202))<0.1);
61-
}
62-
},
63-
'noise3D': {
64-
'should return the same value for the same input': function() {
65-
assert.equals(this.simplex.noise3D(0.1, 0.2, 0.3), this.simplex.noise3D(0.1, 0.2, 0.3));
66-
},
67-
'should return a different value for a different input': function() {
68-
refute.equals(this.simplex.noise3D(0.1, 0.2, 0.3), this.simplex.noise3D(0.101, 0.202, 0.303));
69-
refute.equals(this.simplex.noise3D(0.1, 0.2, 0.3), this.simplex.noise3D(0.1, 0.2, 0.303));
70-
},
71-
'should return values between -1 and 1': function () {
72-
for(var x = 0; x < 10; x++) {
73-
for(var y = 0; y < 10; y++) {
74-
assert(this.simplex.noise3D(x/5, y/5, x+y) >= -1);
75-
assert(this.simplex.noise3D(x/5, y/5, x+y) <= 1);
76-
}
77-
}
78-
},
79-
'should return similar values for similar inputs': function () {
80-
assert(Math.abs(this.simplex.noise3D(0.1, 0.2, 0.3)-this.simplex.noise3D(0.101, 0.202, 0.303))<0.1);
81-
}
82-
},
83-
'noise4D': {
84-
'should return the same value for the same input': function() {
85-
assert.equals(this.simplex.noise4D(0.1, 0.2, 0.3, 0.4), this.simplex.noise4D(0.1, 0.2, 0.3, 0.4));
86-
},
87-
'should return a different value for a different input': function() {
88-
refute.equals(this.simplex.noise4D(0.1, 0.2, 0.3, 0.4), this.simplex.noise4D(0.101, 0.202, 0.303, 0.404));
89-
refute.equals(this.simplex.noise4D(0.1, 0.2, 0.3, 0.4), this.simplex.noise4D(0.1, 0.2, 0.3, 0.404));
90-
},
91-
'should return values between -1 and 1': function () {
92-
for(var x = 0; x < 10; x++) {
93-
for(var y = 0; y < 10; y++) {
94-
assert(this.simplex.noise4D(x/5, y/5, x+y, x-y) >= -1);
95-
assert(this.simplex.noise4D(x/5, y/5, x+y, x-y) <= 1);
96-
}
97-
}
98-
},
99-
'should return similar values for similar inputs': function () {
100-
assert(Math.abs(this.simplex.noise4D(0.1, 0.2, 0.3, 0.4)-this.simplex.noise4D(0.101, 0.202, 0.303, 0.404))<0.1);
101-
}
13+
describe('constructor', function() {
14+
it('should initialize with Math.random', function() {
15+
var simplex = new SimplexNoise();
16+
assert.equal(simplex.perm.length, 512);
17+
assert.equal(simplex.permMod12.length, 512);
18+
for (var i = 0; i < 512; i++) {
19+
assert(simplex.perm[i] < 256);
20+
assert(simplex.perm[i] >= 0);
21+
assert(simplex.perm[i] >= 0);
22+
assert.equal(simplex.perm[i], simplex.perm[i & 255]);
23+
assert.equal(simplex.permMod12[i], simplex.perm[i] % 12);
24+
}
25+
});
26+
27+
it('should initialize with a custom random function', function() {
28+
var i = 2;
29+
var simplex = new SimplexNoise(function() {
30+
return 1.0 / i++;
31+
});
32+
assert.equal(simplex.perm.length, 512);
33+
assert.equal(simplex.permMod12.length, 512);
34+
assert.equal(simplex.perm[0], 128);
35+
assert.equal(simplex.perm[1], 85);
36+
assert.equal(simplex.perm[256], 128);
37+
assert.equal(simplex.perm[257], 85);
38+
assert.equal(simplex.permMod12[0], 128 % 12);
39+
assert.equal(simplex.permMod12[1], 85 % 12);
40+
});
41+
});
42+
43+
describe('noise', function() {
44+
var simplex;
45+
beforeEach(function() {
46+
simplex = new SimplexNoise(getRandom());
47+
});
48+
describe('noise2D', function() {
49+
it('should return the same value for the same input', function() {
50+
assert.equal(simplex.noise2D(0.1, 0.2), simplex.noise2D(0.1, 0.2));
51+
});
52+
it('should return a different value for a different input', function() {
53+
assert.notEqual(simplex.noise2D(0.1, 0.2), simplex.noise2D(0.101, 0.202));
54+
});
55+
it('should return values between -1 and 1', function() {
56+
for (var x = 0; x < 10; x++) {
57+
for (var y = 0; y < 10; y++) {
58+
assert(simplex.noise2D(x / 5, y / 5) >= -1);
59+
assert(simplex.noise2D(x / 5, y / 5) <= 1);
60+
}
10261
}
62+
});
63+
it('should return similar values for similar inputs', function() {
64+
assert(Math.abs(simplex.noise2D(0.1, 0.2) - simplex.noise2D(0.101, 0.202)) < 0.1);
65+
});
66+
});
10367

68+
describe('noise3D', function() {
69+
it('should return the same value for the same input', function() {
70+
assert.equal(simplex.noise3D(0.1, 0.2, 0.3), simplex.noise3D(0.1, 0.2, 0.3));
71+
});
72+
it('should return a different value for a different input', function() {
73+
assert.notEqual(simplex.noise3D(0.1, 0.2, 0.3), simplex.noise3D(0.101, 0.202, 0.303));
74+
assert.notEqual(simplex.noise3D(0.1, 0.2, 0.3), simplex.noise3D(0.1, 0.2, 0.303));
75+
});
76+
it('should return values between -1 and 1', function() {
77+
for (var x = 0; x < 10; x++) {
78+
for (var y = 0; y < 10; y++) {
79+
assert(simplex.noise3D(x / 5, y / 5, x + y) >= -1);
80+
assert(simplex.noise3D(x / 5, y / 5, x + y) <= 1);
81+
}
82+
}
83+
});
84+
it('should return similar values for similar inputs', function() {
85+
assert(Math.abs(simplex.noise3D(0.1, 0.2, 0.3) - simplex.noise3D(0.101, 0.202, 0.303)) < 0.1);
86+
});
87+
});
10488

105-
}
89+
describe('noise4D', function() {
90+
it('should return the same value for the same input', function() {
91+
assert.equal(simplex.noise4D(0.1, 0.2, 0.3, 0.4), simplex.noise4D(0.1, 0.2, 0.3, 0.4));
92+
});
93+
it('should return a different value for a different input', function() {
94+
assert.notEqual(simplex.noise4D(0.1, 0.2, 0.3, 0.4), simplex.noise4D(0.101, 0.202, 0.303, 0.404));
95+
assert.notEqual(simplex.noise4D(0.1, 0.2, 0.3, 0.4), simplex.noise4D(0.1, 0.2, 0.3, 0.404));
96+
});
97+
it('should return values between -1 and 1', function() {
98+
for (var x = 0; x < 10; x++) {
99+
for (var y = 0; y < 10; y++) {
100+
assert(simplex.noise4D(x / 5, y / 5, x + y, x - y) >= -1);
101+
assert(simplex.noise4D(x / 5, y / 5, x + y, x - y) <= 1);
102+
}
103+
}
104+
});
105+
it('should return similar values for similar inputs', function() {
106+
assert(
107+
Math.abs(
108+
simplex.noise4D(0.1, 0.2, 0.3, 0.4) -
109+
simplex.noise4D(0.101, 0.202, 0.303, 0.404)
110+
) < 0.1);
111+
});
112+
});
113+
});
106114
});

0 commit comments

Comments
 (0)