1/* 2 * Copyright (c) 2023-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 C { 17 private x: int[] = [1, 3, 5]; 18 private y: string[] = ["one", "two", "three"]; 19 20 $_get(ind: int) : int { 21 return this.x[ind]; 22 } 23 24 $_get(ind: string) : string { 25 if (ind == "1") return this.y[0]; 26 if (ind == "2") return this.y[1]; 27 if (ind == "3") return this.y[2]; 28 return "none"; 29 } 30 31 $_set(ind: int, val: int): void { 32 this.x[ind] = val; 33 } 34 35 $_set(ind: string, val: string): void { 36 if (ind == "1") this.y[0] = val; 37 if (ind == "2") this.y[1] = val; 38 if (ind == "3") this.y[2] = val; 39 } 40 41} 42 43function main(): void { 44 45 let x: int[] = [1, 3, 5]; 46 47 let y: int = x[0]; 48 let z = x[1]; 49 x[1] = x[2]; 50 x[2] *= 2; 51 52 let c = new C(); 53 54 let u = c[0]; 55 let v = c.$_get(1); 56 c[1] = c[2]; 57 c[2] *= 2; 58 59 assert(y == u); 60 assert(z == v) 61 assert(x[1] == c[1]) 62 assert(x[2] == c[2]) 63 assert(x[0] == c[0]) 64 65 assert(c['1'] == "one") 66 assert(c['2'] == "two") 67 assert(c["3"] == 'three') 68 assert(c['7'] == "none") 69 assert(c[""] == "none") 70 71 c['1'] = "один"; 72 c["2"] = c["3"]; 73 c["3"] += '|три'; 74 75 assert(c['1'] == 'один') 76 assert(c["2"] == 'three') 77 assert(c['3'] == "three|три") 78 assert(c['7'] == "none") 79 assert(c[""] == "none") 80 assert(c['1'] + c[1] == "один5") 81} 82