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 16function add(arg : double[]): double { 17 return arg[0] + arg[1] + arg[2]; 18} 19 20// TODO(user): unify copyBooleanArr and copyCharArr once generics are supported 21function copyBooleanArr(src: boolean[]): boolean[] { 22 let dst: boolean[] = new boolean[src.length]; 23 for (let i = 0; i < src.length; i++) { 24 dst[i] = src[i]; 25 } 26 return dst; 27} 28 29// TODO(user): unify copyBooleanArr and copyCharArr once generics are supported 30function copyCharArr(src: char[]): char[] { 31 let dst: char[] = new char[src.length]; 32 for (let i = 0; i < src.length; i++) { 33 dst[i] = src[i]; 34 } 35 return dst; 36} 37 38// TODO(user): unify cmpBooleanArr and cmpCharArr once generics are supported 39function cmpBooleanArr(arg0: boolean[], arg1: boolean[]): boolean { 40 if (arg0.length != arg1.length) { 41 return false; 42 } 43 44 for (let i = 0; i < arg0.length; i++) { 45 if (arg0[i] != arg1[i]) { 46 return false; 47 } 48 } 49 50 return true; 51} 52 53// TODO(user): unify cmpBooleanArr and cmpCharArr once generics are supported 54function cmpCharArr(arg0: char[], arg1: char[]): boolean { 55 if (arg0.length != arg1.length) { 56 return false; 57 } 58 59 for (let i = 0; i < arg0.length; i++) { 60 if (arg0[i] != arg1[i]) { 61 return false; 62 } 63 } 64 65 return true; 66} 67 68function main(): void { 69 let arr : double[] = [1.1, 2.1, 3.5, 4.9]; 70 assert arr[0] == 1.1 && arr[1] == 2.1 && arr[2] == 3.5 && arr[3] == 4.9; 71 assert add([1.1, 2.2, 3.3]) == 6.6; 72 73 let arr2 : boolean[] = [false, true, false, true, true, false, false, true]; 74 assert cmpBooleanArr(copyBooleanArr(arr2), arr2); 75 76 let arr3 : char[] = [c'a', c'b', c'c', c'd']; 77 assert cmpCharArr(copyCharArr(arr3), arr3); 78 79 return; 80} 81