-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathnoise.js
More file actions
76 lines (69 loc) · 1.95 KB
/
Copy pathnoise.js
File metadata and controls
76 lines (69 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import noise from '../../../src/math/noise.js';
import { vi } from 'vitest';
suite('Noise', function() {
const mockP5 = {
_validateParameters: vi.fn()
};
const mockP5Prototype = {};
beforeAll(function() {
noise(mockP5, mockP5Prototype);
});
afterAll(function() {
});
// This could use some better testing!
// Just checking that we get an actual number now
// 1D noise only
// ALso need test for noiseSeed and noiseDetail
var result;
var results = [];
suite('p5.prototype.noise', function() {
beforeEach(function() {
result = mockP5Prototype.noise(0);
});
test('should return a number', function() {
assert.typeOf(result, 'number');
});
test('should return a number 0 < n < 1', function() {
assert.isTrue(result > 0);
assert.isTrue(result < 1);
});
});
// Test for null arguments
suite('null arguments', function() {
test('null should returns NaN', function() {
assert.isNaN(mockP5Prototype.noise(null));
});
test('noise(0, 0, null) returns NaN', function() {
assert.isNaN(mockP5Prototype.noise(0, 0, null));
});
});
// Test for noiseSeed
suite('p5.prototype.noiseSeed', function() {
beforeEach(function() {
mockP5Prototype.noiseSeed(99);
var t = 0;
for (var i = 0; i < 5; i++) {
results[i] = mockP5Prototype.noise(t);
t += 0.01;
}
mockP5Prototype.noiseSeed(99);
t = 0;
for (i = 5; i < 10; i++) {
results[i] = mockP5Prototype.noise(t);
t += 0.01;
}
});
test('should return a number 0 < n < 1', function() {
for (var i = 0; i < results.length; i++) {
assert.typeOf(results[i], 'number');
assert.isTrue(results[i] > 0);
assert.isTrue(results[i] < 1);
}
});
test('should return same sequence of numbers', function() {
for (var i = 0; i < 5; i++) {
assert.isTrue(results[i] === results[i + 5]);
}
});
});
});