• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 */
15
16function main(): void {
17    let a: byte = 2;
18    let b: short = 20000;
19    let c: int = 2000000;
20    let d: long = 200000000000;
21    let e: float = 2.2f;
22    let f: double = 2.2222222222;
23    let g: double[] = [a, b, c, d, e, f];
24    assertEQ(g[0], 2)
25    assertEQ(g[1], 20000)
26    assertEQ(g[2], 2000000)
27    assertEQ(g[3], 200000000000)
28    assertEQ(g[4], (2.2 as float))
29    assertEQ(g[5], 2.2222222222)
30
31    const h: byte = 2;
32    const i: short = 2;
33    const j: int = 2;
34    const k: long = 2;
35    const l: float = 2.0f;
36    const m: double = 2.0;
37    const n: byte[] = [h, i, j, k, Float.toByte(l), Double.toByte(m)];
38    assertEQ(n[0], 2)
39    assertEQ(n[1], 2)
40    assertEQ(n[2], 2)
41    assertEQ(n[3], 2)
42    assertEQ(n[4], 2)
43    assertEQ(n[5], 2)
44
45    let o: Object[] = [1, 1.1, "testStr", new Int(2), d, k];
46    assertEQ(o[0] as Int, 1)
47    assertEQ(o[1] as Double, 1.1)
48    assertTrue((o[2] as String).equals("testStr"))
49    assertEQ(o[3] as Int, 2)
50    assertEQ(o[4] as Long, 200000000000)
51    assertEQ(o[5] as Long, 2)
52
53    let p: long[] = [new Int(3), new Short(2 as short), new Long(4)];
54    assertEQ(p[0], 3)
55    assertEQ(p[1], 2)
56    assertEQ(p[2], 4)
57}
58