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// @ts-ignore 16import { objectToMemorySize } from '../../../dist/hdc/common/ObjectToMemorySize.js'; 17describe('ObjectToMemoryTest', () => { 18 let obj = new objectToMemorySize(); 19 it('ObjectToMemoryTest_objectToSize_01', () => { 20 expect(obj.objectToSize(12)).toEqual(8); 21 }); 22 23 it('ObjectToMemoryTest_objectToSize_02', () => { 24 expect(obj.objectToSize(true)).toEqual(4); 25 }); 26 27 it('ObjectToMemoryTest_objectToSize_03', () => { 28 expect(obj.objectToSize('abc')).toEqual(6); 29 }); 30 31 it('ObjectToMemoryTest_objectToSize_04', () => { 32 expect(obj.objectToSize([1, 2])).toEqual(16); 33 }); 34 35 it('ObjectToMemoryTest_objectToSize_05', () => { 36 expect(obj.objectToSize({ name: 'demo', age: 12 })).toEqual(30); 37 }); 38 39 it('ObjectToMemoryTest_sizeOfObj_01', () => { 40 expect(obj.sizeOfObj(null)).toEqual(0); 41 }); 42 43 it('ObjectToMemoryTest_sizeOfObj_02', () => { 44 expect(obj.sizeOfObj(12)).toEqual(0); 45 }); 46 47 it('ObjectToMemoryTest_sizeOfObj_03', () => { 48 expect(obj.sizeOfObj(false)).toEqual(0); 49 }); 50 51 it('ObjectToMemoryTest_sizeOfObj_04', () => { 52 expect(obj.sizeOfObj(false)).toEqual(0); 53 }); 54 55 it('ObjectToMemoryTest_sizeOfObj_05', () => { 56 expect(obj.sizeOfObj([1, 2])).toEqual(20); 57 }); 58 59 it('ObjectToMemoryTest_sizeOfObj_06', () => { 60 expect(obj.sizeOfObj({ name: 'demo', age: 12 })).toEqual(30); 61 }); 62 63 it('ObjectToMemoryTest_objectToSize_07', () => { 64 expect(obj.objectToSize(undefined)).toEqual(0); 65 }); 66 67 it('ObjectToMemoryTest_sizeOfObj_08', () => { 68 let object = { 69 [1]: 2, 70 [3]: 4, 71 [5]: 6, 72 [7]: 8, 73 }; 74 expect(obj.sizeOfObj(object)).toEqual(40); 75 }); 76}); 77