From c51d4faebf53694820b0c3e17a7591c61625c081 Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Thu, 1 Aug 2024 11:29:39 +0800 Subject: [PATCH] =?UTF-8?q?[array-buffer]uint16array=E6=B7=BB=E5=8A=A0cons?= =?UTF-8?q?ole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uts-tests/utssdk/TFloat64Array.uts | 12 +- uni_modules/uts-tests/utssdk/TUint16Array.uts | 196 +++++++++--------- 2 files changed, 102 insertions(+), 106 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/TFloat64Array.uts b/uni_modules/uts-tests/utssdk/TFloat64Array.uts index 219639b..5f65fcb 100644 --- a/uni_modules/uts-tests/utssdk/TFloat64Array.uts +++ b/uni_modules/uts-tests/utssdk/TFloat64Array.uts @@ -237,13 +237,14 @@ export class TFloat64Array { // #TEST Float64Array.keys let arr = new Float64Array([10, 20, 30, 40, 50]); let keys = arr.keys(); - console.log(keys.next().value); // 0 + let value = keys.next().value + console.log(value); // 0 console.log(keys.next().value); // 1 console.log(keys.next().value); // 2 console.log(keys.next().value); // 3 console.log(keys.next().value); // 4 // #END - expect(keys.next().value).toEqual(-1); + expect(value).toEqual(0); } map() { @@ -334,7 +335,7 @@ export class TFloat64Array { } } console.log(ret5); // true; - + // #END expect(ret4).toEqual("1"); expect(ret3.toString()).toEqual("2,3"); @@ -389,11 +390,12 @@ export class TFloat64Array { // #TEST Float64Array.values let arr = new Float64Array([1, 2, 3]); let values = arr.values(); - console.log(values.next().value); // 1 + let value = values.next().value + console.log(value); // 1 console.log(values.next().value); // 2 console.log(values.next().value); // 3 // #END - expect(values.next().value).toEqual(-1); + expect(value).toEqual(1); } arrayBufferSlice() { diff --git a/uni_modules/uts-tests/utssdk/TUint16Array.uts b/uni_modules/uts-tests/utssdk/TUint16Array.uts index 956c120..700ec41 100644 --- a/uni_modules/uts-tests/utssdk/TUint16Array.uts +++ b/uni_modules/uts-tests/utssdk/TUint16Array.uts @@ -98,28 +98,24 @@ export class TUint16Array { // #TEST Uint16Array.fill let uint16 = new Uint16Array([1, 2, 3]).fill(4); console.log(uint16.toString()); // "4,4,4" - // #END - expect(uint16.toString()).toEqual("4,4,4"); - uint16 = new Uint16Array([1, 2, 3]).fill(4, 1); - console.log(uint16.toString()); // "1,4,4" - // #END - expect(uint16.toString()).toEqual("1,4,4"); + let uint16_t1 = new Uint16Array([1, 2, 3]).fill(4, 1); + console.log(uint16_t1.toString()); // "1,4,4" - uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 2); - console.log(uint16.toString()); // "1,4,3" - // #END - expect(uint16.toString()).toEqual("1,4,3"); + let uint16_t2 = new Uint16Array([1, 2, 3]).fill(4, 1, 2); + console.log(uint16_t2.toString()); // "1,4,3" - uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 1); - console.log(uint16.toString()); // "1,2,3" - // #END - expect(uint16.toString()).toEqual("1,2,3"); + let uint16_t3 = new Uint16Array([1, 2, 3]).fill(4, 1, 1); + console.log(uint16_t3.toString()); // "1,2,3" - uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2); - console.log(uint16.toString()); // "4,2,3" + let uint16_t4 = new Uint16Array([1, 2, 3]).fill(4, -3, -2); + console.log(uint16_t4.toString()); // "4,2,3" // #END - expect(uint16.toString()).toEqual("4,2,3"); + expect(uint16_t4.toString()).toEqual("4,2,3"); + expect(uint16.toString()).toEqual("4,4,4"); + expect(uint16_t1.toString()).toEqual("1,4,4"); + expect(uint16_t2.toString()).toEqual("1,4,3"); + expect(uint16_t3.toString()).toEqual("1,2,3"); } testFilter() { @@ -145,14 +141,15 @@ export class TUint16Array { let uint16 = new Uint16Array([4, 6, 8, 12]); let res = uint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100); console.log(res); // -1 - // #END - expect(res).toEqual(-1); + let uuint16 = new Uint16Array([4, 6, 7, 120]); - res = uuint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100); - console.log(res); // 3 + let res1 = uuint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100); + console.log(res1); // 3 // #END - expect(res).toEqual(3); + expect(res1).toEqual(3); + + expect(res).toEqual(-1); } foreach() { @@ -178,66 +175,60 @@ export class TUint16Array { let uint16 = new Uint16Array([1, 2, 3]); let res = uint16.includes(2); console.log(res); // true - // #END - expect(res).toEqual(true); - res = uint16.includes(4); - console.log(res); // false - // #END - expect(res).toEqual(false); + let res1 = uint16.includes(4); + console.log(res1); // false - res = uint16.includes(3, 3); - console.log(res); // false + let res2 = uint16.includes(3, 3); + console.log(res2); // false // #END - expect(res).toEqual(false); + expect(res2).toEqual(false); + expect(res1).toEqual(false); + expect(res).toEqual(true); } indexOf() { // #TEST Uint16Array.indexOf let uint16 = new Uint16Array([2, 5, 9]); - let res = uint16.indexOf(2); - console.log(res); // 0 - // #END - expect(res).toEqual(0); - res = uint16.indexOf(7); - console.log(res); // -1 - // #END - expect(res).toEqual(-1); + let res1 = uint16.indexOf(2); + console.log(res1); // 0 - res = uint16.indexOf(9, 2); - console.log(res); // 2 - // #END - expect(res).toEqual(2); + let res2 = uint16.indexOf(7); + console.log(res2); // -1 - res = uint16.indexOf(2, -1); - console.log(res); // -1 - // #END - expect(res).toEqual(-1); + let res3 = uint16.indexOf(9, 2); + console.log(res3); // 2 + + let res4 = uint16.indexOf(2, -1); + console.log(res4); // -1 - res = uint16.indexOf(2, -3); - console.log(res); // 0 + let res5 = uint16.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 Uint16Array.join let uint16 = new Uint16Array([1, 2, 3]); - let res = uint16.join(); - console.log(res); // "1,2,3" - // #END - expect(res).toEqual("1,2,3"); + let res1 = uint16.join(); + console.log(res1); // "1,2,3" - res = uint16.join(" / "); - console.log(res); // "1 / 2 / 3" - // #END - expect(res).toEqual("1 / 2 / 3"); + let res2 = uint16.join(" / "); + console.log(res2); // "1 / 2 / 3" - res = uint16.join(""); - console.log(res); // "123" + let res3 = uint16.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() { @@ -263,35 +254,39 @@ export class TUint16Array { reduce() { // #TEST Uint16Array.reduce let total = new Uint16Array([0, 1, 2, 3]); - let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => - accumulator + currentValue); - console.log(res); // 6 - // #END - expect(res).toEqual(6); + let res1 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => + accumulator + currentValue + ); + console.log(res1); // 6 total = new Uint16Array([0, 1, 2, 3]); - res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => - accumulator + currentValue, 8); - console.log(res); // 14 + let res2 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => + accumulator + currentValue, 8 + ); + console.log(res2); // 14 // #END - expect(res).toEqual(14); + + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reduceRight() { // #TEST Uint16Array.reduceRight let total = new Uint16Array([0, 1, 2, 3]); - let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => - accumulator + currentValue); - console.log(res); // 6 - // #END - expect(res).toEqual(6); + let res1 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => + accumulator + currentValue + ); + console.log(res1); // 6 total = new Uint16Array([0, 1, 2, 3]); - res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => - accumulator + currentValue, 8); - console.log(res); // 14 + let res2 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => + accumulator + currentValue, 8 + ); + console.log(res2); // 14 // #END - expect(res).toEqual(14); + + expect(res1).toEqual(6); + expect(res2).toEqual(14); } reverse() { @@ -306,56 +301,57 @@ export class TUint16Array { slice() { // #TEST Uint16Array.slice let uint16 = new Uint16Array([1, 2, 3]); - let res = uint16.slice(1); - console.log(res.toString()); // "2,3" - // #END - expect(res.toString()).toEqual("2,3"); + let res1 = uint16.slice(1); + console.log(res1.toString()); // "2,3" - res = uint16.slice(2); - console.log(res.toString()); // "3" - // #END - expect(res.toString()).toEqual("3"); + let res2 = uint16.slice(2); + console.log(res2.toString()); // "3" - res = uint16.slice(-2); - console.log(res.toString()); // "2,3" - // #END - expect(res.toString()).toEqual("2,3"); + let res3 = uint16.slice(-2); + console.log(res3.toString()); // "2,3" - res = uint16.slice(0, 1); - console.log(res.toString()); // "1" + let res4 = uint16.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 Uint16Array.sort let numbers = new Uint16Array([40, 1, 5]); numbers.sort(); console.log(numbers.toString()); // "1,5,40" - // #END - expect(numbers.toString()).toEqual("1,5,40"); numbers.sort((a, b) : number => a - b); console.log(numbers.toString()); // "1,5,40" // #END + + expect(numbers.toString()).toEqual("1,5,40"); expect(numbers.toString()).toEqual("1,5,40"); } + subarray() { // #TEST Uint16Array.subarray let buffer = new ArrayBuffer(16); let uint16 = new Uint16Array(buffer); uint16.set([1, 2, 3]); console.log(uint16.toString()); // "1,2,3,0,0,0,0,0" - // #END - expect(uint16.toString()).toEqual("1,2,3,0,0,0,0,0"); let sub = uint16.subarray(0, 4); console.log(sub.toString()); // "1,2,3,0" // #END + + expect(uint16.toString()).toEqual("1,2,3,0,0,0,0,0"); expect(sub.toString()).toEqual("1,2,3,0"); } + values() { // #TEST Uint16Array.values let arr = new Uint16Array([1, 2, 3]); @@ -372,8 +368,6 @@ export class TUint16Array { let uint16 = new Uint16Array(buffer); uint16[4] = 42; console.log(uint16.toString()); // "0,0,0,0,42,0,0,0" - // #END - expect(uint16.toString()).toEqual("0,0,0,0,42,0,0,0"); let res = buffer.slice(8); let sliced = new Uint16Array(res); -- GitLab