• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 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 */
15class A1 {
16    fld: Int[]
17    constructor(p: Int[], q: Int[]) {
18        this.fld = [...p, ...q]
19    }
20    meth(): Int[] {
21        return [10, 20, ...this.fld, 30]
22    }
23}
24
25class B1 extends A1 {
26    constructor(p: Int[], q: Int[]) {
27        super(p, q)
28    }
29    meth(): Int[] {
30        return [10, 20, ...this.fld, 30]
31    }
32}
33
34class A2 {
35    private _fld: Boolean[] = []
36    constructor(p: Boolean[], q: Boolean[]) {
37        this.fld = [...p, ...q]
38    }
39    meth() : Boolean[] {
40        return [true, ...this.fld, false]
41    }
42    get fld(): Boolean[]{
43        return this._fld;
44    }
45    set fld(v: Boolean[]) {
46        this._fld = v;
47    }
48}
49
50class B2 extends A2 {
51    constructor(p: Boolean[], q: Boolean[]) {
52        super(p, q)
53    }
54    meth(): Boolean[] {
55        return [true, ...super.fld, false]
56    }
57}
58
59function main() {
60    let a1: A1 = new A1([1, 2], [3])
61    let arr1 = [...a1.meth()]
62    assertEQ(arr1.length, 6)
63    assertTrue(arr1[0] == 10 && arr1[1] == 20 && arr1[2] == 1)
64    assertTrue(arr1[3] == 2 && arr1[4] == 3 && arr1[5] == 30)
65
66    let b1: B1 = new B1([1, 2], [3])
67    let arr2 = [...b1.meth()]
68    assertEQ(arr2.length, 6)
69    assertTrue(arr2[0] == 10 && arr2[1] == 20 && arr2[2] == 1)
70    assertTrue(arr2[3] == 2 && arr2[4] == 3 && arr2[5] == 30)
71
72    let a2: A2 = new A2([false], [true, false])
73    let arr3: Boolean[] = [...a2.meth()]
74    assertEQ(arr3.length, 5)
75    assertTrue(arr3[0] == true && arr3[1] == false && arr3[2] == true)
76    assertTrue(arr3[3] == false && arr3[4] == false)
77
78    let b2: B2 = new B2([false], [true, false])
79    let arr4: Boolean[] = [...b2.meth()]
80    assertEQ(arr4.length, 5)
81    assertTrue(arr4[0] == true && arr4[1] == false && arr4[2] == true)
82    assertTrue(arr4[3] == false && arr4[4] == false)
83
84}