test_compare_fragments_geometry.js (2864B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { 7 compareFragmentsGeometry, 8 } = require("resource://devtools/client/inspector/grids/utils/utils.js"); 9 10 const TESTS = [ 11 { 12 desc: "No fragments", 13 grids: [[], []], 14 expected: true, 15 }, 16 { 17 desc: "Different number of fragments", 18 grids: [ 19 [{}, {}, {}], 20 [{}, {}], 21 ], 22 expected: false, 23 }, 24 { 25 desc: "Different number of columns", 26 grids: [ 27 [{ cols: { lines: [{}, {}] }, rows: { lines: [] } }], 28 [{ cols: { lines: [{}] }, rows: { lines: [] } }], 29 ], 30 expected: false, 31 }, 32 { 33 desc: "Different number of rows", 34 grids: [ 35 [{ cols: { lines: [{}, {}] }, rows: { lines: [{}] } }], 36 [{ cols: { lines: [{}, {}] }, rows: { lines: [{}, {}] } }], 37 ], 38 expected: false, 39 }, 40 { 41 desc: "Different number of rows and columns", 42 grids: [ 43 [{ cols: { lines: [{}] }, rows: { lines: [{}] } }], 44 [{ cols: { lines: [{}, {}] }, rows: { lines: [{}, {}] } }], 45 ], 46 expected: false, 47 }, 48 { 49 desc: "Different column sizes", 50 grids: [ 51 [ 52 { 53 cols: { lines: [{ start: 0 }, { start: 500 }] }, 54 rows: { lines: [] }, 55 }, 56 ], 57 [ 58 { 59 cols: { lines: [{ start: 0 }, { start: 1000 }] }, 60 rows: { lines: [] }, 61 }, 62 ], 63 ], 64 expected: false, 65 }, 66 { 67 desc: "Different row sizes", 68 grids: [ 69 [ 70 { 71 cols: { lines: [{ start: 0 }, { start: 500 }] }, 72 rows: { lines: [{ start: -100 }] }, 73 }, 74 ], 75 [ 76 { 77 cols: { lines: [{ start: 0 }, { start: 500 }] }, 78 rows: { lines: [{ start: 0 }] }, 79 }, 80 ], 81 ], 82 expected: false, 83 }, 84 { 85 desc: "Different row and column sizes", 86 grids: [ 87 [ 88 { 89 cols: { lines: [{ start: 0 }, { start: 500 }] }, 90 rows: { lines: [{ start: -100 }] }, 91 }, 92 ], 93 [ 94 { 95 cols: { lines: [{ start: 0 }, { start: 505 }] }, 96 rows: { lines: [{ start: 0 }] }, 97 }, 98 ], 99 ], 100 expected: false, 101 }, 102 { 103 desc: "Complete structure, same fragments", 104 grids: [ 105 [ 106 { 107 cols: { lines: [{ start: 0 }, { start: 100.3 }, { start: 200.6 }] }, 108 rows: { lines: [{ start: 0 }, { start: 1000 }, { start: 2000 }] }, 109 }, 110 ], 111 [ 112 { 113 cols: { lines: [{ start: 0 }, { start: 100.3 }, { start: 200.6 }] }, 114 rows: { lines: [{ start: 0 }, { start: 1000 }, { start: 2000 }] }, 115 }, 116 ], 117 ], 118 expected: true, 119 }, 120 ]; 121 122 function run_test() { 123 for (const { desc, grids, expected } of TESTS) { 124 if (desc) { 125 info(desc); 126 } 127 equal(compareFragmentsGeometry(grids[0], grids[1]), expected); 128 } 129 }