test_census-tree-node-06.js (4850B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 /** 6 * Test inverting CensusTreeNode with a by alloaction stack breakdown. 7 */ 8 9 function run_test() { 10 const BREAKDOWN = { 11 by: "allocationStack", 12 then: { by: "count", count: true, bytes: true }, 13 noStack: { by: "count", count: true, bytes: true }, 14 }; 15 16 function a(n) { 17 return b(n); 18 } 19 function b(n) { 20 return c(n); 21 } 22 function c(n) { 23 return saveStack(n); 24 } 25 function d(n) { 26 return b(n); 27 } 28 function e(n) { 29 return c(n); 30 } 31 32 const abc_Stack = a(3); 33 const bc_Stack = b(2); 34 const c_Stack = c(1); 35 const dbc_Stack = d(3); 36 const ec_Stack = e(2); 37 38 const REPORT = new Map([ 39 [abc_Stack, { bytes: 10, count: 1 }], 40 [bc_Stack, { bytes: 10, count: 1 }], 41 [c_Stack, { bytes: 10, count: 1 }], 42 [dbc_Stack, { bytes: 10, count: 1 }], 43 [ec_Stack, { bytes: 10, count: 1 }], 44 ["noStack", { bytes: 50, count: 5 }], 45 ]); 46 47 const EXPECTED = { 48 name: null, 49 bytes: 0, 50 totalBytes: 100, 51 count: 0, 52 totalCount: 10, 53 children: [ 54 { 55 name: "noStack", 56 bytes: 50, 57 totalBytes: 50, 58 count: 5, 59 totalCount: 5, 60 children: [ 61 { 62 name: null, 63 bytes: 0, 64 totalBytes: 100, 65 count: 0, 66 totalCount: 10, 67 children: undefined, 68 id: 16, 69 parent: 15, 70 reportLeafIndex: undefined, 71 }, 72 ], 73 id: 15, 74 parent: 14, 75 reportLeafIndex: 6, 76 }, 77 { 78 name: abc_Stack, 79 bytes: 50, 80 totalBytes: 10, 81 count: 5, 82 totalCount: 1, 83 children: [ 84 { 85 name: null, 86 bytes: 0, 87 totalBytes: 100, 88 count: 0, 89 totalCount: 10, 90 children: undefined, 91 id: 18, 92 parent: 17, 93 reportLeafIndex: undefined, 94 }, 95 { 96 name: abc_Stack.parent, 97 bytes: 0, 98 totalBytes: 10, 99 count: 0, 100 totalCount: 1, 101 children: [ 102 { 103 name: null, 104 bytes: 0, 105 totalBytes: 100, 106 count: 0, 107 totalCount: 10, 108 children: undefined, 109 id: 22, 110 parent: 19, 111 reportLeafIndex: undefined, 112 }, 113 { 114 name: abc_Stack.parent.parent, 115 bytes: 0, 116 totalBytes: 10, 117 count: 0, 118 totalCount: 1, 119 children: [ 120 { 121 name: null, 122 bytes: 0, 123 totalBytes: 100, 124 count: 0, 125 totalCount: 10, 126 children: undefined, 127 id: 21, 128 parent: 20, 129 reportLeafIndex: undefined, 130 }, 131 ], 132 id: 20, 133 parent: 19, 134 reportLeafIndex: undefined, 135 }, 136 { 137 name: dbc_Stack.parent.parent, 138 bytes: 0, 139 totalBytes: 10, 140 count: 0, 141 totalCount: 1, 142 children: [ 143 { 144 name: null, 145 bytes: 0, 146 totalBytes: 100, 147 count: 0, 148 totalCount: 10, 149 children: undefined, 150 id: 24, 151 parent: 23, 152 reportLeafIndex: undefined, 153 }, 154 ], 155 id: 23, 156 parent: 19, 157 reportLeafIndex: undefined, 158 }, 159 ], 160 id: 19, 161 parent: 17, 162 reportLeafIndex: undefined, 163 }, 164 { 165 name: ec_Stack.parent, 166 bytes: 0, 167 totalBytes: 10, 168 count: 0, 169 totalCount: 1, 170 children: [ 171 { 172 name: null, 173 bytes: 0, 174 totalBytes: 100, 175 count: 0, 176 totalCount: 10, 177 children: undefined, 178 id: 26, 179 parent: 25, 180 reportLeafIndex: undefined, 181 }, 182 ], 183 id: 25, 184 parent: 17, 185 reportLeafIndex: undefined, 186 }, 187 ], 188 id: 17, 189 parent: 14, 190 reportLeafIndex: new Set([1, 2, 3, 4, 5]), 191 }, 192 ], 193 id: 14, 194 parent: undefined, 195 reportLeafIndex: undefined, 196 }; 197 198 compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { invert: true }); 199 }