提交 0c883eb7 编写于 作者: M mahaifeng

[array-buffer]添加console

上级 78314af2
...@@ -66,8 +66,9 @@ export class TFloat64Array { ...@@ -66,8 +66,9 @@ export class TFloat64Array {
let float64 = new Float64Array(8); let float64 = new Float64Array(8);
var array = [1, 2, 3]; var array = [1, 2, 3];
float64.set(array, 1); float64.set(array, 1);
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(float64.toString()); // 0,1,2,3,0,0,0,0
// #END // #END
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
...@@ -75,61 +76,74 @@ export class TFloat64Array { ...@@ -75,61 +76,74 @@ export class TFloat64Array {
let float64 = new Float64Array(8); let float64 = new Float64Array(8);
float64.set([1, 2, 3], 1); float64.set([1, 2, 3], 1);
float64.copyWithin(3, 0, 3); float64.copyWithin(3, 0, 3);
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0"); console.log(float64.toString()); // 0,1,2,0,1,2,0,0
// #END // #END
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Float64Array.every // #TEST Float64Array.every
let result = new Float64Array([-10, -20, -30, -40, -50]).every((value : number, _ : number, _a : Float64Array) : boolean => value < 0); let result = new Float64Array([-10, -20, -30, -40, -50]).every((value : number, _ : number, _a : Float64Array) : boolean => value < 0);
expect(result).toEqual(true); console.log(result); // true
// #END // #END
expect(result).toEqual(true);
} }
testFill() { testFill() {
// #TEST Float64Array.fill // #TEST Float64Array.fill
let float64 = new Float64Array([1, 2, 3]).fill(4); let float64_t1 = new Float64Array([1, 2, 3]).fill(4);
expect(float64.toString()).toEqual("4,4,4"); console.log(float64_t1.toString()); // 4,4,4
float64 = new Float64Array([1, 2, 3]).fill(4, 1); let float64_t2 = new Float64Array([1, 2, 3]).fill(4, 1);
expect(float64.toString()).toEqual("1,4,4"); console.log(float64_t2.toString()); // 1,4,4
float64 = new Float64Array([1, 2, 3]).fill(4, 1, 2); let float64_t3 = new Float64Array([1, 2, 3]).fill(4, 1, 2);
expect(float64.toString()).toEqual("1,4,3"); console.log(float64_t3.toString()); // 1,4,3
float64 = new Float64Array([1, 2, 3]).fill(4, 1, 1); let float64_t4 = new Float64Array([1, 2, 3]).fill(4, 1, 1);
expect(float64.toString()).toEqual("1,2,3"); console.log(float64_t4.toString()); // 1,2,3
float64 = new Float64Array([1, 2, 3]).fill(4, -3, -2); let float64_t5 = new Float64Array([1, 2, 3]).fill(4, -3, -2);
expect(float64.toString()).toEqual("4,2,3"); console.log(float64_t5.toString()); // 4,2,3
// #END // #END
expect(float64_t4.toString()).toEqual("1,2,3");
expect(float64_t3.toString()).toEqual("1,4,3");
expect(float64_t2.toString()).toEqual("1,4,4");
expect(float64_t1.toString()).toEqual("4,4,4");
expect(float64_t5.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// #TEST Float64Array.filter // #TEST Float64Array.filter
let float64 = new Float64Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float64Array) : boolean => value >= 10); let float64 = new Float64Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float64Array) : boolean => value >= 10);
expect(float64.toString()).toEqual("12,44"); console.log(float64.toString()); // 12,44
// #END // #END
expect(float64.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Float64Array.find // #TEST Float64Array.find
let float64 = new Float64Array([4, 5, 8, 12]); let float64 = new Float64Array([4, 5, 8, 12]);
let res = float64.find((value : number, _ : number, _a : Float64Array) : boolean => value > 5); let res = float64.find((value : number, _ : number, _a : Float64Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Float64Array.findIndex // #TEST Float64Array.findIndex
let float64 = new Float64Array([4, 6, 8, 12]); let float64 = new Float64Array([4, 6, 8, 12]);
let res = float64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100); let res = float64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
let ufloat64 = new Float64Array([4, 6, 7, 120]); let ufloat64 = new Float64Array([4, 6, 7, 120]);
res = ufloat64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100); res = ufloat64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100);
expect(res).toEqual(3); console.log(res); // 3
// #END // #END
expect(res).toEqual(3);
expect(float64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100)).toEqual(-1);
} }
...@@ -145,129 +159,162 @@ export class TFloat64Array { ...@@ -145,129 +159,162 @@ export class TFloat64Array {
// #TEST Float64Array.entries // #TEST Float64Array.entries
let arr = new Float64Array([10, 20, 30, 40, 50]); let arr = new Float64Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); console.log(entries.next().value[1]); // 10
expect(entries.next().value[1]).toEqual(20); console.log(entries.next().value[1]); // 20
// #END // #END
expect(entries.next().value[1]).toEqual(30);
expect(entries.next().value[1]).toEqual(40);
} }
includes() { includes() {
// #TEST Float64Array.includes // #TEST Float64Array.includes
let float64 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
let res = float64.includes(2); let res = float64.includes(2);
expect(res).toEqual(true); console.log(res); // true
res = float64.includes(4); res = float64.includes(4);
expect(res).toEqual(false); console.log(res); // false
res = float64.includes(3, 3); res = float64.includes(3, 3);
expect(res).toEqual(false); console.log(res); // false
// #END // #END
expect(res).toEqual(false);
expect(float64.includes(4)).toEqual(false);
expect(float64.includes(2)).toEqual(true);
} }
indexOf() { indexOf() {
// #TEST Float64Array.indexOf // #TEST Float64Array.indexOf
let float64 = new Float64Array([2, 5, 9]); let float64 = new Float64Array([2, 5, 9]);
let res = float64.indexOf(2); let res = float64.indexOf(2);
expect(res).toEqual(0); console.log(res); // 0
res = float64.indexOf(7);
expect(res).toEqual(-1);
res = float64.indexOf(9, 2); let res1 = float64.indexOf(7);
expect(res).toEqual(2); console.log(res1); // -1
res = float64.indexOf(2, -1); let res2 = float64.indexOf(9, 2);
expect(res).toEqual(-1); console.log(res2); // 2
res = float64.indexOf(2, -3);
expect(res).toEqual(0); let res3 = float64.indexOf(2, -1);
console.log(res3); // -1
let res4 = float64.indexOf(2, -3);
console.log(res); // 0
// #END // #END
expect(res).toEqual(0);
expect(res).toEqual(0);
expect(res1).toEqual(-1);
expect(res2).toEqual(2);
expect(res3).toEqual(-1);
} }
join() { join() {
// #TEST Float64Array.join // #TEST Float64Array.join
let float64 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
let res = float64.join(); let res = float64.join();
expect(res).toEqual("1,2,3"); console.log(res); // 1,2,3
res = float64.join(" / ");
expect(res).toEqual("1 / 2 / 3");
res = float64.join(""); let res1 = float64.join(" / ");
expect(res).toEqual("123"); console.log(res1); // 1 / 2 / 3
let res2 = float64.join("");
console.log(res2); // 123
// #END // #END
expect(res2).toEqual("123");
expect(res).toEqual("1,2,3");
expect(res1).toEqual("1 / 2 / 3");
} }
keys() { keys() {
// #TEST Float64Array.keys // #TEST Float64Array.keys
let arr = new Float64Array([10, 20, 30, 40, 50]); let arr = new Float64Array([10, 20, 30, 40, 50]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); console.log(keys.next().value); // 0
expect(keys.next().value).toEqual(1); console.log(keys.next().value); // 1
expect(keys.next().value).toEqual(2); console.log(keys.next().value); // 2
expect(keys.next().value).toEqual(3); console.log(keys.next().value); // 3
expect(keys.next().value).toEqual(4); console.log(keys.next().value); // 4
// #END // #END
expect(keys.next().value).toEqual(-1);
} }
map() { map() {
// #TEST Float64Array.map // #TEST Float64Array.map
let numbers = new Float64Array([1, 4, 9]); let numbers = new Float64Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Float64Array) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Float64Array) : number => value * 2);
console.log(numbers.toString()); // 1,4,9
console.log(doubles.toString()); // 2,8,18
// #END
expect(numbers.toString()).toEqual("1,4,9"); expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18"); expect(doubles.toString()).toEqual("2,8,18");
// #END
} }
reduce() { reduce() {
// #TEST Float64Array.reduce // #TEST Float64Array.reduce
let total = new Float64Array([0, 1, 2, 3]); let total = new Float64Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue); let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
total = new Float64Array([0, 1, 2, 3]); total = new Float64Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8); let res1 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res1); // 14
// #END // #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
} }
reduceRight() { reduceRight() {
// #TEST Float64Array.reduceRight // #TEST Float64Array.reduceRight
let total = new Float64Array([0, 1, 2, 3]); let total = new Float64Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue); let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
total = new Float64Array([0, 1, 2, 3]); total = new Float64Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8); let res1 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res1); // 14
// #END // #END
expect(res).toEqual(6);
expect(res1).toEqual(14);
} }
reverse() { reverse() {
// #TEST Float64Array.reverse // #TEST Float64Array.reverse
let float64 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
float64.reverse(); float64.reverse();
expect(float64.toString()).toEqual("3,2,1"); console.log(float64.toString()); // 3,2,1
// #END // #END
expect(float64.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Float64Array.slice // #TEST Float64Array.slice
let float64 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
let res = float64.slice(1); let res = float64.slice(1);
expect(res.toString()).toEqual("2,3"); let ret1 = res.toString()
console.log(ret1); // 2,3
res = float64.slice(2); res = float64.slice(2);
expect(res.toString()).toEqual("3"); let ret2 = res.toString()
console.log(ret2); // 3
res = float64.slice(-2); res = float64.slice(-2);
expect(res.toString()).toEqual("2,3"); let ret3 = res.toString()
console.log(ret3); // 2,3
res = float64.slice(0, 1); res = float64.slice(0, 1);
expect(res.toString()).toEqual("1"); let ret4 = res.toString()
console.log(ret4); // 1
const size = 1000; const size = 1000;
const initialFloat64Array = new Float64Array(size); const initialFloat64Array = new Float64Array(size);
...@@ -279,36 +326,46 @@ export class TFloat64Array { ...@@ -279,36 +326,46 @@ export class TFloat64Array {
let new_arr : Float64Array; let new_arr : Float64Array;
arr = new Float64Array(initialFloat64Array); arr = new Float64Array(initialFloat64Array);
new_arr = arr.slice(1, -1); new_arr = arr.slice(1, -1);
let ret5 = true
for (let i = 1; i < size - 1; ++i) { for (let i = 1; i < size - 1; ++i) {
if (arr[i] !== new_arr[i - 1]) { if (arr[i] !== new_arr[i - 1]) {
expect(true).toEqual(false); ret5 = false
break break;
} }
} }
console.log(ret5); // true;
// #END // #END
expect(ret4).toEqual("1");
expect(ret3.toString()).toEqual("2,3");
expect(ret2).toEqual("3");
expect(ret1.toString()).toEqual("2,3");
expect(true).toEqual(ret5);
} }
sort() { sort() {
// #TEST Float64Array.sort // #TEST Float64Array.sort
let numbers = new Float64Array([40, 1, 5]); let numbers = new Float64Array([40, 1, 5]);
numbers.sort(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); let ret = numbers.toString()
console.log(ret); // 1,5,40
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // 1,5,40
// #END // #END
expect(ret).toEqual("1,5,40");
expect(numbers.toString()).toEqual("1,5,40");
} }
subarray() { subarray() {
// #TEST Float64Array.subarray // #TEST Float64Array.subarray
let buffer = new ArrayBuffer(32); let buffer = new ArrayBuffer(32);
let float64 = new Float64Array(buffer); let float64 = new Float64Array(buffer);
float64.set([1, 2, 3]); float64.set([1, 2, 3]);
expect(float64.toString()).toEqual("1,2,3,0"); console.log(float64.toString()); // 1,2,3,0
let sub = float64.subarray(0, 4); let sub = float64.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // 1,2,3,0
const size = 1000; const size = 1000;
const initialFloat64Array = new Float64Array(size); const initialFloat64Array = new Float64Array(size);
...@@ -317,52 +374,63 @@ export class TFloat64Array { ...@@ -317,52 +374,63 @@ export class TFloat64Array {
} }
let arr = new Float64Array(initialFloat64Array); let arr = new Float64Array(initialFloat64Array);
let new_arr = arr.subarray(1, size - 1); let new_arr = arr.subarray(1, size - 1);
let ret = true
for (let i = 1; i < size - 1; ++i) { for (let i = 1; i < size - 1; ++i) {
if (arr[i] !== new_arr[i - 1]) { if (arr[i] !== new_arr[i - 1]) {
expect(true).toEqual(false); ret = false
break
} }
} }
// #END // #END
expect(true).toEqual(ret);
} }
values() { values() {
// #TEST Float64Array.values // #TEST Float64Array.values
let arr = new Float64Array([1, 2, 3]); let arr = new Float64Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); console.log(values.next().value); // 1
expect(values.next().value).toEqual(2); console.log(values.next().value); // 2
expect(values.next().value).toEqual(3); console.log(values.next().value); // 3
// #END // #END
expect(values.next().value).toEqual(-1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float64 = new Float64Array(buffer); let float64 = new Float64Array(buffer);
float64[1] = 42; float64[1] = 42;
expect(float64.toString()).toEqual("0,42"); console.log(float64.toString()); // 0,42
let res = buffer.slice(8); let res = buffer.slice(8);
let sliced = new Float64Array(res); let sliced = new Float64Array(res);
expect(sliced[0]).toEqual(42); console.log(sliced[0]); // 42
// #END // #END
expect(sliced[0]).toEqual(42);
} }
testSome() { testSome() {
// #TEST Float64Array.some // #TEST Float64Array.some
const float64 = new Float64Array([-10, 20, -30, 40, -50]); const float64 = new Float64Array([-10, 20, -30, 40, -50]);
const positives = new Float64Array([10, 20, 30, 40, 50]); const positives = new Float64Array([10, 20, 30, 40, 50]);
console.log(float64.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0
)); // true
console.log(positives.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0
)); // false
// #END
expect(float64.some((element : number, index : number, array : Float64Array) : boolean => expect(float64.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0 element < 0
)).toEqual(true); )).toEqual(true);
expect(positives.some((element : number, index : number, array : Float64Array) : boolean => expect(positives.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0 element < 0
)).toEqual(false); )).toEqual(false);
// #END
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -48,8 +48,9 @@ export class TInt16Array { ...@@ -48,8 +48,9 @@ export class TInt16Array {
let int16 = new Int16Array(8); let int16 = new Int16Array(8);
var array = [1, 2, 3]; var array = [1, 2, 3];
int16.set(array, 1); int16.set(array, 1);
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(int16.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
...@@ -57,61 +58,77 @@ export class TInt16Array { ...@@ -57,61 +58,77 @@ export class TInt16Array {
let int16 = new Int16Array(8); let int16 = new Int16Array(8);
int16.set([1, 2, 3], 1); int16.set([1, 2, 3], 1);
int16.copyWithin(3, 0, 3); int16.copyWithin(3, 0, 3);
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0"); console.log(int16.toString()); // "0,1,2,0,1,2,0,0"
// #END // #END
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Int16Array.every // #TEST Int16Array.every
let result = new Int16Array([12, 5, 8, 130, 44]).every((value, _, _a : Int16Array) : boolean => value < 40); let result = new Int16Array([12, 5, 8, 130, 44]).every((value, _, _a : Int16Array) : boolean => value < 40);
expect(result).toEqual(false); console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Int16Array.fill // #TEST Int16Array.fill
let int16 = new Int16Array([1, 2, 3]).fill(4); let int16 = new Int16Array([1, 2, 3]).fill(4);
expect(int16.toString()).toEqual("4,4,4"); console.log(int16.toString()); // "4,4,4"
// expect(int16.toString()).toEqual("4,4,4");
int16 = new Int16Array([1, 2, 3]).fill(4, 1); int16 = new Int16Array([1, 2, 3]).fill(4, 1);
expect(int16.toString()).toEqual("1,4,4"); console.log(int16.toString()); // "1,4,4"
// expect(int16.toString()).toEqual("1,4,4");
int16 = new Int16Array([1, 2, 3]).fill(4, 1, 2); int16 = new Int16Array([1, 2, 3]).fill(4, 1, 2);
expect(int16.toString()).toEqual("1,4,3"); console.log(int16.toString()); // "1,4,3"
// expect(int16.toString()).toEqual("1,4,3");
int16 = new Int16Array([1, 2, 3]).fill(4, 1, 1); int16 = new Int16Array([1, 2, 3]).fill(4, 1, 1);
expect(int16.toString()).toEqual("1,2,3"); console.log(int16.toString()); // "1,2,3"
// expect(int16.toString()).toEqual("1,2,3");
int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2); int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
expect(int16.toString()).toEqual("4,2,3"); console.log(int16.toString()); // "4,2,3"
// #END // #END
expect(int16.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);
expect(int16.toString()).toEqual("12,44"); console.log(int16.toString()); // "12,44"
// #END // #END
expect(int16.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Int16Array.find // #TEST Int16Array.find
let int16 = new Int16Array([4, 5, 8, 12]); let int16 = new Int16Array([4, 5, 8, 12]);
let res = int16.find((value, _, _a : Int16Array) : boolean => value > 5); let res = int16.find((value, _, _a : Int16Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Int16Array.findIndex // #TEST Int16Array.findIndex
let int16 = new Int16Array([4, 6, 8, 12]); let int16 = new Int16Array([4, 6, 8, 12]);
let res = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100); let res = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
int16 = new Int16Array([4, 6, 7, 120]); int16 = new Int16Array([4, 6, 7, 120]);
res = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100); let res1 = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100);
expect(res).toEqual(3); console.log(res1); // 3
// #END // #END
expect(res1).toEqual(3);
expect(res).toEqual(-1);
} }
foreach() { foreach() {
...@@ -126,137 +143,184 @@ export class TInt16Array { ...@@ -126,137 +143,184 @@ export class TInt16Array {
// #TEST Int16Array.entries // #TEST Int16Array.entries
let arr = new Int16Array([10, 20, 30, 40, 50]); let arr = new Int16Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let firstEntry = entries.next().value[1];
console.log(firstEntry); // 10
// #END // #END
expect(firstEntry).toEqual(10);
} }
includes() { includes() {
// #TEST Int16Array.includes // #TEST Int16Array.includes
let int16 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
let res = int16.includes(2); let res = int16.includes(2);
expect(res).toEqual(true); console.log(res); // true
res = int16.includes(4); let res1 = int16.includes(4);
expect(res).toEqual(false); console.log(res1); // false
res = int16.includes(3, 3);
expect(res).toEqual(false); let res2 = int16.includes(3, 3);
console.log(res2); // false
// #END // #END
expect(res2).toEqual(false);
expect(res).toEqual(true);
expect(res1).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Int16Array.indexOf // #TEST Int16Array.indexOf
let int16 = new Int16Array([2, 5, 9]); let int16 = new Int16Array([2, 5, 9]);
let res = int16.indexOf(2); let res = int16.indexOf(2);
expect(res).toEqual(0); console.log(res); // 0
res = int16.indexOf(7);
expect(res).toEqual(-1);
res = int16.indexOf(9, 2); let res1 = int16.indexOf(7);
expect(res).toEqual(2); console.log(res1); // -1
res = int16.indexOf(2, -1);
expect(res).toEqual(-1);
res = int16.indexOf(2, -3); let res2 = int16.indexOf(9, 2);
expect(res).toEqual(0); console.log(res2); // 2
let res3 = int16.indexOf(2, -1);
console.log(res3); // -1
let res4 = int16.indexOf(2, -3);
console.log(res4); // 0
// #END // #END
expect(res4).toEqual(0);
expect(res).toEqual(0);
expect(res1).toEqual(-1);
expect(res2).toEqual(2);
expect(res3).toEqual(-1);
} }
join() { join() {
// #TEST Int16Array.join // #TEST Int16Array.join
let int16 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
let res = int16.join(); let res = int16.join();
expect(res).toEqual("1,2,3"); console.log(res); // "1,2,3"
res = int16.join(" / "); let res1 = int16.join(" / ");
expect(res).toEqual("1 / 2 / 3"); console.log(res1); // "1 / 2 / 3"
res = int16.join(""); let res2 = int16.join("");
expect(res).toEqual("123"); console.log(res2); // "123"
// #END // #END
expect(res2).toEqual("123");
expect(res).toEqual("1,2,3");
expect(res1).toEqual("1 / 2 / 3");
} }
keys() { keys() {
// #TEST Int16Array.keys // #TEST Int16Array.keys
let arr = new Int16Array([10, 20, 30, 40, 50]); let arr = new Int16Array([10, 20, 30, 40, 50]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let value1 = keys.next().value
expect(keys.next().value).toEqual(1); console.log(value1); // 0
expect(keys.next().value).toEqual(2); console.log(keys.next().value); // 1
expect(keys.next().value).toEqual(3); console.log(keys.next().value); // 2
expect(keys.next().value).toEqual(4); console.log(keys.next().value); // 3
console.log(keys.next().value); // 4
// #END // #END
expect(value1).toEqual(0);
} }
map() { map() {
// #TEST Int16Array.map // #TEST Int16Array.map
let numbers = new Int16Array([1, 4, 9]); let numbers = new Int16Array([1, 4, 9]);
let doubles = numbers.map((value, _, _a : Int16Array) : number => value * 2); let doubles = numbers.map((value, _, _a : Int16Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9"); expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18"); expect(doubles.toString()).toEqual("2,8,18");
// #END
} }
reduce() { reduce() {
// #TEST Int16Array.reduce // #TEST Int16Array.reduce
let total = new Int16Array([0, 1, 2, 3]); let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue); let res = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
total = new Int16Array([0, 1, 2, 3]); total = new Int16Array([0, 1, 2, 3]);
res = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8); let res1 = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res1); // 14
// #END // #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
} }
reduceRight() { reduceRight() {
// #TEST Int16Array.reduceRight // #TEST Int16Array.reduceRight
let total = new Int16Array([0, 1, 2, 3]); let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue); let res = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
total = new Int16Array([0, 1, 2, 3]); total = new Int16Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8); let res1 = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res1); // 14
// #END // #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
} }
reverse() { reverse() {
// #TEST Int16Array.reverse // #TEST Int16Array.reverse
let int16 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
int16.reverse(); int16.reverse();
expect(int16.toString()).toEqual("3,2,1"); console.log(int16.toString()); // "3,2,1"
// #END // #END
expect(int16.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Int16Array.slice // #TEST Int16Array.slice
let int16 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
let res = int16.slice(1); let res = int16.slice(1);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
res = int16.slice(2);
expect(res.toString()).toEqual("3");
res = int16.slice(-2); let res1 = int16.slice(2);
expect(res.toString()).toEqual("2,3"); console.log(res1.toString()); // "3"
let res2 = int16.slice(-2);
console.log(res2.toString()); // "2,3"
res = int16.slice(0, 1);
expect(res.toString()).toEqual("1"); let res3 = int16.slice(0, 1);
console.log(res3.toString()); // "1"
// #END // #END
expect(res3.toString()).toEqual("1");
expect(res.toString()).toEqual("2,3");
expect(res1.toString()).toEqual("3");
expect(res2.toString()).toEqual("2,3");
} }
sort() { sort() {
// #TEST Int16Array.sort // #TEST Int16Array.sort
let numbers = new Int16Array([40, 1, 5]); let numbers = new Int16Array([40, 1, 5]);
numbers.sort(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
let res = numbers.toString()
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// #END // #END
expect(numbers.toString()).toEqual("1,5,40");
expect(res).toEqual("1,5,40");
} }
subarray() { subarray() {
...@@ -264,49 +328,56 @@ export class TInt16Array { ...@@ -264,49 +328,56 @@ export class TInt16Array {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer); let int16 = new Int16Array(buffer);
int16.set([1, 2, 3]); int16.set([1, 2, 3]);
expect(int16.toString()).toEqual("1,2,3,0,0,0,0,0"); let res = int16.toString()
console.log(res); // "1,2,3,0,0,0,0,0"
let sub = int16.subarray(0, 4); let sub = int16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // "1,2,3,0"
// #END // #END
expect(sub.toString()).toEqual("1,2,3,0");
expect(res).toEqual("1,2,3,0,0,0,0,0");
} }
values() { values() {
// #TEST Int16Array.values // #TEST Int16Array.values
let arr = new Int16Array([1, 2, 3]); let arr = new Int16Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let res = values.next().value
console.log(res); // 1
// #END // #END
expect(res).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int16Array // #TEST ArrayBuffer.slice with Int16Array
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer); let int16 = new Int16Array(buffer);
int16[4] = 42; int16[4] = 42;
expect(int16.toString()).toEqual("0,0,0,0,42,0,0,0"); console.log(int16.toString()); // "0,0,0,0,42,0,0,0"
let res = buffer.slice(8, 12); let res = buffer.slice(8, 12);
let sliced = new Int16Array(res); let sliced = new Int16Array(res);
expect(sliced[0]).toEqual(42); console.log(sliced[0]); // 42
// #END // #END
expect(sliced[0]).toEqual(42);
expect(int16.toString()).toEqual("0,0,0,0,42,0,0,0");
} }
testSome() { testSome() {
// #TEST Int16Array.some // #TEST Int16Array.some
const int16 = new Int16Array([-10, 20, -30, 40, -50]); const int16 = new Int16Array([-10, 20, -30, 40, -50]);
const positives = new Int16Array([10, 20, 30, 40, 50]); const positives = new Int16Array([10, 20, 30, 40, 50]);
expect(int16.some((element : number, index : number, array : Int16Array) : boolean => console.log(int16.some((element : number, index : number, array : Int16Array) : boolean => element < 0)); // true
element < 0
)).toEqual(true);
expect(positives.some((element : number, index : number, array : Int16Array) : boolean => console.log(positives.some((element : number, index : number, array : Int16Array) : boolean => element < 0)); // false
element < 0
)).toEqual(false);
// #END // #END
expect(positives.some((element : number, index : number, array : Int16Array) : boolean => element < 0)).toEqual(false);
expect(int16.some((element : number, index : number, array : Int16Array) : boolean => element < 0)).toEqual(true);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -67,75 +67,91 @@ export class TInt32Array { ...@@ -67,75 +67,91 @@ export class TInt32Array {
testSet() { testSet() {
// #TEST Int32Array.set // #TEST Int32Array.set
let int32 = new Int32Array(8); let int32 = new Int32Array(8);
var array = [1, 2, 3] var array = [1, 2, 3];
int32.set(array, 1); int32.set(array, 1);
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(int32.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
// #TEST Int32Array.copyWithin // #TEST Int32Array.copyWithin
console.log("testCopyWith 1") console.log("testCopyWith start");
let int32 = new Int32Array(8); let int32 = new Int32Array(8);
int32.set([1, 2, 3], 1); int32.set([1, 2, 3], 1);
console.log("testCopyWith 1") console.log(int32.toString()); // "0,1,2,0,0,0,0,0"
int32.copyWithin(3, 0, 3); int32.copyWithin(3, 0, 3);
console.log("testCopyWith 1") console.log(int32.toString()); // "0,1,2,0,1,2,0,0"
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END // #END
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Int32Array.every // #TEST Int32Array.every
let result = new Int32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int32Array) : boolean => value < 40); let result = new Int32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int32Array) : boolean => value < 40);
expect(result).toEqual(false); console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Int32Array.fill // #TEST Int32Array.fill
let int32 = new Int32Array([1, 2, 3]).fill(4); let int32 = new Int32Array([1, 2, 3]).fill(4);
expect(int32.toString()).toEqual("4,4,4"); console.log(int32.toString()); // "4,4,4"
// expect(int32.toString()).toEqual("4,4,4");
int32 = new Int32Array([1, 2, 3]).fill(4, 1); int32 = new Int32Array([1, 2, 3]).fill(4, 1);
expect(int32.toString()).toEqual("1,4,4"); console.log(int32.toString()); // "1,4,4"
// expect(int32.toString()).toEqual("1,4,4");
int32 = new Int32Array([1, 2, 3]).fill(4, 1, 2); int32 = new Int32Array([1, 2, 3]).fill(4, 1, 2);
expect(int32.toString()).toEqual("1,4,3"); console.log(int32.toString()); // "1,4,3"
// expect(int32.toString()).toEqual("1,4,3");
int32 = new Int32Array([1, 2, 3]).fill(4, 1, 1); int32 = new Int32Array([1, 2, 3]).fill(4, 1, 1);
expect(int32.toString()).toEqual("1,2,3"); console.log(int32.toString()); // "1,2,3"
// expect(int32.toString()).toEqual("1,2,3");
int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2); int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
expect(int32.toString()).toEqual("4,2,3"); console.log(int32.toString()); // "4,2,3"
// #END // #END
expect(int32.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// #TEST Int32Array.filter // #TEST Int32Array.filter
let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array) : boolean => value >= 10); let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array) : boolean => value >= 10);
expect(int32.toString()).toEqual("12,44"); console.log(int32.toString()); // "12,44"
// #END // #END
expect(int32.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Int32Array.find // #TEST Int32Array.find
let int32 = new Int32Array([4, 5, 8, 12]); let int32 = new Int32Array([4, 5, 8, 12]);
let res = int32.find((value : number, _ : number, _a : Int32Array) : boolean => value > 5); let res = int32.find((value : number, _ : number, _a : Int32Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Int32Array.findIndex // #TEST Int32Array.findIndex
let int32 = new Int32Array([4, 6, 8, 12]); let int32 = new Int32Array([4, 6, 8, 12]);
let res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); let res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
// expect(res).toEqual(-1);
int32 = new Int32Array([4, 6, 7, 120]); int32 = new Int32Array([4, 6, 7, 120]);
res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100); res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
expect(res).toEqual(3); console.log(res); // 3
// #END // #END
expect(res).toEqual(3);
} }
foreach() { foreach() {
...@@ -150,133 +166,174 @@ export class TInt32Array { ...@@ -150,133 +166,174 @@ export class TInt32Array {
// #TEST Int32Array.entries // #TEST Int32Array.entries
let arr = new Int32Array([10, 20, 30, 40, 50]); let arr = new Int32Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let entry = entries.next();
console.log(entry.value[1]); // 10
// #END // #END
expect(entry.value[1]).toEqual(10);
} }
includes() { includes() {
// #TEST Int32Array.includes // #TEST Int32Array.includes
let int32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
let res = int32.includes(2); let res = int32.includes(2);
expect(res).toEqual(true); console.log(res); // true
// expect(res).toEqual(true);
res = int32.includes(4); res = int32.includes(4);
expect(res).toEqual(false); console.log(res); // false
// expect(res).toEqual(false);
res = int32.includes(3, 3); res = int32.includes(3, 3);
expect(res).toEqual(false); console.log(res); // false
// #END // #END
expect(res).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Int32Array.indexOf // #TEST Int32Array.indexOf
let int32 = new Int32Array([2, 5, 9]); let int32 = new Int32Array([2, 5, 9]);
let res = int32.indexOf(2); let res = int32.indexOf(2);
expect(res).toEqual(0); console.log(res); // 0
// expect(res).toEqual(0);
res = int32.indexOf(7); res = int32.indexOf(7);
expect(res).toEqual(-1); console.log(res); // -1
// expect(res).toEqual(-1);
res = int32.indexOf(9, 2); res = int32.indexOf(9, 2);
expect(res).toEqual(2); console.log(res); // 2
// expect(res).toEqual(2);
res = int32.indexOf(2, -1); res = int32.indexOf(2, -1);
expect(res).toEqual(-1); console.log(res); // -1
// expect(res).toEqual(-1);
res = int32.indexOf(2, -3); res = int32.indexOf(2, -3);
expect(res).toEqual(0); console.log(res); // 0
// #END // #END
expect(res).toEqual(0);
} }
join() { join() {
// #TEST Int32Array.join // #TEST Int32Array.join
let int32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
let res = int32.join(); let res = int32.join();
expect(res).toEqual("1,2,3"); console.log(res); // "1,2,3"
// expect(res).toEqual("1,2,3");
res = int32.join(" / "); res = int32.join(" / ");
expect(res).toEqual("1 / 2 / 3"); console.log(res); // "1 / 2 / 3"
// expect(res).toEqual("1 / 2 / 3");
res = int32.join(""); res = int32.join("");
expect(res).toEqual("123"); console.log(res); // "123"
// #END // #END
expect(res).toEqual("123");
} }
keys() { keys() {
// #TEST Int32Array.keys // #TEST Int32Array.keys
let arr = new Int32Array([10, 20, 30, 40, 50]); let arr = new Int32Array([10, 20, 30, 40, 50]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let key = keys.next();
console.log(key.value); // 0
// #END // #END
expect(key.value).toEqual(0);
} }
map() { map() {
// #TEST Int32Array.map // #TEST Int32Array.map
let numbers = new Int32Array([1, 4, 9]); let numbers = new Int32Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Int32Array) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Int32Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9"); expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18"); expect(doubles.toString()).toEqual("2,8,18");
// #END
} }
reduce() { reduce() {
// #TEST Int32Array.reduce // #TEST Int32Array.reduce
let total = new Int32Array([0, 1, 2, 3]); let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue); let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
// expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]); total = new Int32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8); res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
// #TEST Int32Array.reduceRight // #TEST Int32Array.reduceRight
let total = new Int32Array([0, 1, 2, 3]); let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue); let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
// expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]); total = new Int32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8); res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reverse() { reverse() {
// #TEST Int32Array.reverse // #TEST Int32Array.reverse
let int32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
int32.reverse(); int32.reverse();
expect(int32.toString()).toEqual("3,2,1"); console.log(int32.toString()); // "3,2,1"
// #END // #END
expect(int32.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Int32Array.slice // #TEST Int32Array.slice
let int32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
let res = int32.slice(1); let res = int32.slice(1);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = int32.slice(2); res = int32.slice(2);
expect(res.toString()).toEqual("3"); console.log(res.toString()); // "3"
// expect(res.toString()).toEqual("3");
res = int32.slice(-2); res = int32.slice(-2);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = int32.slice(0, 1); res = int32.slice(0, 1);
expect(res.toString()).toEqual("1"); console.log(res.toString()); // "1"
// #END // #END
expect(res.toString()).toEqual("1");
} }
sort() { sort() {
// #TEST Int32Array.sort // #TEST Int32Array.sort
let numbers = new Int32Array([40, 1, 5]); let numbers = new Int32Array([40, 1, 5]);
numbers.sort(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// #END // #END
expect(numbers.toString()).toEqual("1,5,40");
} }
subarray() { subarray() {
...@@ -284,49 +341,51 @@ export class TInt32Array { ...@@ -284,49 +341,51 @@ export class TInt32Array {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer); let int32 = new Int32Array(buffer);
int32.set([1, 2, 3]); int32.set([1, 2, 3]);
expect(int32.toString()).toEqual("1,2,3,0"); console.log(int32.toString()); // "1,2,3,0"
let sub = int32.subarray(0, 4); let sub = int32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // "1,2,3,0"
// #END // #END
expect(sub.toString()).toEqual("1,2,3,0");
} }
values() { values() {
// #TEST Int32Array.values // #TEST Int32Array.values
let arr = new Int32Array([1, 2, 3]); let arr = new Int32Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let value = values.next().value
console.log(value); // 1
// #END // #END
expect(value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer); let int32 = new Int32Array(buffer);
int32[3] = 42; int32[3] = 42;
expect(int32.toString()).toEqual("0,0,0,42"); console.log(int32.toString()); // "0,0,0,42"
let res = buffer.slice(8); let res = buffer.slice(8);
let sliced = new Int32Array(res); let sliced = new Int32Array(res);
expect(sliced[1]).toEqual(42); console.log(sliced[1]); // 42
// #END // #END
expect(sliced[1]).toEqual(42);
} }
testSome() { testSome() {
// #TEST Int32Array.some // #TEST Int32Array.some
const int32 = new Int32Array([-10, 20, -30, 40, -50]); const int32 = new Int32Array([-10, 20, -30, 40, -50]);
const positives = new Int32Array([10, 20, 30, 40, 50]); const positives = new Int32Array([10, 20, 30, 40, 50]);
expect(int32.some((element : number, index : number, array : Int32Array) : boolean => console.log(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // true
element < 0
)).toEqual(true); // expect(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(true);
expect(positives.some((element : number, index : number, array : Int32Array) : boolean => console.log(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // false
element < 0
)).toEqual(false);
// #END // #END
expect(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(false);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -48,10 +48,11 @@ export class TInt8Array { ...@@ -48,10 +48,11 @@ export class TInt8Array {
testSet() { testSet() {
// #TEST Int8Array.set // #TEST Int8Array.set
let int8 = new Int8Array(8); let int8 = new Int8Array(8);
var array = [1, 2, 3] var array = [1, 2, 3];
int8.set(array, 1); int8.set(array, 1);
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(int8.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
...@@ -59,67 +60,81 @@ export class TInt8Array { ...@@ -59,67 +60,81 @@ export class TInt8Array {
let int8 = new Int8Array(8); let int8 = new Int8Array(8);
int8.set([1, 2, 3], 1); int8.set([1, 2, 3], 1);
int8.copyWithin(3, 0, 3); int8.copyWithin(3, 0, 3);
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0"); console.log(int8.toString()); // "0,1,2,0,1,2,0,0"
// #END // #END
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Int8Array.every // #TEST Int8Array.every
// const isBelowThreshold = (currentValue: number, index: number, array:Int8Array): boolean => currentValue < 40; // const isBelowThreshold = (currentValue: number, index: number, array:Int8Array): boolean => currentValue < 40;
let result = new Int8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int8Array) : boolean => let result = new Int8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int8Array) : boolean =>
value < 40); value < 40
expect(result).toEqual(false); );
console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Int8Array.fill // #TEST Int8Array.fill
let int8 = new Int8Array([1, 2, 3]).fill(4); let int8 = new Int8Array([1, 2, 3]).fill(4);
expect(int8.toString()).toEqual("4,4,4"); console.log(int8.toString()); // "4,4,4"
int8 = new Int8Array([1, 2, 3]).fill(4, 1); let int8_t1 = new Int8Array([1, 2, 3]).fill(4, 1);
expect(int8.toString()).toEqual("1,4,4"); console.log(int8_t1.toString()); // "1,4,4"
int8 = new Int8Array([1, 2, 3]).fill(4, 1, 2); let int8_t2 = new Int8Array([1, 2, 3]).fill(4, 1, 2);
expect(int8.toString()).toEqual("1,4,3"); console.log(int8_t2.toString()); // "1,4,3"
int8 = new Int8Array([1, 2, 3]).fill(4, 1, 1); let int8_t3 = new Int8Array([1, 2, 3]).fill(4, 1, 1);
expect(int8.toString()).toEqual("1,2,3"); console.log(int8_t3.toString()); // "1,2,3"
int8 = new Int8Array([1, 2, 3]).fill(4, -3, -2); let int8_t4 = new Int8Array([1, 2, 3]).fill(4, -3, -2);
expect(int8.toString()).toEqual("4,2,3"); console.log(int8_t4.toString()); // "4,2,3"
// #END // #END
expect(int8_t4.toString()).toEqual("4,2,3");
expect(int8.toString()).toEqual("4,4,4");
expect(int8_t1.toString()).toEqual("1,4,4");
expect(int8_t2.toString()).toEqual("1,4,3");
expect(int8_t3.toString()).toEqual("1,2,3");
} }
testFilter() { testFilter() {
// #TEST Int8Array.filter // #TEST Int8Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let int8 = new Int8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int8Array) : boolean => let int8 = new Int8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int8Array) : boolean =>
value >= 10); value >= 10
expect(int8.toString()).toEqual("12,44"); );
console.log(int8.toString()); // "12,44"
// #END // #END
expect(int8.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Int8Array.find // #TEST Int8Array.find
let int8 = new Int8Array([4, 5, 8, 12]); let int8 = new Int8Array([4, 5, 8, 12]);
let res = int8.find((value : number, _ : number, _a : Int8Array) : boolean => value > 5); let res = int8.find((value : number, _ : number, _a : Int8Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Int8Array.findIndex // #TEST Int8Array.findIndex
let int8 = new Int8Array([4, 6, 8, 12]); let int8 = new Int8Array([4, 6, 8, 12]);
let res = int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100); let res = int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
int8 = new Int8Array([4, 6, 7, 120]); int8 = new Int8Array([4, 6, 7, 120]);
res = int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100); let res1 = int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100);
expect(res).toEqual(3); console.log(res1); // 3
// #END // #END
expect(res1).toEqual(3);
expect(res).toEqual(-1);
} }
foreach() { foreach() {
...@@ -129,83 +144,119 @@ export class TInt8Array { ...@@ -129,83 +144,119 @@ export class TInt8Array {
}); });
// #END // #END
} }
iterator() { iterator() {
// #TEST Int8Array.entries // #TEST Int8Array.entries
let arr = new Int8Array([10, 20, 30, 40, 50]); let arr = new Int8Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let ret1 = entries.next().value[1]
expect(entries.next().value[1]).toEqual(20); let ret2 = entries.next().value[1]
console.log(ret1); // Output: 10
console.log(ret2); // Output: 20
// #END // #END
expect(ret1).toEqual(10);
expect(ret2).toEqual(20);
} }
includes() { includes() {
// #TEST Int8Array.includes // #TEST Int8Array.includes
let int8 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
let res = int8.includes(2); let res = int8.includes(2);
expect(res).toEqual(true); console.log(res); // Output: true
let res1 = int8.includes(4);
console.log(res1); // Output: false
res = int8.includes(4);
expect(res).toEqual(false);
res = int8.includes(3, 3); let res2 = int8.includes(3, 3);
expect(res).toEqual(false); console.log(res2); // Output: false
// #END // #END
expect(res).toEqual(true);
expect(res1).toEqual(false);
expect(res2).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Int8Array.indexOf // #TEST Int8Array.indexOf
let int8 = new Int8Array([2, 5, 9]); let int8 = new Int8Array([2, 5, 9]);
let res = int8.indexOf(2); let res = int8.indexOf(2);
expect(res).toEqual(0); console.log(res); // Output: 0
res = int8.indexOf(7);
expect(res).toEqual(-1);
res = int8.indexOf(9, 2); let res1 = int8.indexOf(7);
expect(res).toEqual(2); console.log(res1); // Output: -1
let res2 = int8.indexOf(9, 2);
console.log(res2); // Output: 2
let res3 = int8.indexOf(2, -1);
console.log(res3); // Output: -1
let res4 = int8.indexOf(2, -3);
console.log(res4); // Output: 0
res = int8.indexOf(2, -1);
expect(res).toEqual(-1);
res = int8.indexOf(2, -3);
expect(res).toEqual(0);
// #END // #END
expect(res).toEqual(0);
expect(res1).toEqual(-1);
expect(res2).toEqual(2);
expect(res3).toEqual(-1);
expect(res4).toEqual(0);
} }
join() { join() {
// #TEST Int8Array.join // #TEST Int8Array.join
let int8 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
let res = int8.join(); let res = int8.join();
expect(res).toEqual("1,2,3"); console.log(res); // Output: "1,2,3"
res = int8.join(" / "); let res1 = int8.join(" / ");
expect(res).toEqual("1 / 2 / 3"); console.log(res1); // Output: "1 / 2 / 3"
res = int8.join("");
expect(res).toEqual("123"); let res2 = int8.join("");
console.log(res2); // Output: "123"
// #END // #END
expect(res2).toEqual("123");
expect(res).toEqual("1,2,3");
expect(res1).toEqual("1 / 2 / 3");
} }
keys() { keys() {
// #TEST Int8Array.keys // #TEST Int8Array.keys
let arr = new Int8Array([10, 20, 30, 40, 50]); let arr = new Int8Array([10, 20, 30, 40, 50]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let value1 = keys.next().value
expect(keys.next().value).toEqual(1); let value2 = keys.next().value
expect(keys.next().value).toEqual(2); let value3 = keys.next().value
expect(keys.next().value).toEqual(3); let value4 = keys.next().value
expect(keys.next().value).toEqual(4); let value5 = keys.next().value
console.log(value1); // Output: 0
console.log(value2); // Output: 1
console.log(value3); // Output: 2
console.log(value4); // Output: 3
console.log(value5); // Output: 4
// #END // #END
expect(value1).toEqual(0);
expect(value2).toEqual(1);
expect(value3).toEqual(2);
expect(value4).toEqual(3);
expect(value5).toEqual(4);
} }
map() { map() {
// #TEST Int8Array.map // #TEST Int8Array.map
let numbers = new Int8Array([1, 4, 9]); let numbers = new Int8Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Int8Array) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Int8Array) : number => value * 2);
console.log(numbers.toString()); // Output: "1,4,9"
console.log(doubles.toString()); // Output: "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9"); expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18"); expect(doubles.toString()).toEqual("2,8,18");
// #END
} }
reduce() { reduce() {
...@@ -213,13 +264,16 @@ export class TInt8Array { ...@@ -213,13 +264,16 @@ export class TInt8Array {
let total = new Int8Array([0, 1, 2, 3]); let total = new Int8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue); number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // Output: 6
total = new Int8Array([0, 1, 2, 3]); total = new Int8Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : number => let res1 = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res1); // Output: 14
// #END // #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
} }
reduceRight() { reduceRight() {
...@@ -227,50 +281,59 @@ export class TInt8Array { ...@@ -227,50 +281,59 @@ export class TInt8Array {
let total = new Int8Array([0, 1, 2, 3]); let total = new Int8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue); number => accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // Output: 6
total = new Int8Array([0, 1, 2, 3]); total = new Int8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : let res1 = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue, 8); number => accumulator + currentValue, 8);
console.log(res1); // Output: 14
expect(res).toEqual(14);
// #END // #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
} }
reverse() { reverse() {
// #TEST Int8Array.reverse // #TEST Int8Array.reverse
let int8 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
int8.reverse(); int8.reverse();
expect(int8.toString()).toEqual("3,2,1"); console.log(int8.toString()); // Output: "3,2,1"
// #END // #END
expect(int8.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Int8Array.slice // #TEST Int8Array.slice
let int8 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
let res = int8.slice(1); let res = int8.slice(1);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // Output: "2,3"
res = int8.slice(2); let res1 = int8.slice(2);
expect(res.toString()).toEqual("3"); console.log(res1.toString()); // Output: "3"
res = int8.slice(-2); let res2 = int8.slice(-2);
expect(res.toString()).toEqual("2,3"); console.log(res2.toString()); // Output: "2,3"
res = int8.slice(0, 1); let res3 = int8.slice(0, 1);
expect(res.toString()).toEqual("1"); console.log(res3.toString()); // Output: "1"
// #END // #END
expect(res3.toString()).toEqual("1");
expect(res.toString()).toEqual("2,3");
expect(res1.toString()).toEqual("3");
expect(res2.toString()).toEqual("2,3");
} }
sort() { sort() {
// #TEST Int8Array.sort // #TEST Int8Array.sort
let numbers = new Int8Array([40, 1, 5]); let numbers = new Int8Array([40, 1, 5]);
numbers.sort(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // Output: "1,5,40"
let res = numbers.toString()
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // Output: "1,5,40"
// #END // #END
expect(numbers.toString()).toEqual("1,5,40");
expect(res).toEqual("1,5,40");
} }
subarray() { subarray() {
...@@ -278,36 +341,45 @@ export class TInt8Array { ...@@ -278,36 +341,45 @@ export class TInt8Array {
let buffer = new ArrayBuffer(8); let buffer = new ArrayBuffer(8);
let int8 = new Int8Array(buffer); let int8 = new Int8Array(buffer);
int8.set([1, 2, 3]); int8.set([1, 2, 3]);
expect(int8.toString()).toEqual("1,2,3,0,0,0,0,0"); console.log(int8.toString()); // Output: "1,2,3,0,0,0,0,0"
let sub = int8.subarray(0, 4); let sub = int8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // Output: "1,2,3,0"
// #END // #END
expect(sub.toString()).toEqual("1,2,3,0");
expect(int8.toString()).toEqual("1,2,3,0,0,0,0,0");
} }
values() { values() {
// #TEST Int8Array.values // #TEST Int8Array.values
let arr = new Int8Array([1, 2, 3]); let arr = new Int8Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let value1 = values.next().value
expect(values.next().value).toEqual(2); let value2 = values.next().value
expect(values.next().value).toEqual(3); let value3 = values.next().value
console.log(value1); // Output: 1
console.log(value2); // Output: 2
console.log(value3); // Output: 3
// #END // #END
expect(value1).toEqual(1);
expect(value2).toEqual(2);
expect(value3).toEqual(3);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let int8 = new Int8Array(buffer); let int8 = new Int8Array(buffer);
int8[4] = 42; int8[4] = 42;
expect(int8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"); console.log(int8.toString()); // Output: "0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"
let res = buffer.slice(4, 5); let res = buffer.slice(4, 5);
let sliced = new Int8Array(res); let sliced = new Int8Array(res);
expect(sliced[0]).toEqual(42); console.log(sliced[0]); // Output: 42
// #END // #END
expect(sliced[0]).toEqual(42);
expect(int8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0");
} }
testSome() { testSome() {
...@@ -315,15 +387,19 @@ export class TInt8Array { ...@@ -315,15 +387,19 @@ export class TInt8Array {
const int8 = new Int8Array([-10, 20, -30, 40, -50]); const int8 = new Int8Array([-10, 20, -30, 40, -50]);
const positives = new Int8Array([10, 20, 30, 40, 50]); const positives = new Int8Array([10, 20, 30, 40, 50]);
expect(int8.some((element : number, index : number, array : Int8Array) : boolean => let res = int8.some((element : number, index : number, array : Int8Array) : boolean =>
element < 0 element < 0
)).toEqual(true); );
console.log(res); // Output: true
expect(positives.some((element : number, index : number, array : Int8Array) : boolean => let res1 = positives.some((element : number, index : number, array : Int8Array) : boolean =>
element < 0 element < 0
)).toEqual(false); );
console.log(res1); // Output: false
// #END // #END
expect(res1).toEqual(false);
expect(res).toEqual(true);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -61,8 +61,9 @@ export class TUint8Array { ...@@ -61,8 +61,9 @@ export class TUint8Array {
let uint8 = new Uint8Array(8); let uint8 = new Uint8Array(8);
var array = [1, 2, 3]; var array = [1, 2, 3];
uint8.set(array, 1); uint8.set(array, 1);
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(uint8.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
...@@ -71,65 +72,68 @@ export class TUint8Array { ...@@ -71,65 +72,68 @@ export class TUint8Array {
let uint8 = new Uint8Array(8); let uint8 = new Uint8Array(8);
uint8.set([1, 2, 3], 1); uint8.set([1, 2, 3], 1);
uint8.copyWithin(3, 0, 3); uint8.copyWithin(3, 0, 3);
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0"); console.log(uint8.toString()); // "0,1,2,0,1,2,0,0"
// #END // #END
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Uint8Array.every // #TEST Uint8Array.every
// const isBelowThreshold = (currentValue: number, index: number, array: Uint8Array): boolean => currentValue < 40;
let result = new Uint8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint8Array) : boolean => let result = new Uint8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint8Array) : boolean =>
value < 40); value < 40);
expect(result).toEqual(false); console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Uint8Array.fill // #TEST Uint8Array.fill
let uint8 = new Uint8Array([1, 2, 3]).fill(4); let uint8 = new Uint8Array([1, 2, 3]).fill(4);
expect(uint8.toString()).toEqual("4,4,4"); console.log(uint8.toString()); // "4,4,4"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1); uint8 = new Uint8Array([1, 2, 3]).fill(4, 1);
expect(uint8.toString()).toEqual("1,4,4"); console.log(uint8.toString()); // "1,4,4"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 2); uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 2);
expect(uint8.toString()).toEqual("1,4,3"); console.log(uint8.toString()); // "1,4,3"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 1); uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 1);
expect(uint8.toString()).toEqual("1,2,3"); console.log(uint8.toString()); // "1,2,3"
uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2); uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
expect(uint8.toString()).toEqual("4,2,3"); console.log(uint8.toString()); // "4,2,3"
// #END // #END
expect(uint8.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// #TEST Uint8Array.filter // #TEST Uint8Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
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);
expect(uint8.toString()).toEqual("12,44"); console.log(uint8.toString()); // "12,44"
// #END // #END
expect(uint8.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Uint8Array.find // #TEST Uint8Array.find
let uint8 = new Uint8Array([4, 5, 8, 12]); let uint8 = new Uint8Array([4, 5, 8, 12]);
let res = uint8.find((value : number, _ : number, _a : Uint8Array) : boolean => value > 5); let res = uint8.find((value : number, _ : number, _a : Uint8Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Uint8Array.findIndex // #TEST Uint8Array.findIndex
let uint8 = new Uint8Array([4, 6, 8, 12]); let uint8 = new Uint8Array([4, 6, 8, 12]);
let res = uint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); let res = uint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
let uuint8 = new Uint8Array([4, 6, 7, 120]); let uuint8 = new Uint8Array([4, 6, 7, 120]);
res = uuint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100); res = uuint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100);
expect(res).toEqual(3); console.log(res); // 3
// #END // #END
expect(res).toEqual(3);
} }
foreach() { foreach() {
...@@ -139,90 +143,115 @@ export class TUint8Array { ...@@ -139,90 +143,115 @@ export class TUint8Array {
}); });
// #END // #END
} }
iterator() { iterator() {
// #TEST Uint8Array.entries // #TEST Uint8Array.entries
let arr = new Uint8Array([10, 20, 30, 40, 50]); let arr = new Uint8Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let entry = entries.next().value;
console.log(entry[1]); // 10
// #END // #END
expect(entry[1]).toEqual(10);
} }
includes() { includes() {
// #TEST Uint8Array.includes // #TEST Uint8Array.includes
let uint8 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.includes(2); let res = uint8.includes(2);
expect(res).toEqual(true); console.log(res); // true
res = uint8.includes(4); res = uint8.includes(4);
expect(res).toEqual(false); console.log(res); // false
res = uint8.includes(3, 3); res = uint8.includes(3, 3);
expect(res).toEqual(false); console.log(res); // false
// #END // #END
expect(res).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Uint8Array.indexOf // #TEST Uint8Array.indexOf
let uint8 = new Uint8Array([2, 5, 9]); let uint8 = new Uint8Array([2, 5, 9]);
let res = uint8.indexOf(2); let res = uint8.indexOf(2);
expect(res).toEqual(0); console.log(res); // 0
// expect(res).toEqual(0);
res = uint8.indexOf(7); res = uint8.indexOf(7);
expect(res).toEqual(-1); console.log(res); // -1
// expect(res).toEqual(-1);
res = uint8.indexOf(9, 2); res = uint8.indexOf(9, 2);
expect(res).toEqual(2); console.log(res); // 2
// expect(res).toEqual(2);
res = uint8.indexOf(2, -1); res = uint8.indexOf(2, -1);
expect(res).toEqual(-1); console.log(res); // -1
// expect(res).toEqual(-1);
res = uint8.indexOf(2, -3); res = uint8.indexOf(2, -3);
expect(res).toEqual(0); console.log(res); // 0
// #END // #END
expect(res).toEqual(0);
} }
join() { join() {
// #TEST Uint8Array.join // #TEST Uint8Array.join
let uint8 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.join(); let res = uint8.join();
expect(res).toEqual("1,2,3"); console.log(res); // "1,2,3"
// expect(res).toEqual("1,2,3");
res = uint8.join(" / "); res = uint8.join(" / ");
expect(res).toEqual("1 / 2 / 3"); console.log(res); // "1 / 2 / 3"
// expect(res).toEqual("1 / 2 / 3");
res = uint8.join(""); res = uint8.join("");
expect(res).toEqual("123"); console.log(res); // "123"
// #END // #END
expect(res).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]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let value = keys.next().value
console.log(value); // 0
// #END // #END
expect(value).toEqual(0);
} }
map() { map() {
// #TEST Uint8Array.map // #TEST Uint8Array.map
let numbers = new Uint8Array([1, 4, 9]); let numbers = new Uint8Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint8Array) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Uint8Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9"); expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18"); expect(doubles.toString()).toEqual("2,8,18");
// #END
} }
reduce() { reduce() {
// #TEST Uint8Array.reduce // #TEST Uint8Array.reduce
let total = new Uint8Array([0, 1, 2, 3]); let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue); accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
// expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]); total = new Uint8Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => accumulator + res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
...@@ -230,48 +259,63 @@ export class TUint8Array { ...@@ -230,48 +259,63 @@ export class TUint8Array {
let total = new Uint8Array([0, 1, 2, 3]); let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue); accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
// expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]); total = new Uint8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number => res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reverse() { reverse() {
// #TEST Uint8Array.reverse // #TEST Uint8Array.reverse
let uint8 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse(); uint8.reverse();
expect(uint8.toString()).toEqual("3,2,1"); console.log(uint8.toString()); // "3,2,1"
// #END // #END
expect(uint8.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Uint8Array.slice // #TEST Uint8Array.slice
let uint8 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.slice(1); let res = uint8.slice(1);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = uint8.slice(2); res = uint8.slice(2);
expect(res.toString()).toEqual("3"); console.log(res.toString()); // "3"
// expect(res.toString()).toEqual("3");
res = uint8.slice(-2); res = uint8.slice(-2);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = uint8.slice(0, 1); res = uint8.slice(0, 1);
expect(res.toString()).toEqual("1"); console.log(res.toString()); // "1"
// #END // #END
expect(res.toString()).toEqual("1");
} }
sort() { sort() {
// #TEST Uint8Array.sort // #TEST Uint8Array.sort
let numbers = new Uint8Array([40, 1, 5]); let numbers = new Uint8Array([40, 1, 5]);
numbers.sort(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// #END // #END
expect(numbers.toString()).toEqual("1,5,40");
} }
subarray() { subarray() {
...@@ -279,50 +323,58 @@ export class TUint8Array { ...@@ -279,50 +323,58 @@ export class TUint8Array {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer); let uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]); uint8.set([1, 2, 3]);
expect(uint8.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"); console.log(uint8.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); let sub = uint8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // "1,2,3,0"
// #END // #END
expect(sub.toString()).toEqual("1,2,3,0");
} }
values() { values() {
// #TEST Uint8Array.values // #TEST Uint8Array.values
let arr = new Uint8Array([1, 2, 3]); let arr = new Uint8Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let value = values.next().value
console.log(value); // 1
// #END // #END
expect(value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer); let uint8 = new Uint8Array(buffer);
uint8[4] = 42; uint8[4] = 42;
expect(uint8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"); console.log(uint8.toString()); // "0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"
let res = buffer.slice(4, 12); let res = buffer.slice(4, 12);
let sliced = new Uint8Array(res); let sliced = new Uint8Array(res);
expect(sliced[0]).toEqual(42); console.log(sliced[0]); // 42
// #END // #END
expect(sliced[0]).toEqual(42);
} }
testSome() { testSome() {
// #TEST Uint8Array.some // #TEST Uint8Array.some
const uint8 = new Uint8Array([8, 20, 30, 40, 50]); const uint8 = new Uint8Array([8, 20, 30, 40, 50]);
const positives = new Uint8Array([10, 20, 30, 40, 50]); const positives = new Uint8Array([10, 20, 30, 40, 50]);
var res = uint8.some((element : number, index : number, array : Uint8Array) : boolean => var res = uint8.some((element : number, index : number, array : Uint8Array) : boolean =>
element < 10 element < 10
) );
expect(res).toEqual(true); console.log('uint8', res); // true
console.log('uint8', res)
// expect(res).toEqual(true);
res = positives.some((element : number, index : number, array : Uint8Array) : boolean => res = positives.some((element : number, index : number, array : Uint8Array) : boolean =>
element < 0 element < 0
) );
console.log('uint8', res) console.log('positives', res); // false
expect(res).toEqual(false);
// #END // #END
expect(res).toEqual(false);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -56,79 +56,84 @@ export class TUint8ClampedArray { ...@@ -56,79 +56,84 @@ export class TUint8ClampedArray {
let uint8Clamped = new Uint8ClampedArray(8); let uint8Clamped = new Uint8ClampedArray(8);
var array = [1, 2, 3]; var array = [1, 2, 3];
uint8Clamped.set(array, 1); uint8Clamped.set(array, 1);
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(uint8Clamped.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
// #TEST Uint8ClampedArray.copyWithin // #TEST Uint8ClampedArray.copyWithin
console.log("testCopyWith 1") console.log("testCopyWith 1");
let uint8Clamped = new Uint8ClampedArray(8); let uint8Clamped = new Uint8ClampedArray(8);
uint8Clamped.set([1, 2, 3], 1); uint8Clamped.set([1, 2, 3], 1);
uint8Clamped.copyWithin(3, 0, 3); uint8Clamped.copyWithin(3, 0, 3);
console.log(uint8Clamped.toString()); // "0,1,2,0,1,2,0,0"
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END // #END
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Uint8ClampedArray.every // #TEST Uint8ClampedArray.every
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8ClampedArray): boolean => currentValue < 40; // const isBelowThreshold = (currentValue: number, index: number, array:Uint8ClampedArray): boolean => currentValue < 40;
let result = new Uint8ClampedArray([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : let result = new Uint8ClampedArray([12, 5, 8, 130, 44]).every((value : number, _ : number, _a :
Uint8ClampedArray) : boolean => value < 40); // Uint8ClampedArray) : boolean => value < 40);
expect(result).toEqual(false); console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Uint8ClampedArray.fill // #TEST Uint8ClampedArray.fill
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4);
expect(uint8Clamped.toString()).toEqual("4,4,4"); console.log(uint8Clamped.toString()); // "4,4,4"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1);
expect(uint8Clamped.toString()).toEqual("1,4,4"); console.log(uint8Clamped.toString()); // "1,4,4"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2);
expect(uint8Clamped.toString()).toEqual("1,4,3"); console.log(uint8Clamped.toString()); // "1,4,3"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1);
expect(uint8Clamped.toString()).toEqual("1,2,3"); console.log(uint8Clamped.toString()); // "1,2,3"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2);
expect(uint8Clamped.toString()).toEqual("4,2,3"); console.log(uint8Clamped.toString()); // "4,2,3"
// #END // #END
expect(uint8Clamped.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;
let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value : number, _ : number, _a : let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value : number, _ : number, _a :
Uint8ClampedArray) : boolean => value >= 10); Uint8ClampedArray) : boolean => value >= 10);
expect(uint8Clamped.toString()).toEqual("12,44"); console.log(uint8Clamped.toString()); // "12,44"
// #END // #END
expect(uint8Clamped.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Uint8ClampedArray.find // #TEST Uint8ClampedArray.find
let uint8Clamped = new Uint8ClampedArray([4, 5, 8, 12]); let uint8Clamped = new Uint8ClampedArray([4, 5, 8, 12]);
let res = uint8Clamped.find((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 5); let res = uint8Clamped.find((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Uint8ClampedArray.findIndex // #TEST Uint8ClampedArray.findIndex
let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]); let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]);
let res = uint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); let res = uint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]); let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]);
res = uuint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100); res = uuint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100);
expect(res).toEqual(3); console.log(res); // 3
// #END // #END
expect(res).toEqual(3);
} }
foreach() { foreach() {
...@@ -138,89 +143,101 @@ export class TUint8ClampedArray { ...@@ -138,89 +143,101 @@ export class TUint8ClampedArray {
}); });
// #END // #END
} }
iterator() { iterator() {
// #TEST Uint8ClampedArray.entries // #TEST Uint8ClampedArray.entries
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]); let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let entry = entries.next().value;
console.log(entry[1]); // 10
// #END // #END
expect(entry[1]).toEqual(10);
} }
includes() { includes() {
// #TEST Uint8ClampedArray.includes // #TEST Uint8ClampedArray.includes
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.includes(2); let res = uint8Clamped.includes(2);
expect(res).toEqual(true); console.log(res); // true
res = uint8Clamped.includes(4); res = uint8Clamped.includes(4);
expect(res).toEqual(false); console.log(res); // false
res = uint8Clamped.includes(3, 3); res = uint8Clamped.includes(3, 3);
expect(res).toEqual(false); console.log(res); // false
// #END // #END
expect(res).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Uint8ClampedArray.indexOf // #TEST Uint8ClampedArray.indexOf
let uint8Clamped = new Uint8ClampedArray([2, 5, 9]); let uint8Clamped = new Uint8ClampedArray([2, 5, 9]);
let res = uint8Clamped.indexOf(2); let res = uint8Clamped.indexOf(2);
expect(res).toEqual(0); console.log(res); // 0
res = uint8Clamped.indexOf(7); res = uint8Clamped.indexOf(7);
expect(res).toEqual(-1); console.log(res); // -1
res = uint8Clamped.indexOf(9, 2); res = uint8Clamped.indexOf(9, 2);
expect(res).toEqual(2); console.log(res); // 2
res = uint8Clamped.indexOf(2, -1); res = uint8Clamped.indexOf(2, -1);
expect(res).toEqual(-1); console.log(res); // -1
res = uint8Clamped.indexOf(2, -3); res = uint8Clamped.indexOf(2, -3);
expect(res).toEqual(0); console.log(res); // 0
// #END // #END
expect(res).toEqual(0);
} }
join() { join() {
// #TEST Uint8ClampedArray.join // #TEST Uint8ClampedArray.join
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.join(); let res = uint8Clamped.join();
expect(res).toEqual("1,2,3"); console.log(res); // "1,2,3"
res = uint8Clamped.join(" / "); res = uint8Clamped.join(" / ");
expect(res).toEqual("1 / 2 / 3"); console.log(res); // "1 / 2 / 3"
res = uint8Clamped.join(""); res = uint8Clamped.join("");
expect(res).toEqual("123"); console.log(res); // "123"
// #END // #END
expect(res).toEqual("123");
} }
keys() { keys() {
// #TEST Uint8ClampedArray.keys // #TEST Uint8ClampedArray.keys
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]); let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let value = keys.next().value
console.log(value); // 0
// #END // #END
expect(value).toEqual(0);
} }
map() { map() {
// #TEST Uint8ClampedArray.map // #TEST Uint8ClampedArray.map
let numbers = new Uint8ClampedArray([1, 4, 9]); let numbers = new Uint8ClampedArray([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint8ClampedArray) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Uint8ClampedArray) : number => value * 2);
expect(numbers.toString()).toEqual("1,4,9"); console.log(numbers.toString()); // "1,4,9"
expect(doubles.toString()).toEqual("2,8,18"); console.log(doubles.toString()); // "2,8,18"
// #END // #END
expect(doubles.toString()).toEqual("2,8,18");
} }
reduce() { reduce() {
// #TEST Uint8ClampedArray.reduce // #TEST Uint8ClampedArray.reduce
let total = new Uint8ClampedArray([0, 1, 2, 3]); let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue); accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
total = new Uint8ClampedArray([0, 1, 2, 3]); total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
...@@ -228,97 +245,118 @@ export class TUint8ClampedArray { ...@@ -228,97 +245,118 @@ export class TUint8ClampedArray {
let total = new Uint8ClampedArray([0, 1, 2, 3]); let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue); accumulator + currentValue);
expect(res).toEqual(6); console.log(res); // 6
total = new Uint8ClampedArray([0, 1, 2, 3]); total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number => res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reverse() { reverse() {
// #TEST Uint8ClampedArray.reverse // #TEST Uint8ClampedArray.reverse
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
uint8Clamped.reverse(); uint8Clamped.reverse();
expect(uint8Clamped.toString()).toEqual("3,2,1"); console.log(uint8Clamped.toString()); // "3,2,1"
// #END // #END
expect(uint8Clamped.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Uint8ClampedArray.slice // #TEST Uint8ClampedArray.slice
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.slice(1); let res = uint8Clamped.slice(1);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
res = uint8Clamped.slice(2); res = uint8Clamped.slice(2);
expect(res.toString()).toEqual("3"); console.log(res.toString()); // "3"
res = uint8Clamped.slice(-2); res = uint8Clamped.slice(-2);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
res = uint8Clamped.slice(0, 1); res = uint8Clamped.slice(0, 1);
expect(res.toString()).toEqual("1"); console.log(res.toString()); // "1"
// #END // #END
expect(res.toString()).toEqual("1");
} }
sort() { sort() {
// #TEST Uint8ClampedArray.sort // #TEST Uint8ClampedArray.sort
let numbers = new Uint8ClampedArray([40, 1, 5]); let numbers = new Uint8ClampedArray([40, 1, 5]);
numbers.sort(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// #END // #END
expect(numbers.toString()).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 = new Uint8ClampedArray(buffer);
uint8Clamped.set([1, 2, 3]); uint8Clamped.set([1, 2, 3]);
expect(uint8Clamped.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"); 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); let sub = uint8Clamped.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // "1,2,3,0"
// #END // #END
expect(sub.toString()).toEqual("1,2,3,0");
} }
values() { values() {
// #TEST Uint8ClampedArray.values // #TEST Uint8ClampedArray.values
let arr = new Uint8ClampedArray([1, 2, 3]); let arr = new Uint8ClampedArray([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let value = values.next().value
console.log(value); // 1
// #END // #END
expect(value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer); let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped[4] = 42; uint8Clamped[4] = 42;
expect(uint8Clamped.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"); console.log(uint8Clamped.toString()); // "0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"
let res = buffer.slice(4, 12); let res = buffer.slice(4, 12);
let sliced = new Uint8ClampedArray(res); let sliced = new Uint8ClampedArray(res);
expect(sliced[0]).toEqual(42); console.log(sliced[0]); // 42
// #END // #END
expect(sliced[0]).toEqual(42);
} }
testSome() { testSome() {
// #TEST Uint8ClampedArray.some // #TEST Uint8ClampedArray.some
const uint8Clamped = new Uint8ClampedArray([8, 20, 30, 40, 50]); const uint8Clamped = new Uint8ClampedArray([8, 20, 30, 40, 50]);
const positives = new Uint8ClampedArray([10, 20, 30, 40, 50]); const positives = new Uint8ClampedArray([10, 20, 30, 40, 50]);
expect(uint8Clamped.some((element : number, index : number, array : Uint8ClampedArray) : boolean => console.log(uint8Clamped.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 10 element < 10
)).toEqual(true); )); // true
console.log(positives.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 0
)); // false
// #END
expect(positives.some((element : number, index : number, array : Uint8ClampedArray) : boolean => expect(positives.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 0 element < 0
)).toEqual(false); )).toEqual(false);
// #END
expect(uint8Clamped.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 10
)).toEqual(true);
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
export class TUint16Array { export class TUint16Array {
test() { test() {
// #ifdef (UNI-APP-X && APP-ANDROID) || WEB // #ifdef (UNI-APP-X && APP-ANDROID) || WEB
this.testuint16(); this.testuint16();
this.testConstructor(); this.testConstructor();
this.testSet(); this.testSet();
...@@ -65,79 +65,94 @@ export class TUint16Array { ...@@ -65,79 +65,94 @@ export class TUint16Array {
testSet() { testSet() {
// #TEST Uint16Array.set // #TEST Uint16Array.set
let uint16 = new Uint16Array(8); let uint16 = new Uint16Array(8);
var array = [1, 2, 3] var array = [1, 2, 3];
uint16.set(array, 1); uint16.set(array, 1);
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(uint16.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
// #TEST Uint16Array.copyWith // #TEST Uint16Array.copyWithin
console.log("testCopyWith 1") console.log("testCopyWith 1");
let uint16 = new Uint16Array(8); let uint16 = new Uint16Array(8);
uint16.set([1, 2, 3], 1); uint16.set([1, 2, 3], 1);
console.log("testCopyWith 2") console.log("testCopyWith 2");
uint16.copyWithin(3, 0, 3); uint16.copyWithin(3, 0, 3);
console.log("testCopyWith 3") console.log("testCopyWith 3");
expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0"); console.log(uint16.toString()); // "0,1,2,0,1,2,0,0"
// #END // #END
expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Uint16Array.every // #TEST Uint16Array.every
// const isBelowThreshold = (currentValue: number, index: number, array: Uint16Array): boolean => currentValue < 40;
let result = new Uint16Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint16Array) : let result = new Uint16Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint16Array) :
boolean => value < 40); boolean => value < 40);
expect(result).toEqual(false); console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
testFill() { testFill() {
// #TEST Uint16Array.fill // #TEST Uint16Array.fill
let uint16 = new Uint16Array([1, 2, 3]).fill(4); let uint16 = new Uint16Array([1, 2, 3]).fill(4);
console.log(uint16.toString()); // "4,4,4"
// #END
expect(uint16.toString()).toEqual("4,4,4"); expect(uint16.toString()).toEqual("4,4,4");
uint16 = new Uint16Array([1, 2, 3]).fill(4, 1); uint16 = new Uint16Array([1, 2, 3]).fill(4, 1);
console.log(uint16.toString()); // "1,4,4"
// #END
expect(uint16.toString()).toEqual("1,4,4"); expect(uint16.toString()).toEqual("1,4,4");
uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 2); 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"); expect(uint16.toString()).toEqual("1,4,3");
uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 1); 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"); expect(uint16.toString()).toEqual("1,2,3");
uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2); uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2);
expect(uint16.toString()).toEqual("4,2,3"); console.log(uint16.toString()); // "4,2,3"
// #END // #END
expect(uint16.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// #TEST Uint16Array.filter // #TEST Uint16Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint16 = new Uint16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint16Array) : let uint16 = new Uint16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint16Array) :
boolean => value >= 10); boolean => value >= 10);
expect(uint16.toString()).toEqual("12,44"); console.log(uint16.toString()); // "12,44"
// #END // #END
expect(uint16.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Uint16Array.find // #TEST Uint16Array.find
let uint16 = new Uint16Array([4, 5, 8, 12]); let uint16 = new Uint16Array([4, 5, 8, 12]);
let res = uint16.find((value : number, _ : number, _a : Uint16Array) : boolean => value > 5); let res = uint16.find((value : number, _ : number, _a : Uint16Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
findIndex() { findIndex() {
// #TEST Uint16Array.findIndex // #TEST Uint16Array.findIndex
let uint16 = new Uint16Array([4, 6, 8, 12]); let uint16 = new Uint16Array([4, 6, 8, 12]);
let res = uint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100); let res = uint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100);
console.log(res); // -1
// #END
expect(res).toEqual(-1); expect(res).toEqual(-1);
let uuint16 = new Uint16Array([4, 6, 7, 120]); let uuint16 = new Uint16Array([4, 6, 7, 120]);
res = uuint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100); res = uuint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100);
expect(res).toEqual(3); console.log(res); // 3
// #END // #END
expect(res).toEqual(3);
} }
foreach() { foreach() {
...@@ -152,87 +167,114 @@ export class TUint16Array { ...@@ -152,87 +167,114 @@ export class TUint16Array {
// #TEST Uint16Array.entries // #TEST Uint16Array.entries
let arr = new Uint16Array([10, 20, 30, 40, 50]); let arr = new Uint16Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let entry = entries.next().value;
console.log(entry[1]); // 10
// #END // #END
expect(entry[1]).toEqual(10);
} }
includes() { includes() {
// #TEST Uint16Array.includes // #TEST Uint16Array.includes
let uint16 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.includes(2); let res = uint16.includes(2);
console.log(res); // true
// #END
expect(res).toEqual(true); expect(res).toEqual(true);
res = uint16.includes(4); res = uint16.includes(4);
console.log(res); // false
// #END
expect(res).toEqual(false); expect(res).toEqual(false);
res = uint16.includes(3, 3); res = uint16.includes(3, 3);
expect(res).toEqual(false); console.log(res); // false
// #END // #END
expect(res).toEqual(false);
} }
indexOf() { indexOf() {
// #TEST Uint16Array.indexOf // #TEST Uint16Array.indexOf
let uint16 = new Uint16Array([2, 5, 9]); let uint16 = new Uint16Array([2, 5, 9]);
let res = uint16.indexOf(2); let res = uint16.indexOf(2);
console.log(res); // 0
// #END
expect(res).toEqual(0); expect(res).toEqual(0);
res = uint16.indexOf(7); res = uint16.indexOf(7);
console.log(res); // -1
// #END
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = uint16.indexOf(9, 2); res = uint16.indexOf(9, 2);
console.log(res); // 2
// #END
expect(res).toEqual(2); expect(res).toEqual(2);
res = uint16.indexOf(2, -1); res = uint16.indexOf(2, -1);
console.log(res); // -1
// #END
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = uint16.indexOf(2, -3); res = uint16.indexOf(2, -3);
expect(res).toEqual(0); console.log(res); // 0
// #END // #END
expect(res).toEqual(0);
} }
join() { join() {
// #TEST Uint16Array.join // #TEST Uint16Array.join
let uint16 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.join(); let res = uint16.join();
console.log(res); // "1,2,3"
// #END
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = uint16.join(" / "); res = uint16.join(" / ");
console.log(res); // "1 / 2 / 3"
// #END
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = uint16.join(""); res = uint16.join("");
expect(res).toEqual("123"); console.log(res); // "123"
// #END // #END
expect(res).toEqual("123");
} }
keys() { keys() {
// #TEST Uint16Array.keys // #TEST Uint16Array.keys
let arr = new Uint16Array([10, 20, 30, 40, 50]); let arr = new Uint16Array([10, 20, 30, 40, 50]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let value = keys.next().value
console.log(value); // 0
// #END // #END
expect(value).toEqual(0);
} }
map() { map() {
// #TEST Uint16Array.map // #TEST Uint16Array.map
let numbers = new Uint16Array([1, 4, 9]); let numbers = new Uint16Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint16Array) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Uint16Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9"); expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18"); expect(doubles.toString()).toEqual("2,8,18");
// #END
} }
reduce() { reduce() {
// #TEST Uint16Array.reduce // #TEST Uint16Array.reduce
let total = new Uint16Array([0, 1, 2, 3]); let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue); accumulator + currentValue);
console.log(res); // 6
// #END
expect(res).toEqual(6); expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]); total = new Uint16Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
...@@ -240,48 +282,63 @@ export class TUint16Array { ...@@ -240,48 +282,63 @@ export class TUint16Array {
let total = new Uint16Array([0, 1, 2, 3]); let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue); accumulator + currentValue);
console.log(res); // 6
// #END
expect(res).toEqual(6); expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]); total = new Uint16Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number => res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue, 8); accumulator + currentValue, 8);
expect(res).toEqual(14); console.log(res); // 14
// #END // #END
expect(res).toEqual(14);
} }
reverse() { reverse() {
// #TEST Uint16Array.reverse // #TEST Uint16Array.reverse
let uint16 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
uint16.reverse(); uint16.reverse();
expect(uint16.toString()).toEqual("3,2,1"); console.log(uint16.toString()); // "3,2,1"
// #END // #END
expect(uint16.toString()).toEqual("3,2,1");
} }
slice() { slice() {
// #TEST Uint16Array.slice // #TEST Uint16Array.slice
let uint16 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.slice(1); let res = uint16.slice(1);
console.log(res.toString()); // "2,3"
// #END
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = uint16.slice(2); res = uint16.slice(2);
console.log(res.toString()); // "3"
// #END
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = uint16.slice(-2); res = uint16.slice(-2);
console.log(res.toString()); // "2,3"
// #END
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = uint16.slice(0, 1); res = uint16.slice(0, 1);
expect(res.toString()).toEqual("1"); console.log(res.toString()); // "1"
// #END // #END
expect(res.toString()).toEqual("1");
} }
sort() { sort() {
// #TEST Uint16Array.sort // #TEST Uint16Array.sort
let numbers = new Uint16Array([40, 1, 5]); let numbers = new Uint16Array([40, 1, 5]);
numbers.sort(); numbers.sort();
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40"); expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// #END // #END
expect(numbers.toString()).toEqual("1,5,40");
} }
subarray() { subarray() {
...@@ -289,35 +346,42 @@ export class TUint16Array { ...@@ -289,35 +346,42 @@ export class TUint16Array {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer); let uint16 = new Uint16Array(buffer);
uint16.set([1, 2, 3]); 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"); expect(uint16.toString()).toEqual("1,2,3,0,0,0,0,0");
let sub = uint16.subarray(0, 4); let sub = uint16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // "1,2,3,0"
// #END // #END
expect(sub.toString()).toEqual("1,2,3,0");
} }
values() { values() {
// #TEST Uint16Array.values // #TEST Uint16Array.values
let arr = new Uint16Array([1, 2, 3]); let arr = new Uint16Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let value = values.next().value
console.log(value); // 1
// #END // #END
expect(value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST Uint16Array.arrayBufferSlice // #TEST Uint16Array.arrayBufferSlice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer); let uint16 = new Uint16Array(buffer);
uint16[4] = 42; 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"); expect(uint16.toString()).toEqual("0,0,0,0,42,0,0,0");
let res = buffer.slice(8); let res = buffer.slice(8);
let sliced = new Uint16Array(res); let sliced = new Uint16Array(res);
expect(sliced[0]).toEqual(42); console.log(sliced[0]); // 42
// #END // #END
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]);
...@@ -327,11 +391,11 @@ export class TUint16Array { ...@@ -327,11 +391,11 @@ export class TUint16Array {
element < 10 element < 10
)).toEqual(true); )).toEqual(true);
expect(positives.some((element : number, index : number, array : Uint16Array) : boolean => expect(positives.some((element : number, index : number, array : Uint16Array) : boolean =>
element < 0 element < 0
)).toEqual(false); )).toEqual(false);
// #END // #END
} }
// #endif // #endif
} }
\ No newline at end of file
...@@ -68,8 +68,9 @@ export class TUint32Array { ...@@ -68,8 +68,9 @@ export class TUint32Array {
let uint32 = new Uint32Array(8); let uint32 = new Uint32Array(8);
var array = [1, 2, 3]; var array = [1, 2, 3];
uint32.set(array, 1); uint32.set(array, 1);
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0"); console.log(uint32.toString()); // "0,1,2,3,0,0,0,0"
// #END // #END
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
...@@ -77,65 +78,65 @@ export class TUint32Array { ...@@ -77,65 +78,65 @@ export class TUint32Array {
console.log("testCopyWith 1"); 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 1"); console.log("testCopyWith 2");
uint32.copyWithin(3, 0, 3); uint32.copyWithin(3, 0, 3);
console.log("testCopyWith 1"); console.log("testCopyWith 3");
expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0"); console.log(uint32.toString()); // "0,1,2,0,1,2,0,0"
// #END // #END
expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// #TEST Uint32Array.every // #TEST Uint32Array.every
// const isBelowThreshold = (currentValue: number, index: number, array: Uint32Array): boolean => currentValue < 40;
let result = new Uint32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint32Array) : boolean => value < 40); let result = new Uint32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint32Array) : boolean => value < 40);
expect(result).toEqual(false); console.log(result); // false
// #END // #END
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);
expect(uint32.toString()).toEqual("4,4,4"); console.log(uint32.toString()); // "4,4,4"
uint32 = new Uint32Array([1, 2, 3]).fill(4, 1); uint32 = new Uint32Array([1, 2, 3]).fill(4, 1);
expect(uint32.toString()).toEqual("1,4,4"); console.log(uint32.toString()); // "1,4,4"
uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 2); uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 2);
expect(uint32.toString()).toEqual("1,4,3"); console.log(uint32.toString()); // "1,4,3"
uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 1); uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 1);
expect(uint32.toString()).toEqual("1,2,3"); console.log(uint32.toString()); // "1,2,3"
uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2); uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2);
expect(uint32.toString()).toEqual("4,2,3"); console.log(uint32.toString()); // "4,2,3"
// #END // #END
expect(uint32.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// #TEST Uint32Array.filter // #TEST Uint32Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint32 = new Uint32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint32Array) : boolean => value >= 10); let uint32 = new Uint32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint32Array) : boolean => value >= 10);
expect(uint32.toString()).toEqual("12,44"); console.log(uint32.toString()); // "12,44"
// #END // #END
expect(uint32.toString()).toEqual("12,44");
} }
find() { find() {
// #TEST Uint32Array.find // #TEST Uint32Array.find
let uint32 = new Uint32Array([4, 5, 8, 12]); let uint32 = new Uint32Array([4, 5, 8, 12]);
let res = uint32.find((value : number, _ : number, _a : Uint32Array) : boolean => value > 5); let res = uint32.find((value : number, _ : number, _a : Uint32Array) : boolean => value > 5);
expect(res).toEqual(8); console.log(res); // 8
// #END // #END
expect(res).toEqual(8);
} }
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); let res = uint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
expect(res).toEqual(-1); console.log(res); // -1
res = new Uint32Array([4, 6, 7, 120]).findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
let uuint32 = new Uint32Array([4, 6, 7, 120]); console.log(res); // 3
res = uuint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
expect(res).toEqual(3);
// #END // #END
expect(res).toEqual(3);
} }
foreach() { foreach() {
...@@ -145,189 +146,206 @@ export class TUint32Array { ...@@ -145,189 +146,206 @@ export class TUint32Array {
}); });
// #END // #END
} }
iterator() { iterator() {
// #TEST Uint32Array.entries // #TEST Uint32Array.entries
let arr = new Uint32Array([10, 20, 30, 40, 50]); let arr = new Uint32Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); let entry = entries.next().value;
console.log(entry[1]); // 10
// #END // #END
expect(entry[1]).toEqual(10);
} }
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); let res = uint32.includes(2);
expect(res).toEqual(true); console.log(res); // true
res = uint32.includes(4); res = uint32.includes(4);
expect(res).toEqual(false); console.log(res); // false
res = uint32.includes(3, 3); res = uint32.includes(3, 3);
expect(res).toEqual(false); console.log(res); // false
// #END // #END
expect(res).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); let res = uint32.indexOf(2);
expect(res).toEqual(0); console.log(res); // 0
res = uint32.indexOf(7); res = uint32.indexOf(7);
expect(res).toEqual(-1); console.log(res); // -1
res = uint32.indexOf(9, 2); res = uint32.indexOf(9, 2);
expect(res).toEqual(2); console.log(res); // 2
res = uint32.indexOf(2, -1); res = uint32.indexOf(2, -1);
expect(res).toEqual(-1); console.log(res); // -1
res = uint32.indexOf(2, -3); res = uint32.indexOf(2, -3);
expect(res).toEqual(0); console.log(res); // 0
// #END // #END
expect(res).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(); let res = uint32.join();
expect(res).toEqual("1,2,3"); console.log(res); // "1,2,3"
res = uint32.join(" / "); res = uint32.join(" / ");
expect(res).toEqual("1 / 2 / 3"); console.log(res); // "1 / 2 / 3"
res = uint32.join(""); res = uint32.join("");
expect(res).toEqual("123"); console.log(res); // "123"
// #END // #END
expect(res).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]);
let keys = arr.keys(); let keys = arr.keys();
expect(keys.next().value).toEqual(0); let value = keys.next().value
console.log(value); // 0
// #END // #END
expect(value).toEqual(0);
} }
map() { map() {
// #TEST Uint32Array.map // #TEST Uint32Array.map
let numbers = new Uint32Array([1, 4, 9]); let numbers = new Uint32Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint32Array) : number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Uint32Array) : number => value * 2);
expect(numbers.toString()).toEqual("1,4,9"); console.log(numbers.toString()); // "1,4,9"
expect(doubles.toString()).toEqual("2,8,18"); console.log(doubles.toString()); // "2,8,18"
// #END // #END
expect(doubles.toString()).toEqual("2,8,18");
} }
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) : let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue);
number => accumulator + currentValue); console.log(res); // 6
expect(res).toEqual(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) : res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8); console.log(res); // 14
expect(res).toEqual(14);
// #END // #END
expect(res).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) : let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue);
number => accumulator + currentValue); console.log(res); // 6
expect(res).toEqual(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) : res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8); console.log(res); // 14
expect(res).toEqual(14);
// #END // #END
expect(res).toEqual(14);
} }
reverse() { reverse() {
// #TEST Uint32Array.reverse // #TEST Uint32Array.reverse
let uint32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
uint32.reverse(); uint32.reverse();
expect(uint32.toString()).toEqual("3,2,1"); console.log(uint32.toString()); // "3,2,1"
// #END // #END
expect(uint32.toString()).toEqual("3,2,1");
} }
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); let res = uint32.slice(1);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
res = uint32.slice(2); res = uint32.slice(2);
expect(res.toString()).toEqual("3"); console.log(res.toString()); // "3"
res = uint32.slice(-2); res = uint32.slice(-2);
expect(res.toString()).toEqual("2,3"); console.log(res.toString()); // "2,3"
res = uint32.slice(0, 1); res = uint32.slice(0, 1);
expect(res.toString()).toEqual("1"); console.log(res.toString()); // "1"
// #END // #END
expect(res.toString()).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(); numbers.sort();
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
numbers.sort((a, b) : number => a - b); numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40"); console.log(numbers.toString()); // "1,5,40"
// #END // #END
expect(numbers.toString()).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]);
expect(uint32.toString()).toEqual("1,2,3,0"); console.log(uint32.toString()); // "1,2,3,0"
let sub = uint32.subarray(0, 4); let sub = uint32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); console.log(sub.toString()); // "1,2,3,0"
// #END // #END
expect(sub.toString()).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]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); let value = values.next().value;
console.log(value); // 1
// #END // #END
expect(value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
// #TEST ArrayBuffer.slice // #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer); let uint32 = new Uint32Array(buffer);
uint32[3] = 42; uint32[3] = 42;
expect(uint32.toString()).toEqual("0,0,0,42"); console.log(uint32.toString()); // "0,0,0,42"
let res = buffer.slice(8); let res = buffer.slice(8);
let sliced = new Uint32Array(res); let sliced = new Uint32Array(res);
expect(sliced[1]).toEqual(42); console.log(sliced[1]); // 42
// #END // #END
expect(sliced[1]).toEqual(42);
} }
testSome() { testSome() {
// #TEST Uint32Array.some // #TEST Uint32Array.some
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]);
expect(uint32.some((element : number, index : number, array : Uint32Array) : boolean => let result = uint32.some((element : number, index : number, array : Uint32Array) : boolean =>
element < 10 element < 10
)).toEqual(true); );
console.log(result); // true
expect(positives.some((element : number, index : number, array : Uint32Array) : boolean => result = positives.some((element : number, index : number, array : Uint32Array) : boolean =>
element < 0 element < 0
)).toEqual(false); );
console.log(result); // false
// #END // #END
expect(result).toEqual(false);
} }
// #endif // #endif
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册