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