13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci* Copyright (c) 2022-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci* you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci* You may obtain a copy of the License at 63af6ab5fSopenharmony_ci* 73af6ab5fSopenharmony_ci* http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci* 93af6ab5fSopenharmony_ci* Unless required by applicable low or agreed to in writing, software 103af6ab5fSopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci* See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci* limitations under the License. 143af6ab5fSopenharmony_ci*/ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_cilet count = 2 173af6ab5fSopenharmony_cilet n = 9 183af6ab5fSopenharmony_cilet a: int[] = new int[count]; 193af6ab5fSopenharmony_cilet v: int[] = new int[count]; 203af6ab5fSopenharmony_citype P = Promise<Int> | null 213af6ab5fSopenharmony_cifunction assert_eq(value1: int, value2: int): void { 223af6ab5fSopenharmony_ci if (value1 == value2) { 233af6ab5fSopenharmony_ci return; 243af6ab5fSopenharmony_ci } 253af6ab5fSopenharmony_ci console.println("Values of type int are not equal: " + value1 + " != " + value2); 263af6ab5fSopenharmony_ci throw new Error(); 273af6ab5fSopenharmony_ci} 283af6ab5fSopenharmony_cifunction ufib(n: int) : Int { 293af6ab5fSopenharmony_ci if (n >= 0 && n < count) { 303af6ab5fSopenharmony_ci return v[n]; 313af6ab5fSopenharmony_ci } 323af6ab5fSopenharmony_ci let p: P[] = new P[count] 333af6ab5fSopenharmony_ci for (let i = 0; i < count; ++i) { 343af6ab5fSopenharmony_ci p[i] = launch ufib(n-1-i); 353af6ab5fSopenharmony_ci } 363af6ab5fSopenharmony_ci let result = 0 373af6ab5fSopenharmony_ci for (let i = 0; i < count; ++i) { 383af6ab5fSopenharmony_ci result = result + p[i]!.awaitResolution() * a[i]; 393af6ab5fSopenharmony_ci } 403af6ab5fSopenharmony_ci return result; 413af6ab5fSopenharmony_ci} 423af6ab5fSopenharmony_cifunction ufib_seq(n: int) : int { 433af6ab5fSopenharmony_ci if (n >= 0 && n < count) { 443af6ab5fSopenharmony_ci return v[n]; 453af6ab5fSopenharmony_ci } 463af6ab5fSopenharmony_ci let result = 0 473af6ab5fSopenharmony_ci for (let i = 0; i < count; ++i) { 483af6ab5fSopenharmony_ci result = result + ufib_seq(n-1-i) * a[i]; 493af6ab5fSopenharmony_ci } 503af6ab5fSopenharmony_ci return result; 513af6ab5fSopenharmony_ci} 523af6ab5fSopenharmony_ciexport function main(): int { 533af6ab5fSopenharmony_ci a[0] = 2; 543af6ab5fSopenharmony_ci v[0] = 6; 553af6ab5fSopenharmony_ci a[1] = 2; 563af6ab5fSopenharmony_ci v[1] = 7; 573af6ab5fSopenharmony_ci let seq_result = ufib_seq(n); 583af6ab5fSopenharmony_ci let p = launch ufib(n); 593af6ab5fSopenharmony_ci let co_result = p.awaitResolution(); 603af6ab5fSopenharmony_ci assert_eq(co_result as int, seq_result); 613af6ab5fSopenharmony_ci return 0; 623af6ab5fSopenharmony_ci} 63