14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_cideclare function print(str:any):string;
174514f5e3Sopenharmony_ci
184514f5e3Sopenharmony_civar first = 0;
194514f5e3Sopenharmony_civar second = 1;
204514f5e3Sopenharmony_civar hundred = "100";
214514f5e3Sopenharmony_ci
224514f5e3Sopenharmony_ci// test array
234514f5e3Sopenharmony_civar array = [100, "hello"];
244514f5e3Sopenharmony_ciprint(array[first]);
254514f5e3Sopenharmony_ciprint(array[second]);
264514f5e3Sopenharmony_ciarray[first] = "helloworld";
274514f5e3Sopenharmony_ciarray[second] = 200;
284514f5e3Sopenharmony_ciprint(array[first]);
294514f5e3Sopenharmony_ciprint(array[second]);
304514f5e3Sopenharmony_ci
314514f5e3Sopenharmony_cilet arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
324514f5e3Sopenharmony_ciarr[0] = 999;
334514f5e3Sopenharmony_ciprint(arr[0])
344514f5e3Sopenharmony_ci
354514f5e3Sopenharmony_ci
364514f5e3Sopenharmony_ci// test object
374514f5e3Sopenharmony_cilet phrase: { 0: string, "100": string | number, fullPhrase: any } = {
384514f5e3Sopenharmony_ci    0 : "100",
394514f5e3Sopenharmony_ci    "100" : "hello",
404514f5e3Sopenharmony_ci
414514f5e3Sopenharmony_ci    get fullPhrase() {
424514f5e3Sopenharmony_ci        return `${this[first]} ${this[hundred]}`;
434514f5e3Sopenharmony_ci    },
444514f5e3Sopenharmony_ci
454514f5e3Sopenharmony_ci    set fullPhrase(value) {
464514f5e3Sopenharmony_ci        [this[first], this[hundred]] = value.split(" ");
474514f5e3Sopenharmony_ci    }
484514f5e3Sopenharmony_ci};
494514f5e3Sopenharmony_ciprint(phrase[first]);
504514f5e3Sopenharmony_ciprint(phrase[hundred]);
514514f5e3Sopenharmony_ciphrase[first] = "helloworld";
524514f5e3Sopenharmony_ciphrase[hundred] = 1;
534514f5e3Sopenharmony_ciprint(phrase[first]);
544514f5e3Sopenharmony_ciprint(phrase[hundred]);
554514f5e3Sopenharmony_ci
564514f5e3Sopenharmony_ci// test class
574514f5e3Sopenharmony_ciclass ParticleSystemCPU {
584514f5e3Sopenharmony_ci    private _arrayTest: number[];
594514f5e3Sopenharmony_ci
604514f5e3Sopenharmony_ci    constructor() {
614514f5e3Sopenharmony_ci        this._arrayTest = new Array(10);
624514f5e3Sopenharmony_ci        this._arrayTest[9] = 19;
634514f5e3Sopenharmony_ci        print(this._arrayTest[9]); // 19
644514f5e3Sopenharmony_ci    }
654514f5e3Sopenharmony_ci}
664514f5e3Sopenharmony_ci
674514f5e3Sopenharmony_civar system: ParticleSystemCPU[] = [new ParticleSystemCPU()];
684514f5e3Sopenharmony_ci
694514f5e3Sopenharmony_ci
704514f5e3Sopenharmony_ci// test getter and setter
714514f5e3Sopenharmony_ciprint(phrase.fullPhrase);
724514f5e3Sopenharmony_ciphrase.fullPhrase = "world hello";
734514f5e3Sopenharmony_ciprint(phrase.fullPhrase);
744514f5e3Sopenharmony_ci
754514f5e3Sopenharmony_ci// test COW array
764514f5e3Sopenharmony_cifunction generateCOWArray() : number[] {
774514f5e3Sopenharmony_ci    return [0, 1, 2, 3, 4]
784514f5e3Sopenharmony_ci}
794514f5e3Sopenharmony_ci
804514f5e3Sopenharmony_cilet arrayA : number [] = generateCOWArray();
814514f5e3Sopenharmony_cilet arrayB : number [] = generateCOWArray();
824514f5e3Sopenharmony_ci
834514f5e3Sopenharmony_ciarrayB[3] = 11;
844514f5e3Sopenharmony_ciprint(arrayB[3]) // expect 11
854514f5e3Sopenharmony_ciprint(arrayA[3]) // expect 3