提交 b290253c 编写于 作者: M mahaifeng

[array-buffer]arraybuffer添加console

上级 4621bbc1
...@@ -271,15 +271,20 @@ export class TFloat32Array { ...@@ -271,15 +271,20 @@ export class TFloat32Array {
reduce() { reduce() {
// #TEST Float32Array.reduce // #TEST Float32Array.reduce
let total = new Float32Array([0, 1, 2, 3]); let total = new Float32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue); let res1 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number =>
console.log(res); // 6 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 // #END
expect(res).toEqual(6);
// total = new Float32Array([0, 1, 2, 3]); expect(res1).toEqual(6);
// res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue, 8); expect(res2).toEqual(14);
// console.log(res); // 14
// expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
...@@ -399,4 +404,4 @@ export class TFloat32Array { ...@@ -399,4 +404,4 @@ export class TFloat32Array {
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -73,32 +73,30 @@ export class TInt16Array { ...@@ -73,32 +73,30 @@ export class TInt16Array {
testFill() { testFill() {
// #TEST Int16Array.fill // #TEST Int16Array.fill
let int16 = new Int16Array([1, 2, 3]).fill(4); let int16_t1 = new Int16Array([1, 2, 3]).fill(4);
console.log(int16.toString()); // "4,4,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); let int16_t3 = new Int16Array([1, 2, 3]).fill(4, 1, 2);
console.log(int16.toString()); // "1,4,4" 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); let int16_t5 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
console.log(int16.toString()); // "1,4,3" console.log(int16_t5.toString()); // "4,2,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"
// #END // #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() { testFilter() {
// #TEST Int16Array.filter // #TEST Int16Array.filter
let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a : Int16Array) : boolean => value >= 10); let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a : Int16Array) : boolean => value >= 10);
......
...@@ -93,33 +93,29 @@ export class TInt32Array { ...@@ -93,33 +93,29 @@ export class TInt32Array {
// #END // #END
expect(result).toEqual(false); expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Int32Array.fill // #TEST Int32Array.fill
let int32 = new Int32Array([1, 2, 3]).fill(4); let int32_t1 = new Int32Array([1, 2, 3]).fill(4);
console.log(int32.toString()); // "4,4,4" console.log(int32_t1.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");
int32 = new Int32Array([1, 2, 3]).fill(4, 1, 2); let int32_t2 = new Int32Array([1, 2, 3]).fill(4, 1);
console.log(int32.toString()); // "1,4,3" 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); let int32_t4 = new Int32Array([1, 2, 3]).fill(4, 1, 1);
console.log(int32.toString()); // "1,2,3" console.log(int32_t4.toString()); // "1,2,3"
// expect(int32.toString()).toEqual("1,2,3");
int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2); let int32_t5 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
console.log(int32.toString()); // "4,2,3" console.log(int32_t5.toString()); // "4,2,3"
// #END // #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() { testFilter() {
...@@ -138,22 +134,22 @@ export class TInt32Array { ...@@ -138,22 +134,22 @@ export class TInt32Array {
// #END // #END
expect(res).toEqual(8); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Int32Array.findIndex // #TEST Int32Array.findIndex
let int32 = new Int32Array([4, 6, 8, 12]); let int32_t1 = new Int32Array([4, 6, 8, 12]);
let res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); let res1 = int32_t1.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
console.log(res); // -1 console.log(res1); // -1
// expect(res).toEqual(-1); let int32_t2 = new Int32Array([4, 6, 7, 120]);
let res2 = int32_t2.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
int32 = new Int32Array([4, 6, 7, 120]); console.log(res2); // 3
res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
console.log(res); // 3
// #END // #END
expect(res).toEqual(3);
expect(res1).toEqual(-1);
expect(res2).toEqual(3);
} }
foreach() { foreach() {
// #TEST Int32Array.forEach // #TEST Int32Array.forEach
new Int32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int32Array) => { new Int32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int32Array) => {
...@@ -174,69 +170,66 @@ export class TInt32Array { ...@@ -174,69 +170,66 @@ export class TInt32Array {
includes() { includes() {
// #TEST Int32Array.includes // #TEST Int32Array.includes
let int32 = new Int32Array([1, 2, 3]); let int32_t1 = new Int32Array([1, 2, 3]);
let res = int32.includes(2); let res1 = int32_t1.includes(2);
console.log(res); // true console.log(res1); // true
// expect(res).toEqual(true); let res2 = int32_t1.includes(4);
console.log(res2); // false
res = int32.includes(4); let res3 = int32_t1.includes(3, 3);
console.log(res); // false console.log(res3); // false
// expect(res).toEqual(false);
res = int32.includes(3, 3);
console.log(res); // false
// #END // #END
expect(res).toEqual(false);
expect(res1).toEqual(true);
expect(res2).toEqual(false);
expect(res3).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Int32Array.indexOf // #TEST Int32Array.indexOf
let int32 = new Int32Array([2, 5, 9]); let int32_t1 = new Int32Array([2, 5, 9]);
let res = int32.indexOf(2); let res1 = int32_t1.indexOf(2);
console.log(res); // 0 console.log(res1); // 0
// expect(res).toEqual(0);
res = int32.indexOf(7);
console.log(res); // -1
// expect(res).toEqual(-1);
res = int32.indexOf(9, 2); let res2 = int32_t1.indexOf(7);
console.log(res); // 2 console.log(res2); // -1
// expect(res).toEqual(2); let res3 = int32_t1.indexOf(9, 2);
console.log(res3); // 2
res = int32.indexOf(2, -1); let res4 = int32_t1.indexOf(2, -1);
console.log(res); // -1 console.log(res4); // -1
// expect(res).toEqual(-1); let res5 = int32_t1.indexOf(2, -3);
console.log(res5); // 0
res = int32.indexOf(2, -3);
console.log(res); // 0
// #END // #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() { join() {
// #TEST Int32Array.join // #TEST Int32Array.join
let int32 = new Int32Array([1, 2, 3]); let int32_t1 = new Int32Array([1, 2, 3]);
let res = int32.join(); let res1 = int32_t1.join();
console.log(res); // "1,2,3" console.log(res1); // "1,2,3"
// expect(res).toEqual("1,2,3"); let res2 = int32_t1.join(" / ");
console.log(res2); // "1 / 2 / 3"
res = int32.join(" / ");
console.log(res); // "1 / 2 / 3" let res3 = int32_t1.join("");
console.log(res3); // "123"
// expect(res).toEqual("1 / 2 / 3");
res = int32.join("");
console.log(res); // "123"
// #END // #END
expect(res).toEqual("123");
expect(res1).toEqual("1,2,3");
expect(res2).toEqual("1 / 2 / 3");
expect(res3).toEqual("123");
} }
keys() { keys() {
...@@ -262,33 +255,43 @@ export class TInt32Array { ...@@ -262,33 +255,43 @@ export class TInt32Array {
reduce() { reduce() {
// #TEST Int32Array.reduce // #TEST Int32Array.reduce
let total = new Int32Array([0, 1, 2, 3]); let total_t1 = new Int32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue); let res1 = total_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number =>
console.log(res); // 6 accumulator + currentValue
);
// expect(res).toEqual(6); console.log(res1); // 6
total = new Int32Array([0, 1, 2, 3]); let total_t2 = new Int32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8); let res2 = total_t2.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number =>
console.log(res); // 14 accumulator + currentValue, 8
);
console.log(res2); // 14
// #END // #END
expect(res).toEqual(14);
expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reduceRight() { reduceRight() {
// #TEST Int32Array.reduceRight // #TEST Int32Array.reduceRight
let total = new Int32Array([0, 1, 2, 3]); let total_t1 = new Int32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue); let res1 = total_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number =>
console.log(res); // 6 accumulator + currentValue
);
// expect(res).toEqual(6); console.log(res1); // 6
total = new Int32Array([0, 1, 2, 3]); let total_t2 = new Int32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8); let res2 = total_t2.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number =>
console.log(res); // 14 accumulator + currentValue, 8
);
console.log(res2); // 14
// #END // #END
expect(res).toEqual(14);
expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reverse() { reverse() {
// #TEST Int32Array.reverse // #TEST Int32Array.reverse
let int32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
...@@ -300,42 +303,43 @@ export class TInt32Array { ...@@ -300,42 +303,43 @@ export class TInt32Array {
slice() { slice() {
// #TEST Int32Array.slice // #TEST Int32Array.slice
let int32 = new Int32Array([1, 2, 3]); let int32_t1 = new Int32Array([1, 2, 3]);
let res = int32.slice(1); let res1 = int32_t1.slice(1);
console.log(res.toString()); // "2,3" console.log(res1.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3"); let res2 = int32_t1.slice(2);
console.log(res2.toString()); // "3"
res = int32.slice(2);
console.log(res.toString()); // "3" let res3 = int32_t1.slice(-2);
console.log(res3.toString()); // "2,3"
// expect(res.toString()).toEqual("3");
let res4 = int32_t1.slice(0, 1);
res = int32.slice(-2); console.log(res4.toString()); // "1"
console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = int32.slice(0, 1);
console.log(res.toString()); // "1"
// #END // #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() { sort() {
// #TEST Int32Array.sort // #TEST Int32Array.sort
let numbers = new Int32Array([40, 1, 5]); let numbers_t1 = new Int32Array([40, 1, 5]);
numbers.sort(); numbers_t1.sort();
console.log(numbers.toString()); // "1,5,40" console.log(numbers_t1.toString()); // "1,5,40"
// expect(numbers.toString()).toEqual("1,5,40"); let numbers_t2 = new Int32Array([40, 1, 5]);
numbers_t2.sort((a, b) : number => a - b);
numbers.sort((a, b) : number => a - b); console.log(numbers_t2.toString()); // "1,5,40"
console.log(numbers.toString()); // "1,5,40"
// #END // #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() { subarray() {
// #TEST Int32Array.subarray // #TEST Int32Array.subarray
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
...@@ -379,12 +383,13 @@ export class TInt32Array { ...@@ -379,12 +383,13 @@ export class TInt32Array {
const positives = new Int32Array([10, 20, 30, 40, 50]); const positives = new Int32Array([10, 20, 30, 40, 50]);
console.log(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // true 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 console.log(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // false
// #END // #END
expect(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(false); 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 // #endif
......
...@@ -88,24 +88,30 @@ export class TUint8Array { ...@@ -88,24 +88,30 @@ export class TUint8Array {
testFill() { testFill() {
// #TEST Uint8Array.fill // #TEST Uint8Array.fill
let uint8 = new Uint8Array([1, 2, 3]).fill(4); let uint8_t1 = new Uint8Array([1, 2, 3]).fill(4);
console.log(uint8.toString()); // "4,4,4" console.log(uint8_t1.toString()); // "4,4,4"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1); let uint8_t2 = new Uint8Array([1, 2, 3]).fill(4, 1);
console.log(uint8.toString()); // "1,4,4" console.log(uint8_t2.toString()); // "1,4,4"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 2); let uint8_t3 = new Uint8Array([1, 2, 3]).fill(4, 1, 2);
console.log(uint8.toString()); // "1,4,3" console.log(uint8_t3.toString()); // "1,4,3"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 1); let uint8_t4 = new Uint8Array([1, 2, 3]).fill(4, 1, 1);
console.log(uint8.toString()); // "1,2,3" console.log(uint8_t4.toString()); // "1,2,3"
uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2); let uint8_t5 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
console.log(uint8.toString()); // "4,2,3" console.log(uint8_t5.toString()); // "4,2,3"
// #END // #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() { testFilter() {
// #TEST Uint8Array.filter // #TEST Uint8Array.filter
let uint8 = new Uint8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint8Array) : boolean => value >= 10); let uint8 = new Uint8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint8Array) : boolean => value >= 10);
...@@ -122,20 +128,22 @@ export class TUint8Array { ...@@ -122,20 +128,22 @@ export class TUint8Array {
// #END // #END
expect(res).toEqual(8); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Uint8Array.findIndex // #TEST Uint8Array.findIndex
let uint8 = new Uint8Array([4, 6, 8, 12]); let uint8_t1 = new Uint8Array([4, 6, 8, 12]);
let res = uint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); let res1 = uint8_t1.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100);
console.log(res); // -1 console.log(res1); // -1
let uuint8 = new Uint8Array([4, 6, 7, 120]); let uint8_t2 = new Uint8Array([4, 6, 7, 120]);
res = uuint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); let res2 = uint8_t2.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100);
console.log(res); // 3 console.log(res2); // 3
// #END // #END
expect(res).toEqual(3);
expect(res1).toEqual(-1);
expect(res2).toEqual(3);
} }
foreach() { foreach() {
// #TEST Uint8Array.forEach // #TEST Uint8Array.forEach
new Uint8Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8Array) => { new Uint8Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8Array) => {
...@@ -155,68 +163,69 @@ export class TUint8Array { ...@@ -155,68 +163,69 @@ export class TUint8Array {
} }
includes() { includes() {
// #TEST Uint8Array.includes // #TEST Uint8Array.includes
let uint8 = new Uint8Array([1, 2, 3]); let uint8_t1 = new Uint8Array([1, 2, 3]);
let res = uint8.includes(2); let res1 = uint8_t1.includes(2);
console.log(res); // true console.log(res1); // true
res = uint8.includes(4); let res2 = uint8_t1.includes(4);
console.log(res); // false console.log(res2); // false
res = uint8.includes(3, 3); let res3 = uint8_t1.includes(3, 3);
console.log(res); // false console.log(res3); // false
// #END // #END
expect(res).toEqual(false);
expect(res1).toEqual(true);
expect(res2).toEqual(false);
expect(res3).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Uint8Array.indexOf // #TEST Uint8Array.indexOf
let uint8 = new Uint8Array([2, 5, 9]); let uint8_t1 = new Uint8Array([2, 5, 9]);
let res = uint8.indexOf(2); let res1 = uint8_t1.indexOf(2);
console.log(res); // 0 console.log(res1); // 0
// expect(res).toEqual(0);
res = uint8.indexOf(7);
console.log(res); // -1
// expect(res).toEqual(-1);
res = uint8.indexOf(9, 2); let res2 = uint8_t1.indexOf(7);
console.log(res); // 2 console.log(res2); // -1
// expect(res).toEqual(2); let res3 = uint8_t1.indexOf(9, 2);
console.log(res3); // 2
res = uint8.indexOf(2, -1); let res4 = uint8_t1.indexOf(2, -1);
console.log(res); // -1 console.log(res4); // -1
// expect(res).toEqual(-1); let res5 = uint8_t1.indexOf(2, -3);
console.log(res5); // 0
res = uint8.indexOf(2, -3);
console.log(res); // 0
// #END // #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() { join() {
// #TEST Uint8Array.join // #TEST Uint8Array.join
let uint8 = new Uint8Array([1, 2, 3]); let uint8_t1 = new Uint8Array([1, 2, 3]);
let res = uint8.join(); let res1 = uint8_t1.join();
console.log(res); // "1,2,3" console.log(res1); // "1,2,3"
// expect(res).toEqual("1,2,3");
res = uint8.join(" / "); let res2 = uint8_t1.join(" / ");
console.log(res); // "1 / 2 / 3" console.log(res2); // "1 / 2 / 3"
// expect(res).toEqual("1 / 2 / 3"); let res3 = uint8_t1.join("");
console.log(res3); // "123"
res = uint8.join("");
console.log(res); // "123"
// #END // #END
expect(res).toEqual("123");
expect(res1).toEqual("1,2,3");
expect(res2).toEqual("1 / 2 / 3");
expect(res3).toEqual("123");
} }
keys() { keys() {
// #TEST Uint8Array.keys // #TEST Uint8Array.keys
let arr = new Uint8Array([10, 20, 30, 40, 50]); let arr = new Uint8Array([10, 20, 30, 40, 50]);
...@@ -239,38 +248,37 @@ export class TUint8Array { ...@@ -239,38 +248,37 @@ export class TUint8Array {
} }
reduce() { reduce() {
// #TEST Uint8Array.reduce // #TEST Uint8Array.reduce
let total = new Uint8Array([0, 1, 2, 3]); let uint8_t1 = new Uint8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => let res1 = uint8_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue); accumulator + currentValue);
console.log(res); // 6 console.log(res1); // 6
// expect(res).toEqual(6); let res2 = uint8_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
console.log(res); // 14 console.log(res2); // 14
// #END // #END
expect(res).toEqual(14);
expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reduceRight() { reduceRight() {
// #TEST Uint8Array.reduceRight // #TEST Uint8Array.reduceRight
let total = new Uint8Array([0, 1, 2, 3]); let uint8_t1 = new Uint8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => let res1 = uint8_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue); accumulator + currentValue);
console.log(res); // 6 console.log(res1); // 6
// expect(res).toEqual(6); let res2 = uint8_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
console.log(res); // 14 console.log(res2); // 14
// #END // #END
expect(res).toEqual(14);
expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reverse() { reverse() {
// #TEST Uint8Array.reverse // #TEST Uint8Array.reverse
let uint8 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
...@@ -282,55 +290,56 @@ export class TUint8Array { ...@@ -282,55 +290,56 @@ export class TUint8Array {
slice() { slice() {
// #TEST Uint8Array.slice // #TEST Uint8Array.slice
let uint8 = new Uint8Array([1, 2, 3]); let uint8_t1 = new Uint8Array([1, 2, 3]);
let res = uint8.slice(1); let res1 = uint8_t1.slice(1);
console.log(res.toString()); // "2,3" console.log(res1.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = uint8.slice(2); let res2 = uint8_t1.slice(2);
console.log(res.toString()); // "3" 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); let res4 = uint8_t1.slice(0, 1);
console.log(res.toString()); // "2,3" console.log(res4.toString()); // "1"
// expect(res.toString()).toEqual("2,3");
res = uint8.slice(0, 1);
console.log(res.toString()); // "1"
// #END // #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() { sort() {
// #TEST Uint8Array.sort // #TEST Uint8Array.sort
let numbers = new Uint8Array([40, 1, 5]); let numbers_t1 = new Uint8Array([40, 1, 5]);
numbers.sort(); numbers_t1.sort();
console.log(numbers.toString()); // "1,5,40" console.log(numbers_t1.toString()); // "1,5,40"
// expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b); let numbers_t2 = new Uint8Array([40, 1, 5]);
console.log(numbers.toString()); // "1,5,40" numbers_t2.sort((a, b) : number => a - b);
console.log(numbers_t2.toString()); // "1,5,40"
// #END // #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() { subarray() {
// #TEST Uint8Array.subarray // #TEST Uint8Array.subarray
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer); let uint8_t1 = new Uint8Array(buffer);
uint8.set([1, 2, 3]); uint8_t1.set([1, 2, 3]);
console.log(uint8.toString()); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0" 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_t1 = uint8_t1.subarray(0, 4);
console.log(sub_t1.toString()); // "1,2,3,0"
let sub = uint8.subarray(0, 4);
console.log(sub.toString()); // "1,2,3,0"
// #END // #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() { values() {
...@@ -359,22 +368,24 @@ export class TUint8Array { ...@@ -359,22 +368,24 @@ export class TUint8Array {
testSome() { testSome() {
// #TEST Uint8Array.some // #TEST Uint8Array.some
const uint8 = new Uint8Array([8, 20, 30, 40, 50]); const uint8_t1 = new Uint8Array([8, 20, 30, 40, 50]);
const positives = new Uint8Array([10, 20, 30, 40, 50]); const positives_t1 = new Uint8Array([10, 20, 30, 40, 50]);
var res = uint8.some((element : number, index : number, array : Uint8Array) : boolean =>
let res_t1 = uint8_t1.some((element : number, index : number, array : Uint8Array) : boolean =>
element < 10 element < 10
); );
console.log('uint8', res); // true console.log('uint8_t1', res_t1); // true
// expect(res).toEqual(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 element < 0
); );
console.log('positives', res); // false console.log('positives_t1', res_t2); // false
// #END // #END
expect(res).toEqual(false); expect(res_t1).toEqual(true);
expect(res_t2).toEqual(false);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -84,25 +84,31 @@ export class TUint8ClampedArray { ...@@ -84,25 +84,31 @@ export class TUint8ClampedArray {
testFill() { testFill() {
// #TEST Uint8ClampedArray.fill // #TEST Uint8ClampedArray.fill
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4); let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]).fill(4);
console.log(uint8Clamped.toString()); // "4,4,4" console.log(uint8Clamped_t1.toString()); // "4,4,4"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1); let uint8Clamped_t2 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1);
console.log(uint8Clamped.toString()); // "1,4,4" console.log(uint8Clamped_t2.toString()); // "1,4,4"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2); let uint8Clamped_t3 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2);
console.log(uint8Clamped.toString()); // "1,4,3" console.log(uint8Clamped_t3.toString()); // "1,4,3"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1); let uint8Clamped_t4 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1);
console.log(uint8Clamped.toString()); // "1,2,3" 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 // #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() { testFilter() {
// #TEST Uint8ClampedArray.filter // #TEST Uint8ClampedArray.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
...@@ -125,17 +131,20 @@ export class TUint8ClampedArray { ...@@ -125,17 +131,20 @@ export class TUint8ClampedArray {
findIndex() { findIndex() {
// #TEST Uint8ClampedArray.findIndex // #TEST Uint8ClampedArray.findIndex
let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]); let uint8Clamped_t1 = new Uint8ClampedArray([4, 6, 8, 12]);
let res = uint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); let res1 = uint8Clamped_t1.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100);
console.log(res); // -1 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 // #END
expect(res).toEqual(3); expect(res1).toEqual(-1);
expect(res2).toEqual(3);
} }
foreach() { foreach() {
// #TEST Uint8ClampedArray.forEach // #TEST Uint8ClampedArray.forEach
new Uint8ClampedArray([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8ClampedArray) => { new Uint8ClampedArray([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8ClampedArray) => {
...@@ -156,53 +165,73 @@ export class TUint8ClampedArray { ...@@ -156,53 +165,73 @@ export class TUint8ClampedArray {
includes() { includes() {
// #TEST Uint8ClampedArray.includes // #TEST Uint8ClampedArray.includes
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.includes(2); let res1 = uint8Clamped_t1.includes(2);
console.log(res); // true console.log(res1); // true
res = uint8Clamped.includes(4); let uint8Clamped_t2 = new Uint8ClampedArray([1, 2, 3]);
console.log(res); // false 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 // #END
expect(res).toEqual(false); expect(res1).toEqual(true);
expect(res2).toEqual(false);
expect(res3).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Uint8ClampedArray.indexOf // #TEST Uint8ClampedArray.indexOf
let uint8Clamped = new Uint8ClampedArray([2, 5, 9]); let uint8Clamped_t1 = new Uint8ClampedArray([2, 5, 9]);
let res = uint8Clamped.indexOf(2); let res1 = uint8Clamped_t1.indexOf(2);
console.log(res); // 0 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); let uint8Clamped_t3 = new Uint8ClampedArray([2, 5, 9]);
console.log(res); // -1 let res3 = uint8Clamped_t3.indexOf(9, 2);
console.log(res3); // 2
res = uint8Clamped.indexOf(9, 2); let uint8Clamped_t4 = new Uint8ClampedArray([2, 5, 9]);
console.log(res); // 2 let res4 = uint8Clamped_t4.indexOf(2, -1);
console.log(res4); // -1
res = uint8Clamped.indexOf(2, -1); let uint8Clamped_t5 = new Uint8ClampedArray([2, 5, 9]);
console.log(res); // -1 let res5 = uint8Clamped_t5.indexOf(2, -3);
console.log(res5); // 0
res = uint8Clamped.indexOf(2, -3);
console.log(res); // 0
// #END // #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() { join() {
// #TEST Uint8ClampedArray.join // #TEST Uint8ClampedArray.join
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.join(); let res1 = uint8Clamped_t1.join();
console.log(res); // "1,2,3" console.log(res1); // "1,2,3"
res = uint8Clamped.join(" / "); let uint8Clamped_t2 = new Uint8ClampedArray([1, 2, 3]);
console.log(res); // "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 // #END
expect(res).toEqual("123"); expect(res1).toEqual("1,2,3");
expect(res2).toEqual("1 / 2 / 3");
expect(res3).toEqual("123");
} }
keys() { keys() {
...@@ -227,32 +256,36 @@ export class TUint8ClampedArray { ...@@ -227,32 +256,36 @@ export class TUint8ClampedArray {
reduce() { reduce() {
// #TEST Uint8ClampedArray.reduce // #TEST Uint8ClampedArray.reduce
let total = new Uint8ClampedArray([0, 1, 2, 3]); let total_t1 = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => let res1 = total_t1.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue); accumulator + currentValue);
console.log(res); // 6 console.log(res1); // 6
total = new Uint8ClampedArray([0, 1, 2, 3]); let total_t2 = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => let res2 = total_t2.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
console.log(res); // 14 console.log(res2); // 14
// #END // #END
expect(res).toEqual(14); expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reduceRight() { reduceRight() {
// #TEST Uint8ClampedArray.reduceRight // #TEST Uint8ClampedArray.reduceRight
let total = new Uint8ClampedArray([0, 1, 2, 3]); let total_t1 = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => let res1 = total_t1.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue); accumulator + currentValue);
console.log(res); // 6 console.log(res1); // 6
total = new Uint8ClampedArray([0, 1, 2, 3]); let total_t2 = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => let res2 = total_t2.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
console.log(res); // 14 console.log(res2); // 14
// #END // #END
expect(res).toEqual(14); expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
...@@ -267,47 +300,54 @@ export class TUint8ClampedArray { ...@@ -267,47 +300,54 @@ export class TUint8ClampedArray {
slice() { slice() {
// #TEST Uint8ClampedArray.slice // #TEST Uint8ClampedArray.slice
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped_t1 = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.slice(1); let res1 = uint8Clamped_t1.slice(1);
console.log(res.toString()); // "2,3" console.log(res1.toString()); // "2,3"
res = uint8Clamped.slice(2); let res2 = uint8Clamped_t1.slice(2);
console.log(res.toString()); // "3" console.log(res2.toString()); // "3"
res = uint8Clamped.slice(-2); let res3 = uint8Clamped_t1.slice(-2);
console.log(res.toString()); // "2,3" console.log(res3.toString()); // "2,3"
res = uint8Clamped.slice(0, 1); let res4 = uint8Clamped_t1.slice(0, 1);
console.log(res.toString()); // "1" console.log(res4.toString()); // "1"
// #END // #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() { sort() {
// #TEST Uint8ClampedArray.sort // #TEST Uint8ClampedArray.sort
let numbers = new Uint8ClampedArray([40, 1, 5]); let uint8Clamped_t1 = new Uint8ClampedArray([40, 1, 5]);
numbers.sort(); uint8Clamped_t1.sort();
console.log(numbers.toString()); // "1,5,40" let res1 = uint8Clamped_t1.toString();
console.log(res1); // "1,5,40"
numbers.sort((a, b) : number => a - b);
console.log(numbers.toString()); // "1,5,40" uint8Clamped_t1.sort((a, b) : number => a - b);
let res2 = uint8Clamped_t1.toString();
console.log(res2); // "1,5,40"
// #END // #END
expect(numbers.toString()).toEqual("1,5,40"); expect(res1).toEqual("1,5,40");
expect(res2).toEqual("1,5,40");
} }
subarray() { subarray() {
// #TEST Uint8ClampedArray.subarray // #TEST Uint8ClampedArray.subarray
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer); let uint8Clamped_t1 = new Uint8ClampedArray(buffer);
uint8Clamped.set([1, 2, 3]); uint8Clamped_t1.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 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.subarray(0, 4);
console.log(sub.toString()); // "1,2,3,0" let sub = uint8Clamped_t1.subarray(0, 4);
let res2 = sub.toString();
console.log(res2); // "1,2,3,0"
// #END // #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");
} }
......
...@@ -372,24 +372,32 @@ export class TUint16Array { ...@@ -372,24 +372,32 @@ export class TUint16Array {
let res = buffer.slice(8); let res = buffer.slice(8);
let sliced = new Uint16Array(res); let sliced = new Uint16Array(res);
console.log(sliced[0]); // 42 console.log(sliced[0]); // 42
// #END // #END
expect(uint16.toString()).toEqual("0,0,0,0,42,0,0,0");
expect(sliced[0]).toEqual(42); expect(sliced[0]).toEqual(42);
} }
testSome() { testSome() {
// #TEST Uint16Array.some // #TEST Uint16Array.some
const uint16 = new Uint16Array([8, 20, 30, 40, 50]); const uint16 = new Uint16Array([8, 20, 30, 40, 50]);
const positives = new Uint16Array([10, 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 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 element < 0
)).toEqual(false); );
console.log('positives', res2); // false
// #END // #END
expect(res1).toEqual(true);
expect(res2).toEqual(false);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -75,15 +75,14 @@ export class TUint32Array { ...@@ -75,15 +75,14 @@ export class TUint32Array {
testCopyWith() { testCopyWith() {
// #TEST Uint32Array.copyWithin // #TEST Uint32Array.copyWithin
console.log("testCopyWith 1");
let uint32 = new Uint32Array(8); let uint32 = new Uint32Array(8);
uint32.set([1, 2, 3], 1); uint32.set([1, 2, 3], 1);
console.log("testCopyWith 2");
uint32.copyWithin(3, 0, 3); uint32.copyWithin(3, 0, 3);
console.log("testCopyWith 3"); let result2 = uint32.toString();
console.log(uint32.toString()); // "0,1,2,0,1,2,0,0" console.log(result2); // "0,1,2,0,1,2,0,0"
// #END // #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() { testEvery() {
...@@ -93,21 +92,34 @@ export class TUint32Array { ...@@ -93,21 +92,34 @@ export class TUint32Array {
// #END // #END
expect(result).toEqual(false); expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Uint32Array.fill // #TEST Uint32Array.fill
let uint32 = new Uint32Array([1, 2, 3]).fill(4); 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); 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); 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); 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); 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 // #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 { ...@@ -131,14 +143,19 @@ export class TUint32Array {
findIndex() { findIndex() {
// #TEST Uint32Array.findIndex // #TEST Uint32Array.findIndex
let uint32 = new Uint32Array([4, 6, 8, 12]); let uint32 = new Uint32Array([4, 6, 8, 12]);
let res = uint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
console.log(res); // -1 let res1 = uint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
res = new Uint32Array([4, 6, 7, 120]).findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100); console.log(res1); // -1
console.log(res); // 3
let res2 = new Uint32Array([4, 6, 7, 120]).findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
console.log(res2); // 3
// #END // #END
expect(res).toEqual(3); expect(res1).toEqual(-1);
expect(res2).toEqual(3);
} }
foreach() { foreach() {
// #TEST Uint32Array.forEach // #TEST Uint32Array.forEach
new Uint32Array([0, 1, 2, 3]).forEach((value : number, index : number, _a : Uint32Array) => { new Uint32Array([0, 1, 2, 3]).forEach((value : number, index : number, _a : Uint32Array) => {
...@@ -160,47 +177,70 @@ export class TUint32Array { ...@@ -160,47 +177,70 @@ export class TUint32Array {
includes() { includes() {
// #TEST Uint32Array.includes // #TEST Uint32Array.includes
let uint32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.includes(2);
console.log(res); // true let res1 = uint32.includes(2);
res = uint32.includes(4); console.log(res1); // true
console.log(res); // false
res = uint32.includes(3, 3); let res2 = uint32.includes(4);
console.log(res); // false console.log(res2); // false
let res3 = uint32.includes(3, 3);
console.log(res3); // false
// #END // #END
expect(res).toEqual(false); expect(res1).toEqual(true);
expect(res2).toEqual(false);
expect(res3).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Uint32Array.indexOf // #TEST Uint32Array.indexOf
let uint32 = new Uint32Array([2, 5, 9]); let uint32 = new Uint32Array([2, 5, 9]);
let res = uint32.indexOf(2);
console.log(res); // 0 let res1 = uint32.indexOf(2);
res = uint32.indexOf(7); console.log(res1); // 0
console.log(res); // -1
res = uint32.indexOf(9, 2); let res2 = uint32.indexOf(7);
console.log(res); // 2 console.log(res2); // -1
res = uint32.indexOf(2, -1);
console.log(res); // -1 let res3 = uint32.indexOf(9, 2);
res = uint32.indexOf(2, -3); console.log(res3); // 2
console.log(res); // 0
let res4 = uint32.indexOf(2, -1);
console.log(res4); // -1
let res5 = uint32.indexOf(2, -3);
console.log(res5); // 0
// #END // #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() { join() {
// #TEST Uint32Array.join // #TEST Uint32Array.join
let uint32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.join();
console.log(res); // "1,2,3" let res1 = uint32.join();
res = uint32.join(" / "); console.log(res1); // "1,2,3"
console.log(res); // "1 / 2 / 3"
res = uint32.join(""); let res2 = uint32.join(" / ");
console.log(res); // "123" console.log(res2); // "1 / 2 / 3"
let res3 = uint32.join("");
console.log(res3); // "123"
// #END // #END
expect(res).toEqual("123"); expect(res1).toEqual("1,2,3");
expect(res2).toEqual("1 / 2 / 3");
expect(res3).toEqual("123");
} }
keys() { keys() {
// #TEST Uint32Array.keys // #TEST Uint32Array.keys
let arr = new Uint32Array([10, 20, 30, 40, 50]); let arr = new Uint32Array([10, 20, 30, 40, 50]);
...@@ -225,25 +265,33 @@ export class TUint32Array { ...@@ -225,25 +265,33 @@ export class TUint32Array {
reduce() { reduce() {
// #TEST Uint32Array.reduce // #TEST Uint32Array.reduce
let total = new Uint32Array([0, 1, 2, 3]); 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]); total = new Uint32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8); let res2 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8);
console.log(res); // 14 console.log(res2); // 14
// #END // #END
expect(res).toEqual(14); expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reduceRight() { reduceRight() {
// #TEST Uint32Array.reduceRight // #TEST Uint32Array.reduceRight
let total = new Uint32Array([0, 1, 2, 3]); 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]); total = new Uint32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8); let res2 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8);
console.log(res); // 14 console.log(res2); // 14
// #END // #END
expect(res).toEqual(14); expect(res1).toEqual(6);
expect(res2).toEqual(14);
} }
reverse() { reverse() {
...@@ -259,48 +307,62 @@ export class TUint32Array { ...@@ -259,48 +307,62 @@ export class TUint32Array {
slice() { slice() {
// #TEST Uint32Array.slice // #TEST Uint32Array.slice
let uint32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.slice(1);
console.log(res.toString()); // "2,3"
res = uint32.slice(2); let res1 = uint32.slice(1);
console.log(res.toString()); // "3" 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); let res3 = uint32.slice(-2);
console.log(res.toString()); // "2,3" 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 // #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() { sort() {
// #TEST Uint32Array.sort // #TEST Uint32Array.sort
let numbers = new Uint32Array([40, 1, 5]); let numbers = new Uint32Array([40, 1, 5]);
numbers.sort(); let numbersString = numbers.toString();
console.log(numbers.toString()); // "1,5,40" console.log(numbersString); // "1,5,40"
numbers.sort((a, b) : number => a - b); 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 // #END
expect(numbers.toString()).toEqual("1,5,40"); expect(numbersString).toEqual("40,1,5");
expect(sortedString).toEqual("1,5,40");
} }
subarray() { subarray() {
// #TEST Uint32Array.subarray // #TEST Uint32Array.subarray
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer); let uint32 = new Uint32Array(buffer);
uint32.set([1, 2, 3]); 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); 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 // #END
expect(sub.toString()).toEqual("1,2,3,0"); expect(uint32String).toEqual("1,2,3,0");
expect(subString).toEqual("1,2,3,0");
} }
values() { values() {
// #TEST Uint32Array.values // #TEST Uint32Array.values
let arr = new Uint32Array([1, 2, 3]); let arr = new Uint32Array([1, 2, 3]);
...@@ -310,7 +372,6 @@ export class TUint32Array { ...@@ -310,7 +372,6 @@ export class TUint32Array {
// #END // #END
expect(value).toEqual(1); expect(value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
...@@ -322,6 +383,7 @@ export class TUint32Array { ...@@ -322,6 +383,7 @@ export class TUint32Array {
let sliced = new Uint32Array(res); let sliced = new Uint32Array(res);
console.log(sliced[1]); // 42 console.log(sliced[1]); // 42
// #END // #END
expect(uint32.toString()).toEqual("0,0,0,42");
expect(sliced[1]).toEqual(42); expect(sliced[1]).toEqual(42);
} }
...@@ -331,17 +393,18 @@ export class TUint32Array { ...@@ -331,17 +393,18 @@ export class TUint32Array {
const uint32 = new Uint32Array([8, 20, 30, 40, 50]); const uint32 = new Uint32Array([8, 20, 30, 40, 50]);
const positives = new Uint32Array([10, 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 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 element < 0
); );
console.log(result); // false console.log(result2); // false
// #END // #END
expect(result).toEqual(false); expect(result1).toEqual(true);
expect(result2).toEqual(false);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册