Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | function test() { |
michael@0 | 2 | this.init(); |
michael@0 | 3 | for (var i=0; i<10; i++) { |
michael@0 | 4 | delete this.blocks[10][9]; |
michael@0 | 5 | this.collapse_blocks(); |
michael@0 | 6 | } |
michael@0 | 7 | this.look_for_holes(); |
michael@0 | 8 | } |
michael@0 | 9 | test.prototype.init = function() { |
michael@0 | 10 | this.blocks = new Array(20); |
michael@0 | 11 | for (var x=0; x<this.blocks.length; x++) { |
michael@0 | 12 | this.blocks[x] = new Array(10); |
michael@0 | 13 | for (var y=0; y<this.blocks[x].length; y++) { |
michael@0 | 14 | this.blocks[x][y] = {}; |
michael@0 | 15 | } |
michael@0 | 16 | } |
michael@0 | 17 | } |
michael@0 | 18 | test.prototype.move_block = function(x,y,x1,y1) { |
michael@0 | 19 | this.blocks[x][y] = this.blocks[x1][y1]; |
michael@0 | 20 | if (this.blocks[x][y]) |
michael@0 | 21 | delete this.blocks[x1][y1]; |
michael@0 | 22 | } |
michael@0 | 23 | test.prototype.collapse_blocks = function() { |
michael@0 | 24 | var didSomething=0; |
michael@0 | 25 | do { |
michael@0 | 26 | didSomething=0; |
michael@0 | 27 | for (var x=0; x<this.blocks.length; x++) |
michael@0 | 28 | for (var y=1; y<this.blocks[x].length; y++) { |
michael@0 | 29 | if (!this.blocks[x][y] && this.blocks[x][y-1]) { |
michael@0 | 30 | this.move_block(x,y,x,y-1); |
michael@0 | 31 | didSomething=1; |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | } while (didSomething); |
michael@0 | 35 | |
michael@0 | 36 | do { |
michael@0 | 37 | didSomething = 0; |
michael@0 | 38 | for (var x=0; x<this.blocks.length-1; x++) { |
michael@0 | 39 | if (!this.blocks[x][9] && this.blocks[x+1][9]) { |
michael@0 | 40 | for (var y=0; y<this.blocks[x].length; y++) |
michael@0 | 41 | this.move_block(x,y,x+1,y); |
michael@0 | 42 | didSomething = 1; |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | } while (didSomething); |
michael@0 | 46 | } |
michael@0 | 47 | test.prototype.look_for_holes = function() { |
michael@0 | 48 | var was_empty = false; |
michael@0 | 49 | var n_empty = 0; |
michael@0 | 50 | for (var x=0; x<this.blocks.length; x++) { |
michael@0 | 51 | var empty = true; |
michael@0 | 52 | for (var y=0; y<this.blocks[x].length; y++) { |
michael@0 | 53 | if (this.blocks[x][y]) { |
michael@0 | 54 | empty = false; |
michael@0 | 55 | n_empty++; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | if (was_empty) |
michael@0 | 59 | assertEq(empty, true); |
michael@0 | 60 | was_empty = empty; |
michael@0 | 61 | } |
michael@0 | 62 | assertEq(n_empty, 190); |
michael@0 | 63 | } |
michael@0 | 64 | new test(); |