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
16declare function print(str:any):string;
17
18var first = 0;
19var second = 1;
20var hundred = "100";
21
22// test array
23var array = [100, "hello"];
24print(array[first]);
25print(array[second]);
26array[first] = "helloworld";
27array[second] = 200;
28print(array[first]);
29print(array[second]);
30
31let arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
32arr[0] = 999;
33print(arr[0])
34
35
36// test object
37let phrase: { 0: string, "100": string | number, fullPhrase: any } = {
38    0 : "100",
39    "100" : "hello",
40
41    get fullPhrase() {
42        return `${this[first]} ${this[hundred]}`;
43    },
44
45    set fullPhrase(value) {
46        [this[first], this[hundred]] = value.split(" ");
47    }
48};
49print(phrase[first]);
50print(phrase[hundred]);
51phrase[first] = "helloworld";
52phrase[hundred] = 1;
53print(phrase[first]);
54print(phrase[hundred]);
55
56// test class
57class ParticleSystemCPU {
58    private _arrayTest: number[];
59
60    constructor() {
61        this._arrayTest = new Array(10);
62        this._arrayTest[9] = 19;
63        print(this._arrayTest[9]); // 19
64    }
65}
66
67var system: ParticleSystemCPU[] = [new ParticleSystemCPU()];
68
69
70// test getter and setter
71print(phrase.fullPhrase);
72phrase.fullPhrase = "world hello";
73print(phrase.fullPhrase);
74
75// test COW array
76function generateCOWArray() : number[] {
77    return [0, 1, 2, 3, 4]
78}
79
80let arrayA : number [] = generateCOWArray();
81let arrayB : number [] = generateCOWArray();
82
83arrayB[3] = 11;
84print(arrayB[3]) // expect 11
85print(arrayA[3]) // expect 3