From 1452aa7e7b2f2bd73bc82067ddf70b646867aea5 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Wed, 9 Apr 2014 21:02:16 -0700 Subject: [PATCH] random testing --- spec/LayoutSpec.js | 35 +++++++++++++++++++++++++++++++++++ style.css | 7 ------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/spec/LayoutSpec.js b/spec/LayoutSpec.js index 7c4a565c..fd471e3f 100755 --- a/spec/LayoutSpec.js +++ b/spec/LayoutSpec.js @@ -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)}); + } + }) + }); diff --git a/style.css b/style.css index a86d8fef..073ce0db 100644 --- a/style.css +++ b/style.css @@ -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;