1/* 2 * Copyright (c) 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 16/* 17 * @tc.name:sendablearray 18 * @tc.desc:test sendablearray 19 * @tc.type: FUNC 20 * @tc.require: issueI8QUU0 21 */ 22 23// @ts-nocheck 24declare function print(str: any): string; 25 26class SuperClass { 27 public num: number = 0; 28 constructor(num: number) { 29 "use sendable" 30 this.num = num; 31 } 32} 33 34class SubClass extends SuperClass { 35 public strProp: string = ""; 36 constructor(num: number) { 37 "use sendable" 38 super(num); 39 this.strProp = "" + num; 40 } 41} 42 43class SubSharedClass extends SendableArray { 44 constructor() { 45 'use sendable'; 46 super(); 47 } 48} 49 50class SuperUnSharedClass { 51 public num: number = 0; 52 constructor(num: number) { 53 this.num = num; 54 } 55} 56 57SendableArray.from<string>(['a', 'r', 'k']); 58 59function at() { 60 print("Start Test at") 61 const array1 = new SendableArray<number>(5, 12, 8, 130, 44); 62 let index = 2; 63 print(`An index of ${index} returns ${array1.at(index)}`); // An index of 2 returns 8 64 65 index = -2; 66 print(`An index of ${index} returns ${array1.at(index)}`); // An index of -2 returns 130 67 68 index = 200; 69 print(`An index of ${index} returns ${array1.at(index)}`); // An index of 200 returns undefined 70 71 print(`An index of null returns ${array1.at(null)}`); // An index of null returns 5 72 73 print(`An index of undefined returns ${array1.at(undefined)}`); // An index of undefined returns 5 74 75 print(`An index of undefined returns ${array1.at(true)}`); // An index of true returns 12 76 77 print(`An index of undefined returns ${array1.at(false)}`); // An index of false returns 5 78 79 index = 2871622679; 80 print(`An index of 2871622679 returns ${array1.at(index)}`); // An index of 2871622679 returns undefined 81} 82 83function entries() { 84 print("Start Test entries") 85 const array1 = new SendableArray<string>('a', 'b', 'c'); 86 const iterator = array1.entries(); 87 for (const [key, value] of iterator) { 88 print("" + key + "," + value); // 0 a, 1 b, 2 c 89 } 90} 91 92function keys() { 93 print("Start Test keys") 94 const array1 = new SendableArray<string>('a', 'b', 'c'); 95 const iterator = array1.keys(); 96 for (const key of iterator) { 97 print("" + key); // 0, 1, 2 98 } 99} 100 101function values() { 102 print("Start Test values") 103 const array1 = new SendableArray<string>('a', 'b', 'c'); 104 const iterator = array1.values(); 105 for (const value of iterator) { 106 print("" + value); // a, b, c 107 } 108} 109 110function find() { 111 print("Start Test find") 112 const array1 = new SendableArray<number>(5, 12, 8, 130, 44); 113 114 const found = array1.find((element: number) => element > 10); 115 print("" + found); // 12 116 117 const array2 = new SendableArray<SuperClass>( 118 new SubClass(5), 119 new SubClass(32), 120 new SubClass(8), 121 new SubClass(130), 122 new SubClass(44), 123 ); 124 const result: SubClass | undefined = array2.find<SubClass>( 125 (value: SuperClass, index: number, obj: SendableArray<SuperClass>) => value instanceof SubClass, 126 ); 127 print((new SubClass(5)).strProp); // 5 128} 129 130function includes() { 131 print("Start Test includes") 132 const array1 = new SendableArray<number>(1, 2, 3); 133 print("" + array1.includes(2)); // true 134 135 const pets = new SendableArray<string>('cat', 'dog', 'bat'); 136 print("" + pets.includes('cat')); // true 137 138 print("" + pets.includes('at')); // false 139} 140 141function index() { 142 print("Start Test index") 143 const array1 = new SendableArray<number>(5, 12, 8, 130, 44); 144 const isLargeNumber = (element: number) => element > 13; 145 print("" + array1.findIndex(isLargeNumber)); // 3 146 147} 148 149class IndexClass { 150 idx: number; 151 constructor() { 152 this.idx = 1; 153 } 154} 155 156function fill() { 157 print("Start Test fill") 158 const array1 = new SendableArray<number>(1, 2, 3, 4); 159 array1.fill(0, 2, 4); 160 print(array1); // [1, 2, 0, 0] 161 162 array1.fill(5, 1); 163 print(array1); // [1, 5, 5, 5] 164 165 array1.fill(6); 166 print(array1) // [6, 6, 6, 6] 167 168 array1.fill(1, true); 169 print(array1) // [6, 1, 1, 1] 170 171 array1.fill(2, null); 172 print(array1) // [2, 2, 2, 2] 173 174 array1.fill(3, undefined); 175 print(array1) // [3, 3, 3, 3] 176 177 array1.fill(4, 1.5, 3.5); 178 print(array1) // [3, 4, 4, 4] 179 180 array1.fill(5, "1.0", "3.5"); 181 print(array1) // [3, 5, 5, 5] 182 183 let superCs = new SuperClass(); 184 array1.fill(7, superCs, 4); 185 print(array1) // [7, 7, 7, 7] 186 187 let idxCs = new IndexClass(); 188 array1.fill(8, idxCs, 4); 189 print(array1) // [8, 8, 8, 8] 190 191 array1.fill(10, null, -1); 192 print(array1) // [10, 10, 10, 8] 193 194 array1.fill(11, -3, -1); 195 print(array1) // [10, 11, 11, 11] 196 197 array1.fill(11, -3, -0.1); 198 print(array1) // [10, 11, 11, 11] 199 200 array1.fill(12, 3, 1); 201 print(array1) // [10, 11, 11, 11] 202} 203 204// remove 205function pop() { 206 print("Start Test pop") 207 const sharedArray = new SendableArray<number>(5, 12, 8, 130, 44, 10, 20, 30, 100, 50, 80, 90, 150, 200); 208 let sharedArray2 = sharedArray.concat(sharedArray).concat(sharedArray).concat(sharedArray).concat(sharedArray); 209 print(sharedArray2.length); 210 let len = sharedArray2.length; 211 for (let idx = 0; idx < 10; ++idx) { 212 sharedArray2.pop(); 213 print(sharedArray2) 214 } 215 print(sharedArray2.length); 216} 217 218// update 219function randomUpdate() { 220 print("Start Test randomUpdate") 221 const sharedArray = new SendableArray<number>(5, 12, 8, 130, 44); 222 sharedArray[1] = 30 223 print(sharedArray[1]); 224 try { 225 sharedArray[null] = 30 226 } catch (err) { 227 print("add element by index access failed. err: " + err + ", code: " + err.code); 228 } 229 230 try { 231 sharedArray[undefined] = 30 232 } catch (err) { 233 print("add element by index access failed. err: " + err + ", code: " + err.code); 234 } 235 236 try { 237 sharedArray[2871622679] = 30 238 } catch (err) { 239 print("add element by index access failed. err: " + err + ", code: " + err.code); 240 } 241} 242 243// get 244function randomGet() { 245 print("Start Test randomGet") 246 const sharedArray = new SendableArray<number>(5, 12, 8, 130, 44); 247 sharedArray.at(0) 248 print(sharedArray); 249} 250 251// add 252function randomAdd() { 253 print("Start Test randomAdd") 254 const sharedArray = new SendableArray<number>(5, 12, 8); 255 try { 256 sharedArray[4000] = 7; 257 } catch (err) { 258 print("add element by index access failed. err: " + err + ", code: " + err.code); 259 } 260} 261 262function create(): void { 263 print("Start Test create") 264 let arkTSTest: SendableArray<number> = new SendableArray<number>(5); 265 let arkTSTest1: SendableArray<number> = new SendableArray<number>(1, 3, 5); 266} 267 268function from(): void { 269 print("Start Test from") 270 print(SendableArray.from<string>(['A', 'B', 'C'])); 271 try { 272 print(SendableArray.from<string>(['E', , 'M', 'P', 'T', 'Y'])); 273 } catch (err) { 274 print("Create from empty element list failed. err: " + err + ", code: " + err.code); 275 } 276 const source = new SendableArray<undefined>(undefined, undefined, 1); 277 try { 278 print('Create from sendable undefined element list success. arr: ' + SendableArray.from<string>(source)); 279 } catch (err) { 280 print("Create from sendable undefined element list failed. err: " + err + ", code: " + err.code); 281 } 282 // trigger string cache 283 SendableArray.from("hello"); 284 print(SendableArray.from("hello")); 285 try { 286 print(SendableArray.from.call({}, [1,2,3])) 287 } catch (err) { 288 print("Create from sendable list failed without constructor functions. err: " + err + ", code: " + err.code); 289 } 290 291 let sArr = SendableArray.from<string>(['A', 'B', 'C'], (str: string) => 'S' + str); 292 print(sArr); 293 let sArr1 = SendableArray.from<string>(sArr, (str: string) => 'S' + str); 294 print(sArr1); 295 296 try { 297 let sArr2 = SendableArray.from<string>(sArr, (str: string) =>{ 298 return new SuperUnSharedClass(1); 299 }); 300 print(sArr2); 301 } catch (err) { 302 print("Create from sendable array. err: " + err + ", code: " + err.code); 303 } 304 305 try { 306 let sArr2 = SendableArray.from<SuperClass>(sArr, (str: string) =>{ 307 return new SuperClass(1); 308 }); 309 sArr2.forEach((element: SubClass) => print(element.num)); // 5, 8, 44 310 } catch (err) { 311 print("Create from sendable array. err: " + err + ", code: " + err.code); 312 } 313 314 let normalArr = new Array<number>(3,2,1,5); 315 let sArr3 = SendableArray.from<number>(normalArr, (num: number) =>{ 316 normalArr.pop(); 317 return num += 1; 318 }); 319 print(sArr3) 320 321 let normalArr1 = new Array<number>(3,2,1,5); 322 let sArr4 = SendableArray.from<number>(normalArr1, (num: number) =>{ 323 if (num < 3) { 324 normalArr1.push(num + 1); 325 } 326 327 return num += 1; 328 }); 329 print(sArr4) 330 331 let normalArr2 = new Array<string>("abcd","bcde","cdef","cfgh"); 332 let sArr5 = SendableArray.from<number>(normalArr2, (str: string) =>{ 333 if (str.length <= 4) { 334 normalArr2.push(str + "cde"); 335 } 336 337 return str + "cde"; 338 }); 339 print(sArr5) 340 341 let obj = { 342 0:1, 343 1:3, 344 2:5, 345 length:3 346 }; 347 let sArr6 = SendableArray.from<number>(obj, (value: number) =>{ 348 if (value < 4) { 349 obj[obj.length] = value + 10; 350 obj.length += 1; 351 } 352 353 return value; 354 }); 355 print(sArr6) 356} 357 358function fromTemplate(): void { 359 print('Start Test fromTemplate'); 360 let artTSTest1: SendableArray<string> = SendableArray.from<Number, string>([1, 2, 3], (x: number) => '' + x); 361 print('artTSTest1: ' + artTSTest1); 362 let arkTSTest2: SendableArray<string> = SendableArray.from<Number, string>([1, 2, 3], (item: number) => '' + item); // ["1", "Key", "3"] 363 print('arkTSTest2: ' + arkTSTest2); 364} 365 366function length(): void { 367 print("Start Test length") 368 let array: SendableArray<number> = new SendableArray<number>(1, 3, 5); 369 print("Array length: " + array.length); 370 array.length = 50; 371 print("Array length after changed: " + array.length); 372} 373 374function push(): void { 375 print("Start Test push") 376 let array: SendableArray<number> = new SendableArray<number>(1, 3, 5); 377 array.push(2, 4, 6); 378 print("Elements pushed: " + array); 379 let array1 = new SendableArray<number>(); 380 array1.push(1); 381 array1.push(2); 382 array1.push(3); 383 array1.push(7, 8, 9); 384 print("Elements pushed: " + array1); 385} 386 387function concat(): void { 388 print("Start Test concat") 389 let array: SendableArray<number> = new SendableArray<number>(1, 3, 5); 390 let arkTSToAppend: SendableArray<number> = new SendableArray<number>(2, 4, 6); 391 let arkTSToAppend1: SendableArray<number> = new SendableArray<number>(100, 101, 102); 392 393 print(array.concat(arkTSToAppend)); // [1, 3, 5, 2, 4, 6] 394 print(array.concat(arkTSToAppend, arkTSToAppend1)); 395 print(array.concat(200)); 396 print(array.concat(201, 202)); 397 let arr: SendableArray<number> = array.concat(null); 398 print(arr); 399 print(arr[3]); 400 print(arr.length); 401 let arr1: SendableArray<number> = array.concat(undefined); 402 print(arr1); 403 print(arr1[3]); 404 print(arr1.length); 405 406 let nsArr = [1, , 4]; 407 let arr2: SendableArray<number> = array.concat(1, nsArr[1], 5); 408 print(arr2); 409 print(arr2.length); 410 411 let arr3: SendableArray<number> = array.concat(1, arr1, 5, nsArr[1]); 412 print(arr3); 413 print(arr3.length); 414} 415 416function join(): void { 417 print("Start Test join") 418 const elements = new SendableArray<string>('Fire', 'Air', 'Water'); 419 print(elements.join()); 420 print(elements.join('')); 421 print(elements.join('-')); 422 print(elements.join(null)); 423 print(elements.join(undefined)); 424 425 const elements1 = new SendableArray<string>("123", "3445", "789"); 426 const elements2 = new SendableArray<SendableArray>(); 427 elements2.push(elements1); 428 elements2.push(elements2); 429 430 print(elements2.join()); 431} 432 433function shift() { 434 print("Start Test shift") 435 const array1 = new SendableArray<number>(2, 4, 6); 436 print(array1.shift()); 437 print(array1.length); 438 439 const emptyArray = new SendableArray<number>(); 440 print(emptyArray.shift()); 441 442 const array2 = new SendableArray<number>(2, 4, 6, 100, 50, 60, 70); 443 let array3 = array2.concat(array2).concat(array2).concat(array2).concat(array2).concat(array2).concat(array2); 444 print(array3); 445 print(array3.length); 446 let len = array3.length; 447 for (let idx = 0; idx < 10; ++idx) { 448 array3.shift(); 449 print(array3); 450 } 451 print(array3.length) 452} 453 454function unshift() { 455 print("Start Test unshift") 456 const array = SendableArray.from<number>([1, 2, 3]); 457 print(array); 458 print(array.length); 459 print(array.unshift(4, 5)); 460 print(array); 461 print(array.length); 462 463 let arr2 = array.concat(array).concat(array).concat(array).concat(array).concat(array).concat(array); 464 print(arr2); 465 print(arr2.length); 466 let arr3 = arr2.concat(arr2); 467 print(arr3); 468 print(arr3.length); 469 print(arr2.unshift(arr3)); 470 print(arr2); 471 print(arr2.length); 472 473} 474 475function slice() { 476 print("Start Test slice") 477 const animals = new SendableArray<string>('ant', 'bison', 'camel', 'duck', 'elephant'); 478 print(animals.slice()); 479 print(animals.slice(2)); 480 print(animals.slice(2, 4)); 481 try { 482 let a1 = animals.slice(1.5, 4); 483 print("slice(1.5, 4) element success"); 484 print(a1); 485 } catch (err) { 486 print("slice element failed. err: " + err + ", code: " + err.code); 487 } 488 489 try { 490 let a2 = animals.slice(8, 4); 491 print("slice(8, 4) element success"); 492 } catch (err) { 493 print("slice element failed. err: " + err + ", code: " + err.code); 494 } 495 496 try { 497 let a3 = animals.slice(8, 100); 498 print("slice(8, 100) element success"); 499 } catch (err) { 500 print("slice element failed. err: " + err + ", code: " + err.code); 501 } 502 503 try { 504 print(animals.slice(null)); 505 } catch (err) { 506 print("slice element failed. err: " + err + ", code: " + err.code); 507 } 508 509 try { 510 print(animals.slice(undefined)); 511 } catch (err) { 512 print("slice element failed. err: " + err + ", code: " + err.code); 513 } 514} 515 516function sort() { 517 print("Start Test sort") 518 const months = new SendableArray<string>('March', 'Jan', 'Feb', 'Dec'); 519 print(months.sort()); 520 521 const array1 = [1, 30, 4, 21, 10000]; 522 print(array1.sort()); 523 524 array1.sort((a: number, b: number) => a - b); 525} 526 527function indexOf() { 528 print("Start Test indexOf") 529 const beasts = new SendableArray<string>('ant', 'bison', 'camel', 'duck', 'bison'); 530 print(beasts.indexOf('bison')); // Expected: 1 531 print(beasts.indexOf('bison', 2)) // Expected: 4 532 print(beasts.indexOf('giraffe')) // Expected: -1 533} 534 535function forEach() { 536 print('Start Test forEach'); 537 const array = new SendableArray<string>('a', 'b', 'c'); 538 array.forEach((element: string) => print(element)); // a <br/> b <br/> c 539 540 array.forEach((element: string, index: number, array: SendableArray<string>) => 541 print(`a[${index}] = ${element}, ${array[index]}`), 542 ); 543} 544 545function map() { 546 print("Start Test map") 547 const array = new SendableArray<number>(1, 4, 9, 16); 548 print(array.map<string>((x: number) => x + x)); 549} 550 551function filter() { 552 print("Start Test filter") 553 const words = new SendableArray<string>('spray', 'elite', 'exuberant', 'destruction', 'present'); 554 print(words.filter((word: string) => word.length > 6)) 555 const array2 = new SendableArray<SuperClass>( 556 new SubClass(5), 557 new SuperClass(12), 558 new SubClass(8), 559 new SuperClass(130), 560 new SubClass(44), 561 ); 562 const result = array2.filter<SubClass>((value: SuperClass, index: number, obj: Array<SuperClass>) => value instanceof SubClass); 563 result.forEach((element: SubClass) => print(element.num)); // 5, 8, 44 564 565 const words1 = new SendableArray<string>('spray', 'elite', 'exuberant', 'destruction', 'present'); 566 let words2 = words1.concat(words).concat(words).concat(words).concat(words).concat(words).concat(words).concat(words); 567 print(words2) 568 print(words2.filter((word: string) => word.length > 10)) 569} 570 571function reduce() { 572 print("Start Test reduce") 573 const array = new SendableArray<number>(1, 2, 3, 4); 574 print(array.reduce((acc: number, currValue: number) => acc + currValue)); // 10 575 576 print(array.reduce((acc: number, currValue: number) => acc + currValue, 10)); // 20 577 578 print(array.reduce<string>((acc: number, currValue: number) => "" + acc + " " + currValue, "10")); // 10, 1, 2, 3, 4 579} 580 581function f0() { 582 const o1 = { 583 }; 584 585 return o1; 586} 587 588const v2 = f0(); 589class C3 { 590 constructor(a5,a6) { 591 const v9 = new SendableArray(); 592 v9.splice(0,0, v2); 593 } 594} 595 596function splice() { 597 print("Start Test splice") 598 const array = new SendableArray<string>('Jan', 'March', 'April', 'June'); 599 print(array.splice()); 600 print(array); 601 array.splice(1, 0, 'Feb', 'Oct'); 602 print(array); // "Jan", "Feb", "Oct", "March", "April", "June" 603 const removeArray = array.splice(4, 2, 'May'); 604 print(array); // "Jan", "Feb", "Oct", "March", "May" 605 print(removeArray); // "April", "June" 606 const removeArray1 = array.splice(2, 3); 607 print(array); // "Jan", "Feb" 608 print(removeArray1); // "Oct", "March", "May" 609 610 const array2 = new SendableArray<SubClass>( 611 new SubClass(5), 612 new SubClass(32), 613 new SubClass(8), 614 new SubClass(130), 615 new SubClass(44), 616 ); 617 618 try { 619 array2.splice(0, 0, new SuperUnSharedClass(48)); 620 print("Add one element by splice api."); 621 } catch (err) { 622 print("Add one element by splice api failed. err: " + err + ", code: " + err.code); 623 } 624 625 try { 626 new C3(); 627 print("Add one element by splice api."); 628 } catch (err) { 629 print("Add one element by splice api failed. err: " + err + ", code: " + err.code); 630 } 631} 632 633function staticCreate() { 634 print("Start Test staticCreate") 635 const array = SendableArray.create<number>(10, 5); 636 print(array); 637 try { 638 const array = SendableArray.create<number>(5); 639 print("Create with without initialValue success."); 640 } catch (err) { 641 print("Create with without initialValue failed. err: " + err + ", code: " + err.code); 642 } 643 try { 644 const array = SendableArray.create<number>(-1, 5); 645 print("Create with negative length success."); 646 } catch (err) { 647 print("Create with negative length failed. err: " + err + ", code: " + err.code); 648 } 649 try { 650 const array = SendableArray.create<number>(13107200, 1); // 13107200: 12.5MB 651 print("Create huge sendableArrayWith initialValue success."); 652 } catch (err) { 653 print("Create huge sendableArrayWith initialValue failed. err: " + err + ", code: " + err.code); 654 } 655 try { 656 const array = SendableArray.create<number>(0x100000000, 5); 657 print("Create with exceed max length success."); 658 } catch (err) { 659 print("Create with exceed max length failed. err: " + err + ", code: " + err.code); 660 } 661} 662 663function readonlyLength() { 664 print("Start Test readonlyLength") 665 const array = SendableArray.create<number>(10, 5); 666 print(array.length); 667 array.length = 0; 668 print(array.length); 669} 670 671function shrinkTo() { 672 print("Start Test shrinkTo") 673 const array = new SendableArray<number>(5, 5, 5, 5, 5, 5, 5, 5, 5, 5); 674 print(array.length); 675 array.shrinkTo(array.length); 676 print("Shrink to array.length: " + array); 677 array.shrinkTo(array.length + 1); 678 print("Shrink to array.length + 1: " + array); 679 try { 680 array.shrinkTo(-1); 681 print("Shrink to -1 success"); 682 } catch (err) { 683 print("Shrink to -1 fail. err: " + err + ", code: " + err.code); 684 } 685 try { 686 array.shrinkTo(0x100000000); 687 print("Shrink to invalid 0x100000000 success"); 688 } catch (err) { 689 print("Shrink to invalid 0x100000000 fail. err: " + err + ", code: " + err.code); 690 } 691 array.shrinkTo(1); 692 print(array.length); 693 print(array); 694 695} 696 697function extendTo() { 698 print("Start Test growTo") 699 const array = SendableArray.create<number>(5, 5); 700 print(array.length); 701 array.extendTo(array.length, 0); 702 print("ExtendTo to array.length: " + array); 703 array.extendTo(array.length - 1, 0); 704 print("ExtendTo to array.length - 1: " + array); 705 array.extendTo(0, 0); 706 print("ExtendTo to 0: " + array); 707 try { 708 array.extendTo(-1, 0); 709 print("ExtendTo to -1 success."); 710 } catch (err) { 711 print("ExtendTo to -1 fail. err: " + err + ", code: " + err.code); 712 } 713 try { 714 array.extendTo(0x100000000, 0); 715 print("ExtendTo to invalid 0x100000000 success."); 716 } catch (err) { 717 print("ExtendTo to invalid 0x100000000 fail. err: " + err + ", code: " + err.code); 718 } 719 try { 720 array.extendTo(8); 721 print("ExtendTo to 8 without initValue success."); 722 } catch (err) { 723 print("ExtendTo to 8 without initValue fail. err: " + err + ", code: " + err.code); 724 } 725 array.extendTo(8, 11); 726 print(array.length); 727 print(array); 728} 729 730function indexAccess() { 731 print("Start Test indexAccess") 732 const array = new SendableArray<number>(1, 3, 5, 7); 733 print("element1: " + array[1]); 734 array[1] = 10 735 print("element1 assigned to 10: " + array[1]); 736 try { 737 array[10] 738 print("Index access read out of range success."); 739 } catch (err) { 740 print("Index access read out of range failed. err: " + err + ", code: " + err.code); 741 } 742 try { 743 array[100] = 10 744 print("Index access write out of range success."); 745 } catch (err) { 746 print("Index access write out of range failed. err: " + err + ", code: " + err.code); 747 } 748 try { 749 array.forEach((key: number, _: number, array: SendableArray) => { 750 array[key + array.length]; 751 }); 752 } catch (err) { 753 print("read element while iterate array fail. err: " + err + ", errCode: " + err.code); 754 } 755 try { 756 array.forEach((key: number, _: number, array: SendableArray) => { 757 array[key + array.length] = 100; 758 }); 759 } catch (err) { 760 print("write element while iterate array fail. err: " + err + ", errCode: " + err.code); 761 } 762} 763 764function indexStringAccess() { 765 print("Start Test indexStringAccess") 766 const array = new SendableArray<number>(1, 3, 5, 7); 767 print("String index element1: " + array["" + 1]); 768 array["" + 1] = 10 769 print("String index element1 assigned to 10: " + array["" + 1]); 770 try { 771 array["" + 10] 772 print("String Index access read out of range success."); 773 } catch (err) { 774 print("String Index access read out of range failed. err: " + err + ", code: " + err.code); 775 } 776 try { 777 array["" + 100] = 10 778 print("String Index access write out of range success."); 779 } catch (err) { 780 print("String Index access write out of range failed. err: " + err + ", code: " + err.code); 781 } 782 try { 783 array.forEach((key: number, _: number, array: SendableArray) => { 784 array['' + key + array.length]; 785 }); 786 } catch (err) { 787 print("String index read element while iterate array fail. err: " + err + ", errCode: " + err.code); 788 } 789 try { 790 array.forEach((key: number, _: number, array: SendableArray) => { 791 array['' + key + array.length] = 100; 792 }); 793 } catch (err) { 794 print("String index write element while iterate array fail. err: " + err + ", errCode: " + err.code); 795 } 796} 797 798function testForIC(index: number) { 799 const array = new SendableArray<number>(1, 3, 5, 7); 800 try { 801 const element = array[index < 80 ? 1 : 10]; 802 if (index == 1) { 803 print("[IC] Index access read in range success. array: " + element); 804 } 805 } catch (err) { 806 if (index == 99) { 807 print("[IC] Index access read out of range failed. err: " + err + ", code: " + err.code); 808 } 809 } 810 try { 811 array[index < 80 ? 1 : 100] = 10 812 if (index == 1) { 813 print("[IC] Index access write in range success."); 814 } 815 } catch (err) { 816 if (index == 99) { 817 print("[IC] Index access write out of range failed. err: " + err + ", code: " + err.code); 818 } 819 } 820 try { 821 array.length = index < 80 ? 1 : 100; 822 if (index == 1) { 823 print("[IC] assign readonly length no error."); 824 } 825 } catch (err) { 826 if (index == 99) { 827 print("[IC] assign readonly length fail. err: " + err + ", code: " + err.code); 828 } 829 } 830} 831 832function testStringForIC(index: number) { 833 const array = new SendableArray<number>(1, 3, 5, 7); 834 try { 835 const element = array["" + index < 80 ? 1 : 10]; 836 if (index == 1) { 837 print("[IC] String Index access read in range success. array: " + element); 838 } 839 } catch (err) { 840 if (index == 99) { 841 print("[IC] String Index access read out of range failed. err: " + err + ", code: " + err.code); 842 } 843 } 844 try { 845 array["" + (index < 80 ? 1 : 100)] = 10 846 if (index == 1) { 847 print("[IC] String Index access write in range success."); 848 } 849 } catch (err) { 850 if (index == 99) { 851 print("[IC] String Index access write out of range failed. err: " + err + ", code: " + err.code); 852 } 853 } 854} 855 856function frozenTest(array: SendableArray) { 857 try { 858 array.notExistProp = 1; 859 } catch (err) { 860 print('Add prop to array failed. err: ' + err); 861 } 862 try { 863 Object.defineProperty(array, 'defineNotExistProp', { value: 321, writable: false }); 864 } catch (err) { 865 print('defineNotExistProp to array failed. err: ' + err); 866 } 867 try { 868 array.at = 1; 869 } catch (err) { 870 print('Update function [at] failed. err: ' + err); 871 } 872 try { 873 Object.defineProperty(array, 'at', { value: 321, writable: false }); 874 } catch (err) { 875 print('Update function [at] by defineProperty failed. err: ' + err); 876 } 877 array.push(111); 878} 879 880function arrayFrozenTest() { 881 print("Start Test arrayFrozenTest") 882 let arr1 = new SendableArray<string>('ARK'); 883 print("arrayFrozenTest [new] single string. arr: " + arr1); 884 frozenTest(arr1); 885 arr1 = new SendableArray<string>('A', 'R', 'K'); 886 print("arrayFrozenTest [new]. arr: " + arr1); 887 frozenTest(arr1); 888 arr1 = SendableArray.from<string>(['A', 'R', 'K']); 889 print("arrayFrozenTest static [from]. arr: " + arr1); 890 frozenTest(arr1); 891 arr1 = SendableArray.create<string>(3, 'A'); 892 print("arrayFrozenTest static [create]. arr: " + arr1); 893 frozenTest(arr1); 894} 895 896function sharedArrayFrozenTest() { 897 print("Start Test sharedArrayFrozenTest") 898 let arr1 = new SubSharedClass(); 899 arr1.push("A"); 900 arr1.push("R"); 901 arr1.push("K"); 902 print("sharedArrayFrozenTest [new]. arr: " + arr1); 903 frozenTest(arr1); 904} 905 906function increaseArray() { 907 print("Start Test extendSharedTest") 908 let sub = new SubSharedClass(); 909 for (let idx: number = 0; idx < 1200; idx++) { 910 sub.push(idx + 10); 911 } 912 print("Push: " + sub); 913} 914 915function arrayFromSet(){ 916 print('Start Test arrayFromSet'); 917 const set = new Set(['foo', 'bar', 'baz', 'foo']); 918 const sharedSet = new SendableSet(['foo', 'bar', 'baz', 'foo']); 919 print('Create from normal set: ' + SendableArray.from(set)); 920 print('Create from shared set: ' + SendableArray.from(set)); 921} 922 923function arrayFromNormalMap() { 924 print("Start Test arrayFromNormalMap") 925 const map = new Map([ 926 [1, 2], 927 [2, 4], 928 [4, 8], 929 ]); 930 Array.from(map); 931 // [[1, 2], [2, 4], [4, 8]] 932 933 const mapper = new Map([ 934 ["1", "a"], 935 ["2", "b"], 936 ]); 937 Array.from(mapper.values()); 938 // ['a', 'b']; 939 940 Array.from(mapper.keys()); 941 // ['1', '2']; 942} 943 944function arrayFromSendableMap() { 945 print('Start test arrayFromSendableMap'); 946 const map = new SendableMap([ 947 [1, 2], 948 [2, 4], 949 [4, 8], 950 ]); 951 try { 952 print('create from sharedMap: ' + SendableArray.from(map)); 953 } catch (err) { 954 print('create from sharedMap with non-sendable array failed. err: ' + err + ', code: ' + err.code); 955 } 956 // [[1, 2], [2, 4], [4, 8]] 957 958 const mapper = new SendableMap([SendableArray.from(['1', 'a']), SendableArray.from(['2', 'b'])]); 959 print('create from sharedMapper.values(): ' + SendableArray.from(mapper.values())); 960 // ['a', 'b']; 961 962 print('create from sharedMapper.values(): ' + SendableArray.from(mapper.keys())); 963 // ['1', '2']; 964} 965 966function arrayFromNotArray() { 967 print("Start test arrayFromNotArray") 968 function NotArray(len: number) { 969 print("NotArray called with length", len); 970 } 971 972 try { 973 print('Create array from notArray: ' + SendableArray.from.call(NotArray, new Set(['foo', 'bar', 'baz']))); 974 } catch (err) { 975 print("Create array from notArray failed. err: " + err + ", code: " + err.code); 976 } 977} 978 979function derivedSlice() { 980 print("Start Test derivedSlice") 981 let animals = new SubSharedClass(); 982 animals.push('ant'); 983 animals.push('bison'); 984 animals.push('camel'); 985 animals.push('duck'); 986 animals.push('elephant'); 987 print("instanceOf slice result: " + (animals.slice() instanceof SubSharedClass)); 988} 989 990function derivedSort() { 991 print("Start Test derivedSort") 992 let months = new SubSharedClass(); 993 months.push('March') 994 months.push('Jan') 995 months.push('Feb') 996 months.push('Dec') 997 998 const sortedMonth = months.sort(); 999 print("instanceOf derived sort result: " + (sortedMonth instanceof SubSharedClass)); 1000} 1001 1002function derivedForEach() { 1003 print('Start Test derivedForEach'); 1004 let array = new SubSharedClass(); 1005 array.push('March'); 1006 array.push('Jan'); 1007 array.push('Feb'); 1008 array.push('Dec'); 1009 array.forEach((element: string, index: number, array: SendableArray<string>) => 1010 print(`a[${index}] = ${element}, ${array instanceof SubSharedClass}`), 1011 ); 1012} 1013 1014function derivedMap() { 1015 print("Start derivedMap") 1016 let array = new SubSharedClass(); 1017 array.push(1); 1018 array.push(4); 1019 array.push(9); 1020 array.push(16); 1021 print("instanceOf derived map result: " + (array.map<string>((x: number) => x + x + "") instanceof SubSharedClass)); 1022} 1023 1024function derivedFill() { 1025 print("Start Test derivedFill") 1026 let array = new SubSharedClass(); 1027 array.push(1); 1028 array.push(2); 1029 array.push(3); 1030 array.push(4); 1031 const filledArray = array.fill(0, 2, 4); 1032 print(array); // [1, 2, 0, 0] 1033 print("instanceOf derived fill result: " + (filledArray instanceof SubSharedClass)); 1034} 1035 1036function readOutOfRange() { 1037 print("Start Test array read out of range") 1038 const array = new SendableArray<number>(1, 3, 5, 7); 1039 print("array[0]: " + array[0]); 1040 try { 1041 let value = array[9]; 1042 print("read out of range success " + value); 1043 } catch (err) { 1044 print("read out of range failed. err: " + err + ", code: " + err.code); 1045 } 1046 1047 try { 1048 let value = array['0']; 1049 print("read out of range success " + value); 1050 } catch (err) { 1051 print("read out of range failed. err: " + err + ", code: " + err.code); 1052 } 1053 1054 try { 1055 let value = array[0.0]; 1056 print("read out of range success " + value); 1057 } catch (err) { 1058 print("read out of range failed. err: " + err + ", code: " + err.code); 1059 } 1060 1061 try { 1062 let value = array[1.5] 1063 print("read out of range success " + value); 1064 } catch (err) { 1065 print("read out of range failed. err: " + err + ", code: " + err.code); 1066 } 1067 1068 try { 1069 let value = array[undefined] 1070 print("read out of range success " + value); 1071 } catch (err) { 1072 print("read out of range failed. err: " + err + ", code: " + err.code); 1073 } 1074 1075 try { 1076 let value = array[null] 1077 print("read out of range success " + value); 1078 } catch (err) { 1079 print("read out of range failed. err: " + err + ", code: " + err.code); 1080 } 1081 1082 try { 1083 let value = array[Symbol.toStringTag] 1084 print("read out of range success " + value); 1085 } catch (err) { 1086 print("read out of range failed. err: " + err + ", code: " + err.code); 1087 } 1088 1089 try { 1090 let value = array[false] 1091 print("read out of range success " + value); 1092 } catch (err) { 1093 print("read out of range failed. err: " + err + ", code: " + err.code); 1094 } 1095 1096 try { 1097 let value = array[true] 1098 print("read out of range success " + value); 1099 } catch (err) { 1100 print("read out of range failed. err: " + err + ", code: " + err.code); 1101 } 1102} 1103 1104function forOf() { 1105 print("Start Test array for of") 1106 const array = new SendableArray<number>(1, 3, 5, 7); 1107 for(const num of array){ 1108 print(num); 1109 } 1110} 1111 1112function sharedArrayConstructorTest(){ 1113 let from_arr = [1,2,3]; 1114 let s_arr = new SendableArray<number>(...from_arr); // output [1,2,3] 1115 print(("SendableArray ...from_arr: " + s_arr)); 1116 let s_arr1 = new SendableArray<number>(0, ...from_arr); // output [1,2,3] 1117 print(("SendableArray ...from_arr1: " + s_arr1)); 1118 try { 1119 print("Create from SendableArray with non-sendable array error: " + new SendableArray(from_arr)); 1120 } catch (err) { 1121 print("Create from SendableArray with non-sendable array error failed. err: " + err + ", code: " + err.code); 1122 } 1123} 1124 1125function fromArrayConstructorTest(): void { 1126 print("Start Test fromArrayConstructorTest") 1127 const array1 = new SendableArray<string>('a', 'b', 'c'); 1128 const iterator = array1.values(); 1129 print(SendableArray.from<string>(iterator)); 1130} 1131 1132function DefinePropertyTest() { 1133 print("Start Test DefinePropertyTest") 1134 let array = new SendableArray<string>('ARK'); 1135 try { 1136 Object.defineProperty(array, '0', {writable: true, configurable: true, enumerable: true, value: "321"}); 1137 print('defineProperty to array success'); 1138 } catch (err) { 1139 print('defineProperty to array failed. err: ' + err); 1140 } 1141 1142 try { 1143 Object.defineProperty(array, '1200', {writable: true, configurable: true, enumerable: true, value: "321"}); 1144 print('defineProperty to array success'); 1145 } catch (err) { 1146 print('defineProperty to array failed. err: ' + err); 1147 } 1148 1149 try { 1150 Object.defineProperty(array, 0, {writable: true, configurable: true, enumerable: true, value: "321"}); 1151 print('defineProperty to array success'); 1152 } catch (err) { 1153 print('defineProperty to array failed. err: ' + err); 1154 } 1155 1156 try { 1157 Object.defineProperty(array, 1200, {writable: true, configurable: true, enumerable: true, value: "321"}); 1158 print('defineProperty to array success'); 1159 } catch (err) { 1160 print('defineProperty to array failed. err: ' + err); 1161 } 1162 1163 try { 1164 Object.defineProperty(array, 2871622679, {writable: true, configurable: true, enumerable: true, value: "321"}); 1165 print('defineProperty to array success'); 1166 } catch (err) { 1167 print('defineProperty to array failed. err: ' + err); 1168 } 1169 try { 1170 Object.defineProperty(array, 0.0, {writable: true, configurable: true, enumerable: true, value: "321"}); 1171 print('defineProperty to array success ' + array[0.0]); 1172 } catch (err) { 1173 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1174 } 1175 1176 try { 1177 Object.defineProperty(array, 1.5, {writable: true, configurable: true, enumerable: true, value: "321"}); 1178 print('defineProperty to array success ' + array[1.5]); 1179 } catch (err) { 1180 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1181 } 1182 1183 try { 1184 Object.defineProperty(array, undefined, {writable: true, configurable: true, enumerable: true, value: "321"}); 1185 print("defineProperty to array success " + array[undefined]); 1186 } catch (err) { 1187 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1188 } 1189 1190 try { 1191 Object.defineProperty(array, null, {writable: true, configurable: true, enumerable: true, value: "321"}); 1192 print("defineProperty to array success " + array[null]); 1193 } catch (err) { 1194 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1195 } 1196 1197 try { 1198 Object.defineProperty(array, Symbol.toStringTag, {writable: true, configurable: true, enumerable: true, value: "321"}); 1199 print("defineProperty to array success " + array[Symbol.toStringTag]); 1200 } catch (err) { 1201 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1202 } 1203 1204 try { 1205 Object.defineProperty(array, true, {writable: true, configurable: true, enumerable: true, value: "321"}); 1206 print("defineProperty to array success " + array[null]); 1207 } catch (err) { 1208 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1209 } 1210 1211 try { 1212 Object.defineProperty(array, false, {writable: true, configurable: true, enumerable: true, value: "321"}); 1213 print("defineProperty to array success " + array[Symbol.toStringTag]); 1214 } catch (err) { 1215 print("defineProperty to array failed. err: " + err + ", code: " + err.code); 1216 } 1217} 1218 1219function isEven(num) { 1220 return num % 2 === 0; 1221} 1222 1223function SomeTest(): void { 1224 print("Start Test SomeTest") 1225 const numbers = new SendableArray<number>(1, 2, 3, 4, 5); 1226 1227 const hasEvenNumber = numbers.some(isEven); // 1: Whether there are even numbers in the array 1228 print(hasEvenNumber); // should be true 1229 1230 const hasNegativeNumber = numbers.some(num => num < 0); // 2: Whether there are negative numbers in the array 1231 print(hasNegativeNumber); // should be false 1232 1233 let nsArr = [1, , 3]; 1234 const numbers1 = new SendableArray<number>(nsArr[1], 2, 3, 4, 5); 1235 print(numbers1.some(num => num < 0)); // should be false 1236 print(numbers1.some(num => num < 0 || num === undefined)); // should be true 1237 print(numbers1.some(num => num)); // should be true 1238 1239 const numbers2 = new SendableArray<number>(null, undefined, 3, 4, 5); 1240 print(numbers2.some(num => num < 0)); // should be false 1241 print(numbers2.some(num => num < 0 || num === undefined)); // should be true 1242 print(numbers2.some(num => num)); // should be true 1243} 1244 1245function EveryTest(): void { 1246 print("Start Test EveryTest") 1247 const numbers = new SendableArray<number>(1, 2, 3, 4, 5); 1248 1249 const allPositive = numbers.every((num) => num > 0); // Check that all elements in the array are greater than 0 1250 print(allPositive); // should be true 1251 1252 const allEven = numbers.every((num) => num % 2 === 0); // Check if all the elements in the array are even 1253 print(allEven); // should be false 1254 1255 let nsArr = [1, , 3, 5]; 1256 const numbers1 = new SendableArray<number>(nsArr[0], nsArr[1], undefined, 4, 5); 1257 const allPositive1 = numbers1.every((num) => num > 0); 1258 print(allPositive1); // should be false 1259 1260 const allPositive2 = numbers1.every((num) => num > 0 || num == undefined); 1261 print(allPositive2); // should be true 1262} 1263 1264function isArrayTest() { 1265 // print true 1266 print("Start Test isArrayTest") 1267 print(SendableArray.isArray(new SendableArray())); 1268 print(SendableArray.isArray(new SendableArray('a', 'b', 'c', 'd'))); 1269 print(SendableArray.isArray(new SendableArray(3))); 1270 print(SendableArray.isArray(SendableArray.prototype)); 1271 1272 // print false 1273 print(SendableArray.isArray([])); 1274 print(SendableArray.isArray([1])); 1275 print(SendableArray.isArray()); 1276 print(SendableArray.isArray({})); 1277 print(SendableArray.isArray(null)); 1278 print(SendableArray.isArray(undefined)); 1279 print(SendableArray.isArray(17)); 1280 print(SendableArray.isArray('SendableArray')); 1281 print(SendableArray.isArray(true)); 1282 print(SendableArray.isArray(false)); 1283 print(SendableArray.isArray(new SendableUint8Array(32))); 1284} 1285 1286function lastIndexOfTest() { 1287 print("Start Test lastIndexOf") 1288 let arr = SendableArray.from([1, 2, 3, 4, 2, 5]); 1289 print(arr.lastIndexOf(2)); 1290 1291 print(arr.lastIndexOf(1)); 1292 print(arr.lastIndexOf(5)); 1293 print(arr.lastIndexOf(6)); 1294 1295 let emptyArr = SendableArray.from([]); 1296 print(emptyArr.lastIndexOf(1)); 1297 1298 let arrWithNaN = SendableArray.from([1, 2, NaN, 4, NaN]); 1299 print(arrWithNaN.lastIndexOf(NaN)); 1300 1301 let arrWithUndefined = SendableArray.from([1, 2, undefined, 4]); 1302 print(arrWithUndefined.lastIndexOf(undefined)); 1303} 1304 1305function ofTest() { 1306 print("Start Test ofTest") 1307 let arr = SendableArray.of(1, 2, 3, 4, 2, 5); 1308 print(arr); 1309 1310 arr = SendableArray.of(); 1311 print(arr); 1312 1313 arr = SendableArray.of.call({}, 1,2,3,4,5); 1314 print(arr); 1315 1316 try { 1317 arr = SendableArray.of([1,2,3,4,5]); 1318 } catch (err) { 1319 print("Create SendableArray failed. err: " + err + ", code: " + err.code); 1320 } 1321 1322 try { 1323 arr = SendableArray.of.call(Array, 1,2,3,4,5); 1324 } catch (err) { 1325 print("Create SendableArray failed. err: " + err + ", code: " + err.code); 1326 } 1327} 1328 1329function copyWithinTest() { 1330 print("Start Test copyWithin") 1331 let arr = new SendableArray(1, 2, 3, 4, 2, 5); 1332 print(arr); 1333 1334 try { 1335 arr.copyWithin(); 1336 } catch (err) { 1337 print("copyWithin SendableArray failed. err: " + err + ", code: " + err.code); 1338 } 1339 1340 arr.copyWithin(1); 1341 print(arr); 1342 1343 arr.copyWithin(2, 3); 1344 print(arr); 1345 1346 arr.copyWithin(3, -4, -2); 1347 print(arr); 1348 1349 arr.copyWithin(2, -3, -4); 1350 print(arr); 1351 1352 arr.copyWithin(4, 2, 1); 1353 print(arr); 1354} 1355 1356function findLast() { 1357 print("Start Test findLast") 1358 const array1 = new SendableArray<number>(5, 12, 8, 130, 44); 1359 1360 const found = array1.findLast((element: number) => element > 100); 1361 print("" + found); // 130 1362 1363 const found2 = array1.findLast((element: number) => element > 200); 1364 print("" + found2); // undefined 1365 1366 try { 1367 const found3 = array1.findLast(130); 1368 print("" + found3); 1369 } catch (err) { 1370 print("findLast failed. err: " + err + ", code: " + err.code); 1371 } 1372 1373 const array2 = new SendableArray<SuperClass>( 1374 new SubClass(5), 1375 new SubClass(32), 1376 new SubClass(8), 1377 new SubClass(130), 1378 new SubClass(44), 1379 ); 1380 const result: SubClass | undefined = array2.findLast<SubClass>( 1381 (value: SuperClass, index: number, obj: SendableArray<SuperClass>) => value instanceof SubClass, 1382 ); 1383 print(result.strProp); // 44 1384} 1385 1386function findLastIndex() { 1387 print("Start Test findLastIndex") 1388 const array1 = new SendableArray<number>(5, 12, 8, 130, 44); 1389 1390 try { 1391 const found3 = array1.findLastIndex(130); 1392 print("" + found3); 1393 } catch (err) { 1394 print("findLastIndex failed. err: " + err + ", code: " + err.code); 1395 } 1396 1397 const found = array1.findLastIndex((element: number) => element > 100); 1398 print("find index1: " + found); // 3 1399 1400 const found2 = array1.findLastIndex((element: number) => element > 200); 1401 print("find index2: " + found2); // -1 1402 1403 const array2 = new SendableArray<SuperClass>( 1404 new SubClass(5), 1405 new SubClass(32), 1406 new SubClass(8), 1407 new SubClass(130), 1408 new SubClass(44), 1409 ); 1410 const result: SubClass | undefined = array2.findLastIndex<SubClass>( 1411 (value: SuperClass, index: number, obj: SendableArray<SuperClass>) => value instanceof SubClass, 1412 ); 1413 print(result); // index is 4 1414} 1415 1416function reduceRight() { 1417 print("Start Test reduceRight") 1418 const array = new SendableArray<number>(1, 2, 3, 4); 1419 print(array.reduceRight((acc: number, currValue: number) => acc + currValue)); // 10 1420 1421 print(array.reduceRight((acc: number, currValue: number) => acc + currValue, 10)); // 20 1422 1423 print(array.reduceRight<string>((acc: number, currValue: number) => "" + acc + " " + currValue, "10")); // 10, 4, 3, 2, 1 1424 1425 const array1 = new SendableArray<number>(1, 2, 3, 4); 1426 print(array1.reduceRight((acc: number, currValue: number) => acc + currValue, undefined)); 1427 1428 const array2 = new SendableArray<number>(); 1429 print(array2.reduceRight((acc: number, currValue: number) => acc + currValue, 1)); 1430 print(array2.reduceRight((acc: number, currValue: number) => acc + currValue, undefined)); 1431 1432 try { 1433 print(array2.reduceRight((acc: number, currValue: number) => acc + currValue)); 1434 } catch (err) { 1435 print("reduceRight failed. err: " + err + ", code: " + err.code); 1436 } 1437 1438 try { 1439 print(array2.reduceRight(1, 1)); 1440 } catch (err) { 1441 print("reduceRight failed. err: " + err + ", code: " + err.code); 1442 } 1443} 1444 1445function reverse() { 1446 print("Start Test reverse") 1447 const array1 = new SendableArray<number>(1, 2, 3, 4); 1448 print(array1.reverse()); 1449 print(array1); 1450 1451 const array2 = new SendableArray<number>("one", "two", "three"); 1452 print(array2.reverse()); 1453 print(array2); 1454} 1455 1456function toStringTest() { 1457 print("Start Test toString") 1458 const array1 = new SendableArray<number>(1, 2, 3, 4); 1459 print(array1.toString()); 1460 1461 const array2 = new SendableArray<string>("one", "two", "three"); 1462 print(array2.toString()); 1463 1464 const array3 = new SendableArray<number>(null, undefined, 3, 4, 5); 1465 print(array3.toString()); 1466} 1467 1468function toLocaleStringTest() { 1469 print("Start Test toLocaleString") 1470 const array1 = new SendableArray<number>(1, 2, 3, 4); 1471 print(array1.toLocaleString()); 1472 1473 const array2 = new SendableArray<string>("one", "two", "three"); 1474 print(array2.toLocaleString()); 1475 1476 const array3 = new SendableArray<number>(null, undefined, 3, 4, 5); 1477 print(array3.toLocaleString()); 1478 1479 const array4 = new SendableArray(1000, 2000, 3000, 4000, 5000); 1480 print(array4.toLocaleString('de-DE')); 1481 print(array4.toLocaleString('fr-FR')); 1482 1483 const array5 = new SendableArray<number>(123456.789, 2000.00); 1484 print(array5.toLocaleString('en-US', {style: 'currency', currency: 'USD'})); 1485 print(array5.toLocaleString('de-DE', {style: 'currency', currency: 'USD'})); 1486 1487 let array6 = new SendableArray<number>(123456.789, 2000.00); 1488 let array7 = new SendableArray<number>(3, 4, 5); 1489 array6.push(array7); 1490 print(array6.toLocaleString('de-DE', {style: 'currency', currency: 'USD'})); 1491} 1492 1493at() 1494 1495entries() 1496 1497keys() 1498 1499values() 1500 1501find(); 1502 1503includes(); 1504 1505index(); 1506 1507fill(); 1508 1509pop(); 1510 1511randomUpdate(); 1512 1513randomGet(); 1514 1515randomAdd(); 1516create(); 1517from(); 1518fromTemplate(); 1519length(); 1520push(); 1521concat(); 1522join() 1523shift() 1524unshift() 1525slice() 1526sort() 1527indexOf() 1528forEach() 1529map() 1530filter() 1531reduce() 1532splice() 1533staticCreate() 1534readonlyLength() 1535shrinkTo() 1536extendTo() 1537indexAccess() 1538indexStringAccess() 1539print("Start Test testForIC") 1540for (let index: number = 0; index < 100; index++) { 1541 testForIC(index) 1542} 1543 1544print("Start Test testStringForIC") 1545for (let index: number = 0; index < 100; index++) { 1546 testStringForIC(index) 1547} 1548 1549arrayFrozenTest() 1550sharedArrayFrozenTest() 1551arrayFromSet() 1552arrayFromNormalMap() 1553arrayFromSendableMap(); 1554arrayFromNotArray(); 1555 1556derivedSlice(); 1557derivedSort(); 1558derivedForEach(); 1559derivedMap() 1560derivedFill() 1561readOutOfRange() 1562forOf(); 1563sharedArrayConstructorTest() 1564fromArrayConstructorTest() 1565DefinePropertyTest() 1566 1567SomeTest() 1568EveryTest() 1569isArrayTest(); 1570lastIndexOfTest(); 1571ofTest(); 1572copyWithinTest(); 1573 1574findLast(); 1575findLastIndex(); 1576reduceRight(); 1577reverse(); 1578 1579toStringTest(); 1580toLocaleStringTest();