• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 */
15declare function print(arg:any):void;
16
17function testcase1() {
18    let testArray: Int32Array = new Int32Array([1, 2, 3]);
19    let len: number = testArray.length;
20    let a: number = testArray[0];
21    let res: number = 5 + len;
22    print(res)
23}
24
25function testcase2() {
26    let testArray: Int32Array = new Int32Array([1, 2, 3]);
27    let a: number = testArray[0];
28    let len: number = testArray.length - 1;
29    let res: number = 6 + len;
30    print(res)
31}
32
33function testcase3() {
34    let testArray: Int32Array = new Int32Array([1, 2, 3]);
35    let len: number = testArray.length;
36    let sum: number = 0;
37    for(let i = 0; i < len; i++) {
38        print(i + 1);
39        sum += testArray[i];
40    }
41}
42
43function testcase4() {
44    let testArray: Int32Array = new Int32Array([1, 2, 3]);
45    let len: number = testArray.length - 1;
46    let sum: number = 0;
47    for(let i = 0; i < len; i++) {
48        sum += testArray[i];
49        print(i + 1);
50    }
51}
52
53function testcase5() {
54    let testArray: number[] = [1, 2, 3];
55    let a: number = testArray[0];
56    let res: number = 5 + testArray.length;
57    print(res);
58}
59
60function testcase6() {
61    let testArray: number[] = [1, 2, 3];
62    let len: number = testArray.length - 1;
63    let sum: number = 0;
64    let i: number = 0;
65    for(let i = 0; i < len; i++) {
66        sum += testArray[i];
67        print(i + 1);
68    }
69}
70
71testcase1();  // 8
72testcase2();  // 8
73
74testcase3();
75testcase4();
76
77testcase5();
78testcase6();