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 */
15
16declare function print(a:any):string;
17
18var LOOP_TIME = 100;
19
20class C {
21    x:number;
22    constructor() {
23        this.x = 123;
24    }
25}
26
27let c1 = new C();
28print(c1.x);
29
30let c2 = new C();
31print(c2.x);
32
33
34function foo(p) {
35    return p[1]
36}
37
38{
39	let a = [1, 2]
40	let b = [1, 2.1, 3]
41	for (let i = 0; i < 10000; i++) {
42		var a1 = foo(a)
43		var a2 = foo(b);
44	}
45	print(a1)
46	print(a2)
47}
48
49// test stownbyindex ic: (too many loop will fail at debug unittest timeout)
50class Attrs {
51	constructor(a : number, b : number, c : number) {
52		this.x = a;
53		this.y = b;
54		this.z = c;
55	}
56	x : number;
57	y : number;
58	z : number;
59}
60
61for (let i = 0; i < LOOP_TIME; i++){
62	for (let j = 0; j < 5; ++j) {
63		var _attrs : Attrs[] = [
64			new Attrs(1, 1, 1),
65			new Attrs(2, 2, 2),
66			new Attrs(3, 3, 3),
67			new Attrs(4, 4, 4),
68			new Attrs(5, 5, 5),
69		];
70		if (i == LOOP_TIME - 1) {
71			print(_attrs[j].x);
72		}
73	}
74}
75
76const tests = [
77	[99.99, "ark"],
78	[-88.48, "brk"],
79	[-1024, "crk"],
80	[6666, "drk"],
81];
82
83for (let i = 0; i < LOOP_TIME; i++){
84    for (const [number, strData] of tests) {
85		if (i == LOOP_TIME - 1) {
86			print(number);
87			print(strData);
88		}
89    }
90}
91
92const exceptions = {
93	"minute" : {
94	  	"-1" : "1 minute ago",
95	  	'0' : 'this minute',
96	  	"1" : "in 1 minute",
97	},
98	"second" : {
99	  	"-1" : "1 second ago",
100	  	"0" : "now",
101	  	"1" : "in 1 second",
102	},
103};
104
105const units = [
106	"second",
107	"minute",
108];
109
110for (let i = 0; i < LOOP_TIME; i++){
111    for (const unit of units) {
112		const expected = unit in exceptions ?
113			[exceptions[unit]["1"], exceptions[unit]["0"], exceptions[unit]["0"], exceptions[unit]["-1"]] :
114			[`in 1 ${unit}`, `in 0 ${unit}s`, `0 ${unit}s ago`, `1 ${unit} ago`];
115		if (i == LOOP_TIME - 1) {
116			print(expected);
117		}
118    }
119}
120
121for (let i = 0; i < LOOP_TIME; i++){
122    Object.defineProperty(Array.prototype, '0', {
123        value: 42,
124    });
125    let arr = [, 2, 3];
126    arr.pop();
127	if (i == LOOP_TIME - 1) {
128		print(arr[1]);
129	}
130}
131
132
133for (let i = 0; i < LOOP_TIME; i++){
134    var a : any[] = [ ["ok"], [1, 2, 3] ];
135    var b = {
136        1 : ["yes", "no"],
137        "100" : [4, 5],
138    }
139	if (i == LOOP_TIME - 1) {
140		print(a[0][0]);
141		print(a[1][0]);
142		print(a[1][1]);
143		print(a[1][2]);
144		
145		print(b[1][0]);
146		print(b[1][1]);
147		print(b["100"][0]);
148		print(b["100"][1]);
149	}
150}
151
152
153