Skip to content

Commit 902b084

Browse files
committed
avoid using random numbers in all tests
1 parent cbd4834 commit 902b084

7 files changed

+39
-17
lines changed

test/jasmine/tests/cartesian_interact_test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,10 @@ describe('axis zoom/pan and main plot zoom', function() {
15881588
clipTranslate: [0, 0]
15891589
}))
15901590
.then(function() {
1591+
Lib.seedPseudoRandom();
1592+
15911593
interval = setInterval(function() {
1592-
Plotly.extendTraces(gd, { y: [[Math.random()]] }, [0]);
1594+
Plotly.extendTraces(gd, { y: [[Lib.pseudoRandom()]] }, [0]);
15931595
}, step);
15941596
})
15951597
.then(delay(1.5 * step))

test/jasmine/tests/contourgl_test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ function transpose(a) {
8989
return a[0].map(function(ignore, columnIndex) {return a.map(function(row) {return row[columnIndex];});});
9090
}
9191

92+
Lib.seedPseudoRandom();
93+
9294
function jitter(maxJitterRatio, n) {
93-
return n * (1 + maxJitterRatio * (2 * Math.random() - 1));
95+
return n * (1 + maxJitterRatio * (2 * Lib.pseudoRandom() - 1));
9496
}
9597

9698
function rotate(rad, point) {

test/jasmine/tests/parcoords_test.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,16 @@ describe('parcoords edge cases', function() {
454454
var mockCopy = Lib.extendDeep({}, mock2);
455455
var dim, i, j;
456456

457+
Lib.seedPseudoRandom();
458+
457459
mockCopy.layout.width = 320;
458460
for(i = 0; i < mockCopy.data[0].dimensions.length; i++) {
459461
dim = mockCopy.data[0].dimensions[i];
460462
delete dim.constraintrange;
461463
dim.range = [1, 2];
462464
dim.values = [];
463465
for(j = 0; j < 1; j++) {
464-
dim.values[j] = 1 + Math.random();
466+
dim.values[j] = 1 + Lib.pseudoRandom();
465467
}
466468
}
467469

@@ -527,6 +529,8 @@ describe('parcoords edge cases', function() {
527529
var mockCopy = Lib.extendDeep({}, mock1);
528530
var newDimension, i, j;
529531

532+
Lib.seedPseudoRandom();
533+
530534
mockCopy.layout.width = 1680;
531535
mockCopy.data[0].dimensions = [];
532536
for(i = 0; i < 60; i++) {
@@ -537,7 +541,7 @@ describe('parcoords edge cases', function() {
537541
newDimension.range = [1, 2];
538542
newDimension.values = [];
539543
for(j = 0; j < 100; j++) {
540-
newDimension.values[j] = 1 + Math.random();
544+
newDimension.values[j] = 1 + Lib.pseudoRandom();
541545
}
542546
mockCopy.data[0].dimensions[i] = newDimension;
543547
}
@@ -555,6 +559,8 @@ describe('parcoords edge cases', function() {
555559
var mockCopy = Lib.extendDeep({}, mock1);
556560
var newDimension, i, j;
557561

562+
Lib.seedPseudoRandom();
563+
558564
mockCopy.layout.width = 1680;
559565
for(i = 0; i < 70; i++) {
560566
newDimension = Lib.extendDeep({}, mock1.data[0].dimensions[0]);
@@ -563,7 +569,7 @@ describe('parcoords edge cases', function() {
563569
delete newDimension.constraintrange;
564570
newDimension.range = [0, 999];
565571
for(j = 0; j < 10; j++) {
566-
newDimension.values[j] = Math.floor(1000 * Math.random());
572+
newDimension.values[j] = Math.floor(1000 * Lib.pseudoRandom());
567573
}
568574
mockCopy.data[0].dimensions[i] = newDimension;
569575
}
@@ -581,6 +587,8 @@ describe('parcoords edge cases', function() {
581587
var mockCopy = Lib.extendDeep({}, mock1);
582588
var newDimension, i, j;
583589

590+
Lib.seedPseudoRandom();
591+
584592
mockCopy.layout.width = 1680;
585593
for(i = 0; i < 60; i++) {
586594
newDimension = Lib.extendDeep({}, mock1.data[0].dimensions[0]);
@@ -590,7 +598,7 @@ describe('parcoords edge cases', function() {
590598
newDimension.range = [0, 999];
591599
newDimension.values = [];
592600
for(j = 0; j < 65 - i; j++) {
593-
newDimension.values[j] = Math.floor(1000 * Math.random());
601+
newDimension.values[j] = Math.floor(1000 * Lib.pseudoRandom());
594602
}
595603
mockCopy.data[0].dimensions[i] = newDimension;
596604
}
@@ -608,6 +616,8 @@ describe('parcoords edge cases', function() {
608616
var mockCopy = Lib.extendDeep({}, mock1);
609617
var newDimension, i, j;
610618

619+
Lib.seedPseudoRandom();
620+
611621
mockCopy.layout.width = 680;
612622
mockCopy.data[0].dimensions = [];
613623
for(i = 0; i < 5; i++) {
@@ -618,7 +628,7 @@ describe('parcoords edge cases', function() {
618628
newDimension.range = [1, 2];
619629
newDimension.values = [];
620630
for(j = 0; j < 100; j++) {
621-
newDimension.values[j] = 1 + Math.random();
631+
newDimension.values[j] = 1 + Lib.pseudoRandom();
622632
}
623633
mockCopy.data[0].dimensions[i] = newDimension;
624634
}

test/jasmine/tests/scattergl_test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,14 @@ describe('end-to-end scattergl tests', function() {
586586
});
587587

588588
it('@gl should reset the sanp to length after react and not to TOO_MANY_POINTS constant', function(done) {
589+
Lib.seedPseudoRandom();
590+
589591
function fig(num) {
590592
var x = [];
591593
var y = [];
592594
for(var i = 0; i < num; i++) {
593-
x.push(Math.random());
594-
y.push(Math.random());
595+
x.push(Lib.pseudoRandom());
596+
y.push(Lib.pseudoRandom());
595597
}
596598

597599
return {

test/jasmine/tests/shapes_test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,14 @@ describe('Test shapes:', function() {
275275
null;
276276
}
277277

278+
Lib.seedPseudoRandom();
279+
278280
function getRandomShape() {
279281
return {
280-
x0: Math.random(),
281-
y0: Math.random(),
282-
x1: Math.random(),
283-
y1: Math.random()
282+
x0: Lib.pseudoRandom(),
283+
y0: Lib.pseudoRandom(),
284+
x1: Lib.pseudoRandom(),
285+
y1: Lib.pseudoRandom()
284286
};
285287
}
286288

test/jasmine/tests/streamtube_test.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,12 @@ describe('Test streamtube interactions', function() {
305305
var v = [];
306306
var w = [];
307307

308+
Lib.seedPseudoRandom();
309+
308310
for(var n = 0; n < 1000; n++) {
309-
x.push((10 * Math.random()) | 0);
310-
y.push((10 * Math.random()) | 0);
311-
z.push((10 * Math.random()) | 0);
311+
x.push((10 * Lib.pseudoRandom()) | 0);
312+
y.push((10 * Lib.pseudoRandom()) | 0);
313+
z.push((10 * Lib.pseudoRandom()) | 0);
312314
u.push(1);
313315
v.push(1);
314316
w.push(1);

test/jasmine/tests/updatemenus_test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1045,11 +1045,13 @@ describe('update menus interaction with scrollbox:', function() {
10451045
}
10461046
};
10471047

1048+
Lib.seedPseudoRandom();
1049+
10481050
for(var i = 0, n = 20; i < n; i++) {
10491051
var j;
10501052

10511053
var y;
1052-
for(j = 0, y = []; j < 10; j++) y.push(Math.random);
1054+
for(j = 0, y = []; j < 10; j++) y.push(Lib.pseudoRandom());
10531055

10541056
mock.data.push({
10551057
y: y,

0 commit comments

Comments
 (0)