diff --git a/uni_modules/uts-tests/utssdk/TFloat32Array.uts b/uni_modules/uts-tests/utssdk/TFloat32Array.uts index 2e6233fce5db12a5462c782acf38dfc2e45cd5e1..010b10a051aac5170bbb2338c157274950f6d5c7 100644 --- a/uni_modules/uts-tests/utssdk/TFloat32Array.uts +++ b/uni_modules/uts-tests/utssdk/TFloat32Array.uts @@ -271,15 +271,20 @@ export class TFloat32Array { reduce() { // #TEST Float32Array.reduce let total = new Float32Array([0, 1, 2, 3]); - let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue); - console.log(res); // 6 + let res1 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => + accumulator + currentValue + ); + console.log(res1); // 6 + + total = new Float32Array([0, 1, 2, 3]); + let res2 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => + accumulator + currentValue, 8 + ); + console.log(res2); // 14 // #END - expect(res).toEqual(6); - // total = new Float32Array([0, 1, 2, 3]); - // res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue, 8); - // console.log(res); // 14 - // expect(res).toEqual(14); + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reduceRight() { @@ -399,4 +404,4 @@ export class TFloat32Array { } // #endif -} +} \ No newline at end of file diff --git a/uni_modules/uts-tests/utssdk/TInt16Array.uts b/uni_modules/uts-tests/utssdk/TInt16Array.uts index 1a6ed8c7b88cb9df43788af88443ef2d20ab5a67..287fa734f8002af734c494e3eb47591522f602a1 100644 --- a/uni_modules/uts-tests/utssdk/TInt16Array.uts +++ b/uni_modules/uts-tests/utssdk/TInt16Array.uts @@ -73,32 +73,30 @@ export class TInt16Array { testFill() { // #TEST Int16Array.fill - let int16 = new Int16Array([1, 2, 3]).fill(4); - console.log(int16.toString()); // "4,4,4" + let int16_t1 = new Int16Array([1, 2, 3]).fill(4); + console.log(int16_t1.toString()); // "4,4,4" - // expect(int16.toString()).toEqual("4,4,4"); + let int16_t2 = new Int16Array([1, 2, 3]).fill(4, 1); + console.log(int16_t2.toString()); // "1,4,4" - int16 = new Int16Array([1, 2, 3]).fill(4, 1); - console.log(int16.toString()); // "1,4,4" + let int16_t3 = new Int16Array([1, 2, 3]).fill(4, 1, 2); + console.log(int16_t3.toString()); // "1,4,3" - // expect(int16.toString()).toEqual("1,4,4"); + let int16_t4 = new Int16Array([1, 2, 3]).fill(4, 1, 1); + console.log(int16_t4.toString()); // "1,2,3" - int16 = new Int16Array([1, 2, 3]).fill(4, 1, 2); - console.log(int16.toString()); // "1,4,3" - - // expect(int16.toString()).toEqual("1,4,3"); - - int16 = new Int16Array([1, 2, 3]).fill(4, 1, 1); - console.log(int16.toString()); // "1,2,3" - - // expect(int16.toString()).toEqual("1,2,3"); - - int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2); - console.log(int16.toString()); // "4,2,3" + let int16_t5 = new Int16Array([1, 2, 3]).fill(4, -3, -2); + console.log(int16_t5.toString()); // "4,2,3" // #END - expect(int16.toString()).toEqual("4,2,3"); + + expect(int16_t1.toString()).toEqual("4,4,4"); + expect(int16_t2.toString()).toEqual("1,4,4"); + expect(int16_t3.toString()).toEqual("1,4,3"); + expect(int16_t4.toString()).toEqual("1,2,3"); + expect(int16_t5.toString()).toEqual("4,2,3"); } + testFilter() { // #TEST Int16Array.filter let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a : Int16Array) : boolean => value >= 10); diff --git a/uni_modules/uts-tests/utssdk/TInt32Array.uts b/uni_modules/uts-tests/utssdk/TInt32Array.uts index 9a8e17af68c4c7ecea0b362ab432cb199b3ff804..1e1672db2c6b1320a3c6f04224a721a0445c4616 100644 --- a/uni_modules/uts-tests/utssdk/TInt32Array.uts +++ b/uni_modules/uts-tests/utssdk/TInt32Array.uts @@ -93,33 +93,29 @@ export class TInt32Array { // #END expect(result).toEqual(false); } - testFill() { // #TEST Int32Array.fill - let int32 = new Int32Array([1, 2, 3]).fill(4); - console.log(int32.toString()); // "4,4,4" - - // expect(int32.toString()).toEqual("4,4,4"); - - int32 = new Int32Array([1, 2, 3]).fill(4, 1); - console.log(int32.toString()); // "1,4,4" - - // expect(int32.toString()).toEqual("1,4,4"); + let int32_t1 = new Int32Array([1, 2, 3]).fill(4); + console.log(int32_t1.toString()); // "4,4,4" - int32 = new Int32Array([1, 2, 3]).fill(4, 1, 2); - console.log(int32.toString()); // "1,4,3" + let int32_t2 = new Int32Array([1, 2, 3]).fill(4, 1); + console.log(int32_t2.toString()); // "1,4,4" - // expect(int32.toString()).toEqual("1,4,3"); + let int32_t3 = new Int32Array([1, 2, 3]).fill(4, 1, 2); + console.log(int32_t3.toString()); // "1,4,3" - int32 = new Int32Array([1, 2, 3]).fill(4, 1, 1); - console.log(int32.toString()); // "1,2,3" - - // expect(int32.toString()).toEqual("1,2,3"); + let int32_t4 = new Int32Array([1, 2, 3]).fill(4, 1, 1); + console.log(int32_t4.toString()); // "1,2,3" - int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2); - console.log(int32.toString()); // "4,2,3" + let int32_t5 = new Int32Array([1, 2, 3]).fill(4, -3, -2); + console.log(int32_t5.toString()); // "4,2,3" // #END - expect(int32.toString()).toEqual("4,2,3"); + + expect(int32_t1.toString()).toEqual("4,4,4"); + expect(int32_t2.toString()).toEqual("1,4,4"); + expect(int32_t3.toString()).toEqual("1,4,3"); + expect(int32_t4.toString()).toEqual("1,2,3"); + expect(int32_t5.toString()).toEqual("4,2,3"); } testFilter() { @@ -138,22 +134,22 @@ export class TInt32Array { // #END expect(res).toEqual(8); } - findIndex() { // #TEST Int32Array.findIndex - let int32 = new Int32Array([4, 6, 8, 12]); - let res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); - console.log(res); // -1 + let int32_t1 = new Int32Array([4, 6, 8, 12]); + let res1 = int32_t1.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); + console.log(res1); // -1 - // expect(res).toEqual(-1); - - int32 = new Int32Array([4, 6, 7, 120]); - res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); - console.log(res); // 3 + let int32_t2 = new Int32Array([4, 6, 7, 120]); + let res2 = int32_t2.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); + console.log(res2); // 3 // #END - expect(res).toEqual(3); + + expect(res1).toEqual(-1); + expect(res2).toEqual(3); } + foreach() { // #TEST Int32Array.forEach new Int32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int32Array) => { @@ -174,69 +170,66 @@ export class TInt32Array { includes() { // #TEST Int32Array.includes - let int32 = new Int32Array([1, 2, 3]); - let res = int32.includes(2); - console.log(res); // true + let int32_t1 = new Int32Array([1, 2, 3]); + let res1 = int32_t1.includes(2); + console.log(res1); // true - // expect(res).toEqual(true); + let res2 = int32_t1.includes(4); + console.log(res2); // false - res = int32.includes(4); - console.log(res); // false - - // expect(res).toEqual(false); - - res = int32.includes(3, 3); - console.log(res); // false + let res3 = int32_t1.includes(3, 3); + console.log(res3); // false // #END - expect(res).toEqual(false); + + expect(res1).toEqual(true); + expect(res2).toEqual(false); + expect(res3).toEqual(false); } + indexOf() { // #TEST Int32Array.indexOf - let int32 = new Int32Array([2, 5, 9]); - let res = int32.indexOf(2); - console.log(res); // 0 - - // expect(res).toEqual(0); - - res = int32.indexOf(7); - console.log(res); // -1 - - // expect(res).toEqual(-1); + let int32_t1 = new Int32Array([2, 5, 9]); + let res1 = int32_t1.indexOf(2); + console.log(res1); // 0 - res = int32.indexOf(9, 2); - console.log(res); // 2 + let res2 = int32_t1.indexOf(7); + console.log(res2); // -1 - // expect(res).toEqual(2); + let res3 = int32_t1.indexOf(9, 2); + console.log(res3); // 2 - res = int32.indexOf(2, -1); - console.log(res); // -1 + let res4 = int32_t1.indexOf(2, -1); + console.log(res4); // -1 - // expect(res).toEqual(-1); - - res = int32.indexOf(2, -3); - console.log(res); // 0 + let res5 = int32_t1.indexOf(2, -3); + console.log(res5); // 0 // #END - expect(res).toEqual(0); + + expect(res1).toEqual(0); + expect(res2).toEqual(-1); + expect(res3).toEqual(2); + expect(res4).toEqual(-1); + expect(res5).toEqual(0); } + join() { // #TEST Int32Array.join - let int32 = new Int32Array([1, 2, 3]); - let res = int32.join(); - console.log(res); // "1,2,3" - - // expect(res).toEqual("1,2,3"); - - res = int32.join(" / "); - console.log(res); // "1 / 2 / 3" - - // expect(res).toEqual("1 / 2 / 3"); - - res = int32.join(""); - console.log(res); // "123" + let int32_t1 = new Int32Array([1, 2, 3]); + let res1 = int32_t1.join(); + console.log(res1); // "1,2,3" + + let res2 = int32_t1.join(" / "); + console.log(res2); // "1 / 2 / 3" + + let res3 = int32_t1.join(""); + console.log(res3); // "123" // #END - expect(res).toEqual("123"); + + expect(res1).toEqual("1,2,3"); + expect(res2).toEqual("1 / 2 / 3"); + expect(res3).toEqual("123"); } keys() { @@ -262,33 +255,43 @@ export class TInt32Array { reduce() { // #TEST Int32Array.reduce - let total = new Int32Array([0, 1, 2, 3]); - let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue); - console.log(res); // 6 - - // expect(res).toEqual(6); - - total = new Int32Array([0, 1, 2, 3]); - res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8); - console.log(res); // 14 + let total_t1 = new Int32Array([0, 1, 2, 3]); + let res1 = total_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => + accumulator + currentValue + ); + console.log(res1); // 6 + + let total_t2 = new Int32Array([0, 1, 2, 3]); + let res2 = total_t2.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => + accumulator + currentValue, 8 + ); + console.log(res2); // 14 // #END - expect(res).toEqual(14); + + expect(res1).toEqual(6); + expect(res2).toEqual(14); } + reduceRight() { // #TEST Int32Array.reduceRight - let total = new Int32Array([0, 1, 2, 3]); - let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue); - console.log(res); // 6 - - // expect(res).toEqual(6); - - total = new Int32Array([0, 1, 2, 3]); - res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8); - console.log(res); // 14 + let total_t1 = new Int32Array([0, 1, 2, 3]); + let res1 = total_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => + accumulator + currentValue + ); + console.log(res1); // 6 + + let total_t2 = new Int32Array([0, 1, 2, 3]); + let res2 = total_t2.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => + accumulator + currentValue, 8 + ); + console.log(res2); // 14 // #END - expect(res).toEqual(14); + + expect(res1).toEqual(6); + expect(res2).toEqual(14); } + reverse() { // #TEST Int32Array.reverse let int32 = new Int32Array([1, 2, 3]); @@ -300,42 +303,43 @@ export class TInt32Array { slice() { // #TEST Int32Array.slice - let int32 = new Int32Array([1, 2, 3]); - let res = int32.slice(1); - console.log(res.toString()); // "2,3" - - // expect(res.toString()).toEqual("2,3"); - - res = int32.slice(2); - console.log(res.toString()); // "3" - - // expect(res.toString()).toEqual("3"); - - res = int32.slice(-2); - console.log(res.toString()); // "2,3" - - // expect(res.toString()).toEqual("2,3"); - - res = int32.slice(0, 1); - console.log(res.toString()); // "1" + let int32_t1 = new Int32Array([1, 2, 3]); + let res1 = int32_t1.slice(1); + console.log(res1.toString()); // "2,3" + + let res2 = int32_t1.slice(2); + console.log(res2.toString()); // "3" + + let res3 = int32_t1.slice(-2); + console.log(res3.toString()); // "2,3" + + let res4 = int32_t1.slice(0, 1); + console.log(res4.toString()); // "1" // #END - expect(res.toString()).toEqual("1"); + + expect(res1.toString()).toEqual("2,3"); + expect(res2.toString()).toEqual("3"); + expect(res3.toString()).toEqual("2,3"); + expect(res4.toString()).toEqual("1"); } + sort() { // #TEST Int32Array.sort - let numbers = new Int32Array([40, 1, 5]); - numbers.sort(); - console.log(numbers.toString()); // "1,5,40" - - // expect(numbers.toString()).toEqual("1,5,40"); - - numbers.sort((a, b) : number => a - b); - console.log(numbers.toString()); // "1,5,40" + let numbers_t1 = new Int32Array([40, 1, 5]); + numbers_t1.sort(); + console.log(numbers_t1.toString()); // "1,5,40" + + let numbers_t2 = new Int32Array([40, 1, 5]); + numbers_t2.sort((a, b) : number => a - b); + console.log(numbers_t2.toString()); // "1,5,40" // #END - expect(numbers.toString()).toEqual("1,5,40"); + + expect(numbers_t1.toString()).toEqual("1,5,40"); + expect(numbers_t2.toString()).toEqual("1,5,40"); } + subarray() { // #TEST Int32Array.subarray let buffer = new ArrayBuffer(16); @@ -379,12 +383,13 @@ export class TInt32Array { const positives = new Int32Array([10, 20, 30, 40, 50]); console.log(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // true - - // expect(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(true); + console.log(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // false // #END expect(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(false); + expect(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(true); + } // #endif diff --git a/uni_modules/uts-tests/utssdk/TUInt8Array.uts b/uni_modules/uts-tests/utssdk/TUInt8Array.uts index 7e394cb99ed7963bca0aa45f36d4109b10861676..cfc7ab8930e8809b35d6b8a7bc220a8636bbd624 100644 --- a/uni_modules/uts-tests/utssdk/TUInt8Array.uts +++ b/uni_modules/uts-tests/utssdk/TUInt8Array.uts @@ -88,24 +88,30 @@ export class TUint8Array { testFill() { // #TEST Uint8Array.fill - let uint8 = new Uint8Array([1, 2, 3]).fill(4); - console.log(uint8.toString()); // "4,4,4" + let uint8_t1 = new Uint8Array([1, 2, 3]).fill(4); + console.log(uint8_t1.toString()); // "4,4,4" - uint8 = new Uint8Array([1, 2, 3]).fill(4, 1); - console.log(uint8.toString()); // "1,4,4" + let uint8_t2 = new Uint8Array([1, 2, 3]).fill(4, 1); + console.log(uint8_t2.toString()); // "1,4,4" - uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 2); - console.log(uint8.toString()); // "1,4,3" + let uint8_t3 = new Uint8Array([1, 2, 3]).fill(4, 1, 2); + console.log(uint8_t3.toString()); // "1,4,3" - uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 1); - console.log(uint8.toString()); // "1,2,3" + let uint8_t4 = new Uint8Array([1, 2, 3]).fill(4, 1, 1); + console.log(uint8_t4.toString()); // "1,2,3" - uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2); - console.log(uint8.toString()); // "4,2,3" + let uint8_t5 = new Uint8Array([1, 2, 3]).fill(4, -3, -2); + console.log(uint8_t5.toString()); // "4,2,3" // #END - expect(uint8.toString()).toEqual("4,2,3"); + + expect(uint8_t1.toString()).toEqual("4,4,4"); + expect(uint8_t2.toString()).toEqual("1,4,4"); + expect(uint8_t3.toString()).toEqual("1,4,3"); + expect(uint8_t4.toString()).toEqual("1,2,3"); + expect(uint8_t5.toString()).toEqual("4,2,3"); } + testFilter() { // #TEST Uint8Array.filter let uint8 = new Uint8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint8Array) : boolean => value >= 10); @@ -122,20 +128,22 @@ export class TUint8Array { // #END expect(res).toEqual(8); } - findIndex() { // #TEST Uint8Array.findIndex - let uint8 = new Uint8Array([4, 6, 8, 12]); - let res = uint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); - console.log(res); // -1 + let uint8_t1 = new Uint8Array([4, 6, 8, 12]); + let res1 = uint8_t1.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); + console.log(res1); // -1 - let uuint8 = new Uint8Array([4, 6, 7, 120]); - res = uuint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); - console.log(res); // 3 + let uint8_t2 = new Uint8Array([4, 6, 7, 120]); + let res2 = uint8_t2.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); + console.log(res2); // 3 // #END - expect(res).toEqual(3); + + expect(res1).toEqual(-1); + expect(res2).toEqual(3); } + foreach() { // #TEST Uint8Array.forEach new Uint8Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8Array) => { @@ -155,68 +163,69 @@ export class TUint8Array { } includes() { // #TEST Uint8Array.includes - let uint8 = new Uint8Array([1, 2, 3]); - let res = uint8.includes(2); - console.log(res); // true + let uint8_t1 = new Uint8Array([1, 2, 3]); + let res1 = uint8_t1.includes(2); + console.log(res1); // true - res = uint8.includes(4); - console.log(res); // false + let res2 = uint8_t1.includes(4); + console.log(res2); // false - res = uint8.includes(3, 3); - console.log(res); // false + let res3 = uint8_t1.includes(3, 3); + console.log(res3); // false // #END - expect(res).toEqual(false); + + expect(res1).toEqual(true); + expect(res2).toEqual(false); + expect(res3).toEqual(false); } indexOf() { // #TEST Uint8Array.indexOf - let uint8 = new Uint8Array([2, 5, 9]); - let res = uint8.indexOf(2); - console.log(res); // 0 - - // expect(res).toEqual(0); - - res = uint8.indexOf(7); - console.log(res); // -1 - - // expect(res).toEqual(-1); + let uint8_t1 = new Uint8Array([2, 5, 9]); + let res1 = uint8_t1.indexOf(2); + console.log(res1); // 0 - res = uint8.indexOf(9, 2); - console.log(res); // 2 + let res2 = uint8_t1.indexOf(7); + console.log(res2); // -1 - // expect(res).toEqual(2); + let res3 = uint8_t1.indexOf(9, 2); + console.log(res3); // 2 - res = uint8.indexOf(2, -1); - console.log(res); // -1 + let res4 = uint8_t1.indexOf(2, -1); + console.log(res4); // -1 - // expect(res).toEqual(-1); - - res = uint8.indexOf(2, -3); - console.log(res); // 0 + let res5 = uint8_t1.indexOf(2, -3); + console.log(res5); // 0 // #END - expect(res).toEqual(0); + + expect(res1).toEqual(0); + expect(res2).toEqual(-1); + expect(res3).toEqual(2); + expect(res4).toEqual(-1); + expect(res5).toEqual(0); } + join() { // #TEST Uint8Array.join - let uint8 = new Uint8Array([1, 2, 3]); - let res = uint8.join(); - console.log(res); // "1,2,3" - - // expect(res).toEqual("1,2,3"); + let uint8_t1 = new Uint8Array([1, 2, 3]); + let res1 = uint8_t1.join(); + console.log(res1); // "1,2,3" - res = uint8.join(" / "); - console.log(res); // "1 / 2 / 3" + let res2 = uint8_t1.join(" / "); + console.log(res2); // "1 / 2 / 3" - // expect(res).toEqual("1 / 2 / 3"); - - res = uint8.join(""); - console.log(res); // "123" + let res3 = uint8_t1.join(""); + console.log(res3); // "123" // #END - expect(res).toEqual("123"); + + expect(res1).toEqual("1,2,3"); + expect(res2).toEqual("1 / 2 / 3"); + expect(res3).toEqual("123"); } + keys() { // #TEST Uint8Array.keys let arr = new Uint8Array([10, 20, 30, 40, 50]); @@ -239,38 +248,37 @@ export class TUint8Array { } reduce() { // #TEST Uint8Array.reduce - let total = new Uint8Array([0, 1, 2, 3]); - let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => + let uint8_t1 = new Uint8Array([0, 1, 2, 3]); + let res1 = uint8_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => accumulator + currentValue); - console.log(res); // 6 + console.log(res1); // 6 - // expect(res).toEqual(6); - - total = new Uint8Array([0, 1, 2, 3]); - res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => + let res2 = uint8_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => accumulator + currentValue, 8); - console.log(res); // 14 + console.log(res2); // 14 // #END - expect(res).toEqual(14); + + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reduceRight() { // #TEST Uint8Array.reduceRight - let total = new Uint8Array([0, 1, 2, 3]); - let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => + let uint8_t1 = new Uint8Array([0, 1, 2, 3]); + let res1 = uint8_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => accumulator + currentValue); - console.log(res); // 6 + console.log(res1); // 6 - // expect(res).toEqual(6); - - total = new Uint8Array([0, 1, 2, 3]); - res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => + let res2 = uint8_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => accumulator + currentValue, 8); - console.log(res); // 14 + console.log(res2); // 14 // #END - expect(res).toEqual(14); + + expect(res1).toEqual(6); + expect(res2).toEqual(14); } + reverse() { // #TEST Uint8Array.reverse let uint8 = new Uint8Array([1, 2, 3]); @@ -282,55 +290,56 @@ export class TUint8Array { slice() { // #TEST Uint8Array.slice - let uint8 = new Uint8Array([1, 2, 3]); - let res = uint8.slice(1); - console.log(res.toString()); // "2,3" - - // expect(res.toString()).toEqual("2,3"); + let uint8_t1 = new Uint8Array([1, 2, 3]); + let res1 = uint8_t1.slice(1); + console.log(res1.toString()); // "2,3" - res = uint8.slice(2); - console.log(res.toString()); // "3" + let res2 = uint8_t1.slice(2); + console.log(res2.toString()); // "3" - // expect(res.toString()).toEqual("3"); + let res3 = uint8_t1.slice(-2); + console.log(res3.toString()); // "2,3" - res = uint8.slice(-2); - console.log(res.toString()); // "2,3" - - // expect(res.toString()).toEqual("2,3"); - - res = uint8.slice(0, 1); - console.log(res.toString()); // "1" + let res4 = uint8_t1.slice(0, 1); + console.log(res4.toString()); // "1" // #END - expect(res.toString()).toEqual("1"); + + expect(res1.toString()).toEqual("2,3"); + expect(res2.toString()).toEqual("3"); + expect(res3.toString()).toEqual("2,3"); + expect(res4.toString()).toEqual("1"); } + sort() { // #TEST Uint8Array.sort - let numbers = new Uint8Array([40, 1, 5]); - numbers.sort(); - console.log(numbers.toString()); // "1,5,40" - - // expect(numbers.toString()).toEqual("1,5,40"); + let numbers_t1 = new Uint8Array([40, 1, 5]); + numbers_t1.sort(); + console.log(numbers_t1.toString()); // "1,5,40" - numbers.sort((a, b) : number => a - b); - console.log(numbers.toString()); // "1,5,40" + let numbers_t2 = new Uint8Array([40, 1, 5]); + numbers_t2.sort((a, b) : number => a - b); + console.log(numbers_t2.toString()); // "1,5,40" // #END - expect(numbers.toString()).toEqual("1,5,40"); + + expect(numbers_t1.toString()).toEqual("1,5,40"); + expect(numbers_t2.toString()).toEqual("1,5,40"); } + subarray() { // #TEST Uint8Array.subarray let buffer = new ArrayBuffer(16); - let uint8 = new Uint8Array(buffer); - uint8.set([1, 2, 3]); - console.log(uint8.toString()); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0" + let uint8_t1 = new Uint8Array(buffer); + uint8_t1.set([1, 2, 3]); + console.log(uint8_t1.toString()); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0" - // expect(uint8.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"); - - let sub = uint8.subarray(0, 4); - console.log(sub.toString()); // "1,2,3,0" + let sub_t1 = uint8_t1.subarray(0, 4); + console.log(sub_t1.toString()); // "1,2,3,0" // #END - expect(sub.toString()).toEqual("1,2,3,0"); + + expect(uint8_t1.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"); + expect(sub_t1.toString()).toEqual("1,2,3,0"); } values() { @@ -359,22 +368,24 @@ export class TUint8Array { testSome() { // #TEST Uint8Array.some - const uint8 = new Uint8Array([8, 20, 30, 40, 50]); - const positives = new Uint8Array([10, 20, 30, 40, 50]); - var res = uint8.some((element : number, index : number, array : Uint8Array) : boolean => + const uint8_t1 = new Uint8Array([8, 20, 30, 40, 50]); + const positives_t1 = new Uint8Array([10, 20, 30, 40, 50]); + + let res_t1 = uint8_t1.some((element : number, index : number, array : Uint8Array) : boolean => element < 10 ); - console.log('uint8', res); // true - - // expect(res).toEqual(true); + console.log('uint8_t1', res_t1); // true - res = positives.some((element : number, index : number, array : Uint8Array) : boolean => + let res_t2 = positives_t1.some((element : number, index : number, array : Uint8Array) : boolean => element < 0 ); - console.log('positives', res); // false + console.log('positives_t1', res_t2); // false + // #END - expect(res).toEqual(false); + expect(res_t1).toEqual(true); + expect(res_t2).toEqual(false); } + // #endif } \ No newline at end of file diff --git a/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts b/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts index 56c9321b5dbe5bcda319f397dfccee5dbc6411ab..221e453c3565322276f3aa1af52f937f8465ceeb 100644 --- a/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts +++ b/uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts @@ -84,25 +84,31 @@ export class TUint8ClampedArray { testFill() { // #TEST Uint8ClampedArray.fill - let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4); - console.log(uint8Clamped.toString()); // "4,4,4" + let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]).fill(4); + console.log(uint8Clamped_t1.toString()); // "4,4,4" - uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1); - console.log(uint8Clamped.toString()); // "1,4,4" + let uint8Clamped_t2 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1); + console.log(uint8Clamped_t2.toString()); // "1,4,4" - uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2); - console.log(uint8Clamped.toString()); // "1,4,3" + let uint8Clamped_t3 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2); + console.log(uint8Clamped_t3.toString()); // "1,4,3" - uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1); - console.log(uint8Clamped.toString()); // "1,2,3" + let uint8Clamped_t4 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1); + console.log(uint8Clamped_t4.toString()); // "1,2,3" + + let uint8Clamped_t5 = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2); + console.log(uint8Clamped_t5.toString()); // "4,2,3" - uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2); - console.log(uint8Clamped.toString()); // "4,2,3" // #END - expect(uint8Clamped.toString()).toEqual("4,2,3"); + expect(uint8Clamped_t1.toString()).toEqual("4,4,4"); + expect(uint8Clamped_t2.toString()).toEqual("1,4,4"); + expect(uint8Clamped_t3.toString()).toEqual("1,4,3"); + expect(uint8Clamped_t4.toString()).toEqual("1,2,3"); + expect(uint8Clamped_t5.toString()).toEqual("4,2,3"); } + testFilter() { // #TEST Uint8ClampedArray.filter // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; @@ -125,17 +131,20 @@ export class TUint8ClampedArray { findIndex() { // #TEST Uint8ClampedArray.findIndex - let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]); - let res = uint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); - console.log(res); // -1 + let uint8Clamped_t1 = new Uint8ClampedArray([4, 6, 8, 12]); + let res1 = uint8Clamped_t1.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); + console.log(res1); // -1 + + let uint8Clamped_t2 = new Uint8ClampedArray([4, 6, 7, 120]); + let res2 = uint8Clamped_t2.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); + console.log(res2); // 3 - let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]); - res = uuint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); - console.log(res); // 3 // #END - expect(res).toEqual(3); + expect(res1).toEqual(-1); + expect(res2).toEqual(3); } + foreach() { // #TEST Uint8ClampedArray.forEach new Uint8ClampedArray([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8ClampedArray) => { @@ -156,53 +165,73 @@ export class TUint8ClampedArray { includes() { // #TEST Uint8ClampedArray.includes - let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); - let res = uint8Clamped.includes(2); - console.log(res); // true + let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]); + let res1 = uint8Clamped_t1.includes(2); + console.log(res1); // true - res = uint8Clamped.includes(4); - console.log(res); // false + let uint8Clamped_t2 = new Uint8ClampedArray([1, 2, 3]); + let res2 = uint8Clamped_t2.includes(4); + console.log(res2); // false + + let uint8Clamped_t3 = new Uint8ClampedArray([1, 2, 3]); + let res3 = uint8Clamped_t3.includes(3, 3); + console.log(res3); // false - res = uint8Clamped.includes(3, 3); - console.log(res); // false // #END - expect(res).toEqual(false); + expect(res1).toEqual(true); + expect(res2).toEqual(false); + expect(res3).toEqual(false); } indexOf() { // #TEST Uint8ClampedArray.indexOf - let uint8Clamped = new Uint8ClampedArray([2, 5, 9]); - let res = uint8Clamped.indexOf(2); - console.log(res); // 0 + let uint8Clamped_t1 = new Uint8ClampedArray([2, 5, 9]); + let res1 = uint8Clamped_t1.indexOf(2); + console.log(res1); // 0 + + let uint8Clamped_t2 = new Uint8ClampedArray([2, 5, 9]); + let res2 = uint8Clamped_t2.indexOf(7); + console.log(res2); // -1 - res = uint8Clamped.indexOf(7); - console.log(res); // -1 + let uint8Clamped_t3 = new Uint8ClampedArray([2, 5, 9]); + let res3 = uint8Clamped_t3.indexOf(9, 2); + console.log(res3); // 2 - res = uint8Clamped.indexOf(9, 2); - console.log(res); // 2 + let uint8Clamped_t4 = new Uint8ClampedArray([2, 5, 9]); + let res4 = uint8Clamped_t4.indexOf(2, -1); + console.log(res4); // -1 - res = uint8Clamped.indexOf(2, -1); - console.log(res); // -1 + let uint8Clamped_t5 = new Uint8ClampedArray([2, 5, 9]); + let res5 = uint8Clamped_t5.indexOf(2, -3); + console.log(res5); // 0 - res = uint8Clamped.indexOf(2, -3); - console.log(res); // 0 // #END - expect(res).toEqual(0); + expect(res1).toEqual(0); + expect(res2).toEqual(-1); + expect(res3).toEqual(2); + expect(res4).toEqual(-1); + expect(res5).toEqual(0); } + join() { // #TEST Uint8ClampedArray.join - let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); - let res = uint8Clamped.join(); - console.log(res); // "1,2,3" + let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]); + let res1 = uint8Clamped_t1.join(); + console.log(res1); // "1,2,3" - res = uint8Clamped.join(" / "); - console.log(res); // "1 / 2 / 3" + let uint8Clamped_t2 = new Uint8ClampedArray([1, 2, 3]); + let res2 = uint8Clamped_t2.join(" / "); + console.log(res2); // "1 / 2 / 3" + + let uint8Clamped_t3 = new Uint8ClampedArray([1, 2, 3]); + let res3 = uint8Clamped_t3.join(""); + console.log(res3); // "123" - res = uint8Clamped.join(""); - console.log(res); // "123" // #END - expect(res).toEqual("123"); + expect(res1).toEqual("1,2,3"); + expect(res2).toEqual("1 / 2 / 3"); + expect(res3).toEqual("123"); } keys() { @@ -227,32 +256,36 @@ export class TUint8ClampedArray { reduce() { // #TEST Uint8ClampedArray.reduce - let total = new Uint8ClampedArray([0, 1, 2, 3]); - let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => + let total_t1 = new Uint8ClampedArray([0, 1, 2, 3]); + let res1 = total_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => accumulator + currentValue); - console.log(res); // 6 + console.log(res1); // 6 - total = new Uint8ClampedArray([0, 1, 2, 3]); - res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => + let total_t2 = new Uint8ClampedArray([0, 1, 2, 3]); + let res2 = total_t2.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => accumulator + currentValue, 8); - console.log(res); // 14 + console.log(res2); // 14 + // #END - expect(res).toEqual(14); + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reduceRight() { // #TEST Uint8ClampedArray.reduceRight - let total = new Uint8ClampedArray([0, 1, 2, 3]); - let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => + let total_t1 = new Uint8ClampedArray([0, 1, 2, 3]); + let res1 = total_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => accumulator + currentValue); - console.log(res); // 6 + console.log(res1); // 6 - total = new Uint8ClampedArray([0, 1, 2, 3]); - res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => + let total_t2 = new Uint8ClampedArray([0, 1, 2, 3]); + let res2 = total_t2.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => accumulator + currentValue, 8); - console.log(res); // 14 + console.log(res2); // 14 + // #END - expect(res).toEqual(14); + expect(res1).toEqual(6); + expect(res2).toEqual(14); } @@ -267,47 +300,54 @@ export class TUint8ClampedArray { slice() { // #TEST Uint8ClampedArray.slice - let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); - let res = uint8Clamped.slice(1); - console.log(res.toString()); // "2,3" + let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]); + let res1 = uint8Clamped_t1.slice(1); + console.log(res1.toString()); // "2,3" - res = uint8Clamped.slice(2); - console.log(res.toString()); // "3" + let res2 = uint8Clamped_t1.slice(2); + console.log(res2.toString()); // "3" - res = uint8Clamped.slice(-2); - console.log(res.toString()); // "2,3" + let res3 = uint8Clamped_t1.slice(-2); + console.log(res3.toString()); // "2,3" - res = uint8Clamped.slice(0, 1); - console.log(res.toString()); // "1" + let res4 = uint8Clamped_t1.slice(0, 1); + console.log(res4.toString()); // "1" // #END - expect(res.toString()).toEqual("1"); + expect(res1.toString()).toEqual("2,3"); + expect(res2.toString()).toEqual("3"); + expect(res3.toString()).toEqual("2,3"); + expect(res4.toString()).toEqual("1"); } - - sort() { // #TEST Uint8ClampedArray.sort - let numbers = new Uint8ClampedArray([40, 1, 5]); - numbers.sort(); - console.log(numbers.toString()); // "1,5,40" - - numbers.sort((a, b) : number => a - b); - console.log(numbers.toString()); // "1,5,40" + let uint8Clamped_t1 = new Uint8ClampedArray([40, 1, 5]); + uint8Clamped_t1.sort(); + let res1 = uint8Clamped_t1.toString(); + console.log(res1); // "1,5,40" + + uint8Clamped_t1.sort((a, b) : number => a - b); + let res2 = uint8Clamped_t1.toString(); + console.log(res2); // "1,5,40" // #END - expect(numbers.toString()).toEqual("1,5,40"); + expect(res1).toEqual("1,5,40"); + expect(res2).toEqual("1,5,40"); } subarray() { // #TEST Uint8ClampedArray.subarray let buffer = new ArrayBuffer(16); - let uint8Clamped = new Uint8ClampedArray(buffer); - uint8Clamped.set([1, 2, 3]); - console.log(uint8Clamped.toString()); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0" - - let sub = uint8Clamped.subarray(0, 4); - console.log(sub.toString()); // "1,2,3,0" + let uint8Clamped_t1 = new Uint8ClampedArray(buffer); + uint8Clamped_t1.set([1, 2, 3]); + let res1 = uint8Clamped_t1.toString(); + console.log(res1); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0" + + let sub = uint8Clamped_t1.subarray(0, 4); + let res2 = sub.toString(); + console.log(res2); // "1,2,3,0" // #END - expect(sub.toString()).toEqual("1,2,3,0"); + expect(res1).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"); + expect(res2).toEqual("1,2,3,0"); } diff --git a/uni_modules/uts-tests/utssdk/TUint16Array.uts b/uni_modules/uts-tests/utssdk/TUint16Array.uts index 700ec419c1ded7e67a6c3f73a07a05260ee0cb2c..4ada02d0ddafd7ad9e4cace09d7e331028461729 100644 --- a/uni_modules/uts-tests/utssdk/TUint16Array.uts +++ b/uni_modules/uts-tests/utssdk/TUint16Array.uts @@ -372,24 +372,32 @@ export class TUint16Array { let res = buffer.slice(8); let sliced = new Uint16Array(res); console.log(sliced[0]); // 42 + // #END + expect(uint16.toString()).toEqual("0,0,0,0,42,0,0,0"); expect(sliced[0]).toEqual(42); } + testSome() { // #TEST Uint16Array.some const uint16 = new Uint16Array([8, 20, 30, 40, 50]); const positives = new Uint16Array([10, 20, 30, 40, 50]); - expect(uint16.some((element : number, index : number, array : Uint16Array) : boolean => + const res1 = uint16.some((element : number, index : number, array : Uint16Array) : boolean => element < 10 - )).toEqual(true); + ); + console.log('uint16', res1); // true - expect(positives.some((element : number, index : number, array : Uint16Array) : boolean => + const res2 = positives.some((element : number, index : number, array : Uint16Array) : boolean => element < 0 - )).toEqual(false); + ); + console.log('positives', res2); // false // #END + expect(res1).toEqual(true); + expect(res2).toEqual(false); } + // #endif } \ No newline at end of file diff --git a/uni_modules/uts-tests/utssdk/TUint32Array.uts b/uni_modules/uts-tests/utssdk/TUint32Array.uts index 8c1a02bdd0567b9fa31ff48a68637ee76ef30784..3099ff8660f8951f42fc3cf4d0000430017d10a7 100644 --- a/uni_modules/uts-tests/utssdk/TUint32Array.uts +++ b/uni_modules/uts-tests/utssdk/TUint32Array.uts @@ -75,15 +75,14 @@ export class TUint32Array { testCopyWith() { // #TEST Uint32Array.copyWithin - console.log("testCopyWith 1"); let uint32 = new Uint32Array(8); uint32.set([1, 2, 3], 1); - console.log("testCopyWith 2"); uint32.copyWithin(3, 0, 3); - console.log("testCopyWith 3"); - console.log(uint32.toString()); // "0,1,2,0,1,2,0,0" + let result2 = uint32.toString(); + console.log(result2); // "0,1,2,0,1,2,0,0" + // #END - expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0"); + expect(result2).toEqual("0,1,2,0,1,2,0,0"); } testEvery() { @@ -93,21 +92,34 @@ export class TUint32Array { // #END expect(result).toEqual(false); } - testFill() { // #TEST Uint32Array.fill let uint32 = new Uint32Array([1, 2, 3]).fill(4); - console.log(uint32.toString()); // "4,4,4" + let result1 = uint32.toString(); + console.log(result1); // "4,4,4" + uint32 = new Uint32Array([1, 2, 3]).fill(4, 1); - console.log(uint32.toString()); // "1,4,4" + let result2 = uint32.toString(); + console.log(result2); // "1,4,4" + uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 2); - console.log(uint32.toString()); // "1,4,3" + let result3 = uint32.toString(); + console.log(result3); // "1,4,3" + uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 1); - console.log(uint32.toString()); // "1,2,3" + let result4 = uint32.toString(); + console.log(result4); // "1,2,3" + uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2); - console.log(uint32.toString()); // "4,2,3" + let result5 = uint32.toString(); + console.log(result5); // "4,2,3" + // #END - expect(uint32.toString()).toEqual("4,2,3"); + expect(result1).toEqual("4,4,4"); + expect(result2).toEqual("1,4,4"); + expect(result3).toEqual("1,4,3"); + expect(result4).toEqual("1,2,3"); + expect(result5).toEqual("4,2,3"); } @@ -131,14 +143,19 @@ export class TUint32Array { findIndex() { // #TEST Uint32Array.findIndex let uint32 = new Uint32Array([4, 6, 8, 12]); - let res = uint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100); - console.log(res); // -1 - res = new Uint32Array([4, 6, 7, 120]).findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100); - console.log(res); // 3 + + let res1 = uint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100); + console.log(res1); // -1 + + let res2 = new Uint32Array([4, 6, 7, 120]).findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100); + console.log(res2); // 3 + // #END - expect(res).toEqual(3); + expect(res1).toEqual(-1); + expect(res2).toEqual(3); } + foreach() { // #TEST Uint32Array.forEach new Uint32Array([0, 1, 2, 3]).forEach((value : number, index : number, _a : Uint32Array) => { @@ -160,47 +177,70 @@ export class TUint32Array { includes() { // #TEST Uint32Array.includes let uint32 = new Uint32Array([1, 2, 3]); - let res = uint32.includes(2); - console.log(res); // true - res = uint32.includes(4); - console.log(res); // false - res = uint32.includes(3, 3); - console.log(res); // false + + let res1 = uint32.includes(2); + console.log(res1); // true + + let res2 = uint32.includes(4); + console.log(res2); // false + + let res3 = uint32.includes(3, 3); + console.log(res3); // false + // #END - expect(res).toEqual(false); + expect(res1).toEqual(true); + expect(res2).toEqual(false); + expect(res3).toEqual(false); } indexOf() { // #TEST Uint32Array.indexOf let uint32 = new Uint32Array([2, 5, 9]); - let res = uint32.indexOf(2); - console.log(res); // 0 - res = uint32.indexOf(7); - console.log(res); // -1 - res = uint32.indexOf(9, 2); - console.log(res); // 2 - res = uint32.indexOf(2, -1); - console.log(res); // -1 - res = uint32.indexOf(2, -3); - console.log(res); // 0 + + let res1 = uint32.indexOf(2); + console.log(res1); // 0 + + let res2 = uint32.indexOf(7); + console.log(res2); // -1 + + let res3 = uint32.indexOf(9, 2); + console.log(res3); // 2 + + let res4 = uint32.indexOf(2, -1); + console.log(res4); // -1 + + let res5 = uint32.indexOf(2, -3); + console.log(res5); // 0 + // #END - expect(res).toEqual(0); + expect(res1).toEqual(0); + expect(res2).toEqual(-1); + expect(res3).toEqual(2); + expect(res4).toEqual(-1); + expect(res5).toEqual(0); } join() { // #TEST Uint32Array.join let uint32 = new Uint32Array([1, 2, 3]); - let res = uint32.join(); - console.log(res); // "1,2,3" - res = uint32.join(" / "); - console.log(res); // "1 / 2 / 3" - res = uint32.join(""); - console.log(res); // "123" + + let res1 = uint32.join(); + console.log(res1); // "1,2,3" + + let res2 = uint32.join(" / "); + console.log(res2); // "1 / 2 / 3" + + let res3 = uint32.join(""); + console.log(res3); // "123" + // #END - expect(res).toEqual("123"); + expect(res1).toEqual("1,2,3"); + expect(res2).toEqual("1 / 2 / 3"); + expect(res3).toEqual("123"); } + keys() { // #TEST Uint32Array.keys let arr = new Uint32Array([10, 20, 30, 40, 50]); @@ -225,25 +265,33 @@ export class TUint32Array { reduce() { // #TEST Uint32Array.reduce let total = new Uint32Array([0, 1, 2, 3]); - let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue); - console.log(res); // 6 + + let res1 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue); + console.log(res1); // 6 + total = new Uint32Array([0, 1, 2, 3]); - res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8); - console.log(res); // 14 + let res2 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8); + console.log(res2); // 14 + // #END - expect(res).toEqual(14); + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reduceRight() { // #TEST Uint32Array.reduceRight let total = new Uint32Array([0, 1, 2, 3]); - let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue); - console.log(res); // 6 + + let res1 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue); + console.log(res1); // 6 + total = new Uint32Array([0, 1, 2, 3]); - res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8); - console.log(res); // 14 + let res2 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8); + console.log(res2); // 14 + // #END - expect(res).toEqual(14); + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reverse() { @@ -259,48 +307,62 @@ export class TUint32Array { slice() { // #TEST Uint32Array.slice let uint32 = new Uint32Array([1, 2, 3]); - let res = uint32.slice(1); - console.log(res.toString()); // "2,3" - res = uint32.slice(2); - console.log(res.toString()); // "3" + let res1 = uint32.slice(1); + let res1String = res1.toString(); + console.log(res1String); // "2,3" + + let res2 = uint32.slice(2); + let res2String = res2.toString(); + console.log(res2String); // "3" - res = uint32.slice(-2); - console.log(res.toString()); // "2,3" + let res3 = uint32.slice(-2); + let res3String = res3.toString(); + console.log(res3String); // "2,3" + + let res4 = uint32.slice(0, 1); + let res4String = res4.toString(); + console.log(res4String); // "1" - res = uint32.slice(0, 1); - console.log(res.toString()); // "1" // #END - expect(res.toString()).toEqual("1"); + expect(res1String).toEqual("2,3"); + expect(res2String).toEqual("3"); + expect(res3String).toEqual("2,3"); + expect(res4String).toEqual("1"); } sort() { // #TEST Uint32Array.sort let numbers = new Uint32Array([40, 1, 5]); - numbers.sort(); - console.log(numbers.toString()); // "1,5,40" + let numbersString = numbers.toString(); + console.log(numbersString); // "1,5,40" numbers.sort((a, b) : number => a - b); - console.log(numbers.toString()); // "1,5,40" + let sortedString = numbers.toString(); + console.log(sortedString); // "1,5,40" // #END - expect(numbers.toString()).toEqual("1,5,40"); + expect(numbersString).toEqual("40,1,5"); + expect(sortedString).toEqual("1,5,40"); } - subarray() { // #TEST Uint32Array.subarray let buffer = new ArrayBuffer(16); let uint32 = new Uint32Array(buffer); uint32.set([1, 2, 3]); - console.log(uint32.toString()); // "1,2,3,0" + let uint32String = uint32.toString(); + console.log(uint32String); // "1,2,3,0" let sub = uint32.subarray(0, 4); - console.log(sub.toString()); // "1,2,3,0" + let subString = sub.toString(); + console.log(subString); // "1,2,3,0" // #END - expect(sub.toString()).toEqual("1,2,3,0"); + expect(uint32String).toEqual("1,2,3,0"); + expect(subString).toEqual("1,2,3,0"); } + values() { // #TEST Uint32Array.values let arr = new Uint32Array([1, 2, 3]); @@ -310,7 +372,6 @@ export class TUint32Array { // #END expect(value).toEqual(1); } - arrayBufferSlice() { // #TEST ArrayBuffer.slice let buffer = new ArrayBuffer(16); @@ -322,6 +383,7 @@ export class TUint32Array { let sliced = new Uint32Array(res); console.log(sliced[1]); // 42 // #END + expect(uint32.toString()).toEqual("0,0,0,42"); expect(sliced[1]).toEqual(42); } @@ -331,17 +393,18 @@ export class TUint32Array { const uint32 = new Uint32Array([8, 20, 30, 40, 50]); const positives = new Uint32Array([10, 20, 30, 40, 50]); - let result = uint32.some((element : number, index : number, array : Uint32Array) : boolean => + let result1 = uint32.some((element : number, index : number, array : Uint32Array) : boolean => element < 10 ); - console.log(result); // true + console.log(result1); // true - result = positives.some((element : number, index : number, array : Uint32Array) : boolean => + let result2 = positives.some((element : number, index : number, array : Uint32Array) : boolean => element < 0 ); - console.log(result); // false + console.log(result2); // false // #END - expect(result).toEqual(false); + expect(result1).toEqual(true); + expect(result2).toEqual(false); }