random testing

This commit is contained in:
Christopher Chedeau
2014-04-09 21:02:16 -07:00
parent d6e1efdb41
commit 1452aa7e7b
2 changed files with 35 additions and 7 deletions

View File

@@ -460,5 +460,40 @@ describe('Layout', function() {
});
});
it('should layout randomly', function() {
function RNG(seed) {
this.state = seed;
}
RNG.prototype.nextFloat = function() {
// LCG using GCC's constants
this.state = (1103515245 * this.state + 12345) % 0x80000000;
return this.state / (0x80000000 - 1);
}
var rng = new RNG(0);
function randMinMax(node, chance, attribute, min, max) {
if (rng.nextFloat() < chance) {
node.style[attribute] = Math.floor(rng.nextFloat() * (max - min)) + min;
}
}
function generateRandomNode() {
var node = {style: {}};
randMinMax(node, 0.1, 'width', 0, 1000);
randMinMax(node, 0.1, 'height', 0, 1000);
randMinMax(node, 0.1, 'margin', -5, 20);
randMinMax(node, 0.1, 'marginLeft', -5, 20);
randMinMax(node, 0.1, 'marginTop', -5, 20);
randMinMax(node, 0.1, 'marginRight', -5, 20);
randMinMax(node, 0.1, 'marginBottom', -5, 20);
return node;
}
for (var i = 0; i < 100; ++i) {
var node = generateRandomNode();
expect({node: node, layout: computeLayout(node)})
.toEqual({node: node, layout: computeDOMLayout(node)});
}
})
});

View File

@@ -1,11 +1,4 @@
* {
border-style: solid;
border-width: 0;
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
box-sizing: border-box;
display: flex;