1/*
2 * Copyright (c) 2021-2024 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
16class A {}
17
18function main(): int {
19  classEquality();
20  arrayEquality();
21  functiontypeEquality();
22  nullEquality();
23  return 0;
24}
25
26function classEquality(): void {
27  let a = new A;
28  let b = a;
29  assert (a == b);
30  b = new A;
31  assert (a != b);
32}
33
34function arrayEquality(): void {
35  let a : int[] = null;
36  let b = a;
37  assert (a == b);
38}
39
40function functiontypeEquality(): void {
41  let a : (x : double, y : double) : double;
42  let b = a;
43  assert (a == b);
44}
45
46function nullEquality(): void {
47  let a = new A;
48  let hit : int = 0;
49
50  if (a == null) {
51    assert(false);
52  } else {
53    hit = 1;
54  }
55  assert (hit == 1);
56
57  if (a != null) {
58    hit = 2;
59  } else {
60    assert(false);
61  }
62  assert (hit == 2);
63
64  if (null == a) {
65    assert(false);
66  } else {
67    hit = 3;
68  }
69  assert (hit == 3);
70
71  if (null != a) {
72    hit = 4;
73  } else {
74    assert(false);
75  }
76  assert (hit == 4);
77
78
79  a = null;
80
81  if (a != null) {
82    assert(false);
83  } else {
84    hit = 1;
85  }
86  assert (hit == 1);
87
88  if (a == null) {
89    hit = 2;
90  } else {
91    assert(false);
92  }
93  assert (hit == 2);
94
95  if (null != a) {
96    assert(false);
97  } else {
98    hit = 3;
99  }
100  assert (hit == 3);
101
102  if (null == a) {
103    hit = 4;
104  } else {
105    assert(false);
106  }
107  assert (hit == 4);
108}
109