1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// @ts-ignore 17import {Utils} from "../../../../../dist/trace/component/trace/base/Utils.js"; 18 19describe("Utils Test", () => { 20 beforeAll(() => { 21 }) 22 23 it('Utils Test01', () => { 24 let instance = Utils.getInstance(); 25 let instance2 = Utils.getInstance(); 26 expect(instance).toBe(instance2) 27 }); 28 29 it('Utils Test02', () => { 30 let instance = Utils.getInstance(); 31 expect(instance.getStatusMap().get("D")).toBe("Uninterruptible Sleep") 32 }); 33 34 it('Utils Test03', () => { 35 expect(Utils.getEndState("D")).toBe("Uninterruptible Sleep") 36 }); 37 38 it('Utils Test04', () => { 39 expect(Utils.getEndState("")).toBe("") 40 }); 41 42 it('Utils Test05', () => { 43 expect(Utils.getEndState("ggg")).toBe("Unknown State") 44 }); 45 46 it('Utils Test06', () => { 47 expect(Utils.getStateColor("D")).toBe("#f19b38") 48 }); 49 50 it('Utils Test07', () => { 51 expect(Utils.getStateColor("R")).toBe("#a0b84d") 52 }); 53 it('Utils Test08', () => { 54 expect(Utils.getStateColor("I")).toBe("#673ab7") 55 }); 56 57 it('Utils Test09', () => { 58 expect(Utils.getStateColor("Running")).toBe("#467b3b") 59 }); 60 61 it('Utils Test09', () => { 62 expect(Utils.getStateColor("S")).toBe("#e0e0e0") 63 }); 64 65 66 it('Utils Test10', () => { 67 expect(Utils.getTimeString(5900_000_000_000)).toBe("1h 38m ") 68 }); 69 70 it('Utils Test11', () => { 71 expect(Utils.getByteWithUnit(2_000_000_000)).toBe("1.86 Gb") 72 }); 73 74 it('Utils Test12', () => { 75 expect(Utils.getByteWithUnit(1_000_000_000)).toBe("953.67 Mb") 76 }); 77 78 it('Utils Test13', () => { 79 expect(Utils.getByteWithUnit(1000_000)).toBe("976.56 Kb") 80 }); 81 82 it('Utils Test23', () => { 83 expect(Utils.getByteWithUnit(-2_000)).toBe("-1.95 Kb") 84 }); 85 86 it('Utils Test14', () => { 87 expect(Utils.getTimeString( 1_000_000_000_000)).toBe("16m 40s ") 88 }); 89 90 it('Utils Test15', () => { 91 expect(Utils.getTimeString( 2_000_000)).toBe("2ms ") 92 }); 93 94 it('Utils Test16', () => { 95 expect(Utils.getTimeString( 3_000)).toBe("3μs ") 96 }); 97 98 it('Utils Test17', () => { 99 expect(Utils.getTimeString( 300)).toBe("300ns ") 100 }); 101 102 it('Utils Test18', () => { 103 expect(Utils.getTimeStringHMS(5900_000_000_000)).toBe("1:38:") 104 }); 105 106 it('Utils Test19', () => { 107 expect(Utils.getTimeStringHMS(3_000_000_000)).toBe("3:") 108 }); 109 110 it('Utils Test20', () => { 111 expect(Utils.getTimeStringHMS(2_000_000)).toBe("2.") 112 }); 113 114 it('Utils Test21', () => { 115 expect(Utils.getTimeStringHMS(5_000)).toBe("5.") 116 }); 117 118 it('Utils Test22', () => { 119 expect(Utils.getTimeStringHMS(90)).toBe("90") 120 }); 121 122 it('Utils Test24', () => { 123 expect(Utils.getBinaryByteWithUnit(0)).toBe("0Bytes") 124 }); 125 126 it('Utils Test25', () => { 127 expect(Utils.getBinaryByteWithUnit(3_000_000_000)).toBe("2.79Gib") 128 }); 129 130 it('Utils Test26', () => { 131 expect(Utils.getBinaryByteWithUnit(2_000_000)).toBe("1.91Mib") 132 }); 133 134 it('Utils Test27', () => { 135 expect(Utils.getBinaryByteWithUnit(2_000)).toBe("1.95kib") 136 }); 137 138 it('Utils Test28', () => { 139 expect(Utils.getTimeStampHMS(3900_000_000_000)).toBe("01:05:00:000.000") 140 }); 141 142 it('Utils Test29', () => { 143 expect(Utils.getTimeStampHMS(70_000_000_000)).toBe("01:10:000.000") 144 }); 145 146 it('Utils Test30', () => { 147 expect(Utils.getTimeStampHMS(2_000_000_000)).toBe("02:000.000") 148 }); 149 150 it('Utils Test31', () => { 151 expect(Utils.getTimeStampHMS(2_000_000)).toBe("00:002.000") 152 }); 153 154 it('Utils Test32', () => { 155 expect(Utils.getTimeStampHMS(2_000)).toBe("00:000.002.") 156 }); 157 158 it('Utils Test33', () => { 159 expect(Utils.getTimeStampHMS(1)).toBe("00:000.000001") 160 }); 161 162 it('Utils Test40', () => { 163 expect(Utils.getDurString(61_000_000_000)).toBe("61.000 s ") 164 }); 165 166 it('Utils Test34', () => { 167 expect(Utils.getDurString(2_000_000_000)).toBe("2.000 s ") 168 }); 169 170 it('Utils Test35', () => { 171 expect(Utils.getDurString(1_800_000)).toBe("1 ms ") 172 }); 173 174 it('Utils Test36', () => { 175 expect(Utils.timeMsFormat2p(3800_000)).toBe("1.00h") 176 }); 177 178 it('Utils Test37', () => { 179 expect(Utils.timeMsFormat2p(90_000)).toBe("1.00min") 180 }); 181 182 it('Utils Test38', () => { 183 expect(Utils.timeMsFormat2p(2_000)).toBe("2.00s") 184 }); 185 186 it('Utils Test39', () => { 187 expect(Utils.timeMsFormat2p(1)).toBe("1.00ms") 188 }); 189 190 it('Utils Test41', () => { 191 expect(Utils.getProbablyTime(3600_000_000_000)).toBe("1.00h "); 192 }); 193 194 it('Utils Test42', () => { 195 expect(Utils.getProbablyTime(60_000_000_000)).toBe("1.00m "); 196 }); 197 198 it('Utils Test43', () => { 199 expect(Utils.getProbablyTime(1_000_000_000)).toBe("1.00s "); 200 }); 201 202 it('Utils Test44', () => { 203 expect(Utils.getProbablyTime(1_000_000)).toBe("1.00ms "); 204 }); 205 206 it('Utils Test45', () => { 207 expect(Utils.getProbablyTime(1_000)).toBe("1.00μs "); 208 }); 209 210 it('Utils Test46', () => { 211 expect(Utils.getProbablyTime(0)).toBe("0"); 212 }); 213 214 it('Utils Test47', () => { 215 expect(Utils.groupByMap([],'')).not.toBeUndefined(); 216 }); 217 218 it('Utils Test48', () => { 219 expect(Utils.uuid).not.toBeUndefined(); 220 }); 221 222 it('Utils Test49', () => { 223 expect(Utils.removeDuplicates([10],[11],"pid")).not.toBeUndefined(); 224 }); 225 226 it('Utils Test50', () => { 227 expect(Utils.groupBy([],'')).not.toBeUndefined(); 228 }); 229 230 it('Utils Test51', () => { 231 expect(Utils.getTimeStringHMS(0)).toBe("0"); 232 }); 233 234 it('Utils Test52', () => { 235 expect(Utils.timeMsFormat2p(0)).toBe("0s"); 236 }); 237 238 it('Utils Test53', () => { 239 expect(Utils.getBinaryByteWithUnit(1)).toBe("1.00Bytes"); 240 }); 241 242 it('Utils Test54', () => { 243 expect(Utils.getTimeStampHMS(0)).toBe("00:000.000"); 244 }); 245 246 it('Utils Test55', () => { 247 expect(Utils.getDurString(1)).toBe("1") 248 }); 249 250 it('Utils Test56', () => { 251 expect(Utils.getCompletionTime(300,3)).toBe('300'); 252 }); 253 254 it('Utils Test57', () => { 255 expect(Utils.getCompletionTime(30,3)).toBe('030'); 256 }); 257 258 it('Utils Test58', () => { 259 expect(Utils.getCompletionTime(0,0)).toBe('0'); 260 }); 261 262 it('Utils Test59', () => { 263 expect(Utils.groupByMap([10],'pid')).not.toBeUndefined(); 264 }); 265 266 it('Utils Test60', () => { 267 expect(Utils.getProbablyTime(1)).toBe("1ns "); 268 }); 269 270 it('Utils Test61', () => { 271 expect(Utils.groupBy([10],'pid')).not.toBeUndefined(); 272 }); 273 274 afterAll(() => { 275 // 后处理操作 276 }) 277})