提交 b7581100 编写于 作者: M mahaifeng

[array-buffer]添加#TEST 注释

上级 f62fd355
......@@ -63,6 +63,7 @@ export class TFloat32Array {
}
testConstructor() {
let buffer = new ArrayBuffer(16);
let float32 = new Float32Array(buffer);
float32[1] = 42;
......@@ -70,30 +71,33 @@ export class TFloat32Array {
}
testSet() {
// #TEST Float32Array.set
let float32 = new Float32Array(8);
var array = [1, 2, 3]
float32.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Float32Array.copyWithin
let float32 = new Float32Array(8);
float32.set([1, 2, 3], 1);
console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Float32Array): boolean => currentValue < 40;
let result = new Float32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Float32Array) :
boolean => value < 40); //
// #TEST Float32Array.every
let result = new Float32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Float32Array) : boolean => value < 40);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Float32Array.fill
let float32 = new Float32Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4");
......@@ -108,23 +112,26 @@ export class TFloat32Array {
float32 = new Float32Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Float32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float32Array) :
boolean => value >= 10);
// #TEST Float32Array.filter
let float32 = new Float32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float32Array) : boolean => value >= 10);
expect(float32.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Float32Array.find
let float32 = new Float32Array([4, 5, 8, 12]);
let res = float32.find((value : number, _ : number, _a : Float32Array) : boolean => value > 5);
expect(res).toEqual(8);
// #END
}
findIndex() {
// #TEST Float32Array.findIndex
let float32 = new Float32Array([4, 6, 8, 12]);
let res = float32.findIndex((value : number, _ : number, _a : Float32Array) : boolean => value > 100);
expect(res).toEqual(-1);
......@@ -132,22 +139,28 @@ export class TFloat32Array {
let ufloat32 = new Float32Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value : number, _ : number, _a : Float32Array) : boolean => value > 100);
expect(res).toEqual(3);
// #END
}
foreach() {
// #TEST Float32Array.forEach
new Float32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Float32Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Float32Array.entries
let arr = new Float32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
// #END
}
includes() {
// #TEST Float32Array.includes
let float32 = new Float32Array([1, 2, 3]);
let res = float32.includes(2.0);
expect(res).toEqual(true);
......@@ -157,9 +170,11 @@ export class TFloat32Array {
res = float32.includes(3.0, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Float32Array.indexOf
let float32 = new Float32Array([2, 5, 9]);
let res = float32.indexOf(2);
expect(res).toEqual(0);
......@@ -175,9 +190,11 @@ export class TFloat32Array {
res = float32.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Float32Array.join
let float32 = new Float32Array([1, 2, 3]);
let res = float32.join();
expect(res).toEqual("1,2,3");
......@@ -187,9 +204,11 @@ export class TFloat32Array {
res = float32.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Float32Array.keys
let arr = new Float32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
......@@ -197,46 +216,53 @@ export class TFloat32Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
// #END
}
map() {
// #TEST Float32Array.map
let numbers = new Float32Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Float32Array) : number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Float32Array.reduce
let total = new Float32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) :
number => accumulator + currentValue);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
total = new Float32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) :
number => accumulator + currentValue, 8);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Float32Array.reduceRight
let total = new Float32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a :
Float32Array) : number => accumulator + currentValue);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
total = new Float32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float32Array) :
number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Float32Array.reverse
let float32 = new Float32Array([1, 2, 3]);
float32.reverse();
expect(float32.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Float32Array.slice
let float32 = new Float32Array([1, 2, 3]);
let res = float32.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -249,18 +275,22 @@ export class TFloat32Array {
res = float32.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Float32Array.sort
let numbers = new Float32Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
// #END
}
subarray() {
// #TEST Float32Array.subarray
let buffer = new ArrayBuffer(16);
let float32 = new Float32Array(buffer);
float32.set([1, 2, 3]);
......@@ -268,17 +298,21 @@ export class TFloat32Array {
let sub = float32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Float32Array.values
let arr = new Float32Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let float32 = new Float32Array(buffer);
float32[3] = 42;
......@@ -287,6 +321,8 @@ export class TFloat32Array {
let res = buffer.slice(8);
let sliced = new Float32Array(res);
expect(sliced[1]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import {
export class TFloat64Array {
test() {
// #ifdef APP-ANDROID
this.testfloat64();
this.testConstructor();
this.testSet();
......@@ -31,8 +32,9 @@ export class TFloat64Array {
this.subarray();
this.values();
this.arrayBufferSlice();
// #endif
}
// #ifdef APP-ANDROID
testfloat64() {
let float64 = new Float64Array(2);
float64[0] = 42;
......@@ -60,27 +62,32 @@ export class TFloat64Array {
}
testSet() {
// #TEST Float64Array.set
let float64 = new Float64Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3];
float64.set(array, 1);
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
// #TEST Float64Array.copyWithin
let float64 = new Float64Array(8);
float64.set([1, 2, 3], 1);
float64.copyWithin(3, 0, 3);
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Float64Array): boolean => currentValue < 40;
let result = new Float64Array([-10, -20, -30, -40, -50]).every((value: number, _: number, _a:
Float64Array): boolean => value < 0); //
// #TEST Float64Array.every
let result = new Float64Array([-10, -20, -30, -40, -50]).every((value : number, _ : number, _a : Float64Array) : boolean => value < 0);
expect(result).toEqual(true);
// #END
}
testFill() {
// #TEST Float64Array.fill
let float64 = new Float64Array([1, 2, 3]).fill(4);
expect(float64.toString()).toEqual("4,4,4");
......@@ -95,46 +102,56 @@ export class TFloat64Array {
float64 = new Float64Array([1, 2, 3]).fill(4, -3, -2);
expect(float64.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float64 = new Float64Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Float64Array):
boolean => value >= 10);
// #TEST Float64Array.filter
let float64 = new Float64Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float64Array) : boolean => value >= 10);
expect(float64.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Float64Array.find
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);
// #END
}
findIndex() {
// #TEST Float64Array.findIndex
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);
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);
// #END
}
foreach() {
new Float64Array([0, 1, 2, 3]).forEach((value: number, index: number, _: Float64Array) => {
// #TEST Float64Array.forEach
new Float64Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Float64Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Float64Array.entries
let arr = new Float64Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
// #END
}
includes() {
// #TEST Float64Array.includes
let float64 = new Float64Array([1, 2, 3]);
let res = float64.includes(2);
expect(res).toEqual(true);
......@@ -144,9 +161,11 @@ export class TFloat64Array {
res = float64.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Float64Array.indexOf
let float64 = new Float64Array([2, 5, 9]);
let res = float64.indexOf(2);
expect(res).toEqual(0);
......@@ -162,9 +181,11 @@ export class TFloat64Array {
res = float64.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Float64Array.join
let float64 = new Float64Array([1, 2, 3]);
let res = float64.join();
expect(res).toEqual("1,2,3");
......@@ -174,10 +195,12 @@ export class TFloat64Array {
res = float64.join("");
expect(res).toEqual("123");
// #END
}
keys() {
//todo 有差异 js 是keys.next().value
// #TEST Float64Array.keys
let arr = new Float64Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
......@@ -185,46 +208,52 @@ export class TFloat64Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
// #END
}
map() {
// #TEST Float64Array.map
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);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Float64Array.reduce
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);
total = new Float64Array([0, 1, 2, 3]);
res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Float64Array):
number => accumulator + currentValue, 8);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Float64Array.reduceRight
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);
total = new Float64Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Float64Array):
number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Float64Array.reverse
let float64 = new Float64Array([1, 2, 3]);
float64.reverse();
expect(float64.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Float64Array.slice
let float64 = new Float64Array([1, 2, 3]);
let res = float64.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -237,18 +266,23 @@ export class TFloat64Array {
res = float64.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Float64Array.sort
let numbers = new Float64Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Float64Array.subarray
let buffer = new ArrayBuffer(32);
let float64 = new Float64Array(buffer);
float64.set([1, 2, 3]);
......@@ -256,17 +290,21 @@ export class TFloat64Array {
let sub = float64.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Float64Array.values
let arr = new Float64Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
// #END
}
arrayBufferSlice() {
// #TEST Float64Array with ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let float64 = new Float64Array(buffer);
float64[1] = 42;
......@@ -275,5 +313,8 @@ export class TFloat64Array {
let res = buffer.slice(8);
let sliced = new Float64Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import {
export class TInt16Array {
test() {
// #ifdef APP-ANDROID
this.testConstructor();
this.testSet();
this.testCopyWith();
......@@ -30,9 +31,10 @@ export class TInt16Array {
this.subarray();
this.values();
this.arrayBufferSlice();
// #endif
}
// #ifdef APP-ANDROID
testConstructor() {
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
......@@ -41,29 +43,32 @@ export class TInt16Array {
}
testSet() {
// #TEST Int16Array.set
let int16 = new Int16Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3];
int16.set(array, 1);
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Int16Array.copyWithin
let int16 = new Int16Array(8);
int16.set([1, 2, 3], 1);
console.log("testCopyWith 1")
int16.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Int16Array): boolean => currentValue < 40;
let result = new Int16Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int16Array) : boolean => value < 40); //
// #TEST Int16Array.every
let result = new Int16Array([12, 5, 8, 130, 44]).every((value, _, _a:Int16Array):boolean => value < 40);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Int16Array.fill
let int16 = new Int16Array([1, 2, 3]).fill(4);
expect(int16.toString()).toEqual("4,4,4");
......@@ -78,44 +83,54 @@ export class TInt16Array {
int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
expect(int16.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let int16 = new Int16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int16Array) : boolean => value >= 10);
// #TEST Int16Array.filter
let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a:Int16Array):boolean => value >= 10);
expect(int16.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Int16Array.find
let int16 = new Int16Array([4, 5, 8, 12]);
let res = int16.find((value : number, _ : number, _a : Int16Array) : boolean => value > 5);
let res = int16.find((value, _, _a:Int16Array):boolean => value > 5);
expect(res).toEqual(8);
// #END
}
findIndex() {
// #TEST Int16Array.findIndex
let int16 = new Int16Array([4, 6, 8, 12]);
let res = int16.findIndex((value : number, _ : number, _a : Int16Array) : boolean => value > 100);
let res = int16.findIndex((value, _, _a:Int16Array):boolean => value > 100);
expect(res).toEqual(-1);
int16 = new Int16Array([4, 6, 7, 120]);
res = int16.findIndex((value : number, _ : number, _a : Int16Array) : boolean => value > 100);
res = int16.findIndex((value, _, _a:Int16Array):boolean => value > 100);
expect(res).toEqual(3);
// #END
}
foreach() {
new Int16Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int16Array) => {
// #TEST Int16Array.forEach
new Int16Array([0, 1, 2, 3]).forEach((value, index, _:Int16Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Int16Array.entries
let arr = new Int16Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
// #END
}
includes() {
// #TEST Int16Array.includes
let int16 = new Int16Array([1, 2, 3]);
let res = int16.includes(2);
expect(res).toEqual(true);
......@@ -125,9 +140,11 @@ export class TInt16Array {
res = int16.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Int16Array.indexOf
let int16 = new Int16Array([2, 5, 9]);
let res = int16.indexOf(2);
expect(res).toEqual(0);
......@@ -143,9 +160,11 @@ export class TInt16Array {
res = int16.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Int16Array.join
let int16 = new Int16Array([1, 2, 3]);
let res = int16.join();
expect(res).toEqual("1,2,3");
......@@ -155,9 +174,11 @@ export class TInt16Array {
res = int16.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Int16Array.keys
let arr = new Int16Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
......@@ -165,42 +186,52 @@ export class TInt16Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
// #END
}
map() {
// #TEST Int16Array.map
let numbers = new Int16Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Int16Array) : number => value * 2);
let doubles = numbers.map((value, _, _a:Int16Array):number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Int16Array.reduce
let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int16Array) : number => accumulator + currentValue);
let res = total.reduce((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue);
expect(res).toEqual(6);
total = new Int16Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int16Array) : number => accumulator + currentValue, 8);
res = total.reduce((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Int16Array.reduceRight
let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int16Array) : number => accumulator + currentValue);
let res = total.reduceRight((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue);
expect(res).toEqual(6);
total = new Int16Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int16Array) : number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator, currentValue, _, _a:Int16Array):number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Int16Array.reverse
let int16 = new Int16Array([1, 2, 3]);
int16.reverse();
expect(int16.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Int16Array.slice
let int16 = new Int16Array([1, 2, 3]);
let res = int16.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -213,18 +244,22 @@ export class TInt16Array {
res = int16.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Int16Array.sort
let numbers = new Int16Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Int16Array.subarray
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
int16.set([1, 2, 3]);
......@@ -232,15 +267,19 @@ export class TInt16Array {
let sub = int16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Int16Array.values
let arr = new Int16Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int16Array
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
int16[4] = 42;
......@@ -249,5 +288,8 @@ export class TInt16Array {
let res = buffer.slice(8, 12);
let sliced = new Int16Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ export class TInt32Array {
// #endif
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testInt32Array() {
let int32 = new Int32Array(2);
int32[0] = 42;
......@@ -63,13 +63,16 @@ export class TInt32Array {
}
testSet() {
// #TEST Int32Array.set
let int32 = new Int32Array(8);
var array =[1, 2, 3]
var array = [1, 2, 3]
int32.set(array, 1);
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
// #TEST Int32Array.copyWithin
console.log("testCopyWith 1")
let int32 = new Int32Array(8);
int32.set([1, 2, 3], 1);
......@@ -77,15 +80,18 @@ export class TInt32Array {
int32.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Int32Array): boolean => currentValue < 40;
let result = new Int32Array([12, 5, 8, 130, 44]).every((value:number,_ : number, _a : Int32Array): boolean => value< 40); //
// #TEST Int32Array.every
let result = new Int32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int32Array) : boolean => value < 40);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Int32Array.fill
let int32 = new Int32Array([1, 2, 3]).fill(4);
expect(int32.toString()).toEqual("4,4,4");
......@@ -100,45 +106,54 @@ export class TInt32Array {
int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
expect(int32.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array): boolean => value>= 10);
// #TEST Int32Array.filter
let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array) : boolean => value >= 10);
expect(int32.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Int32Array.find
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);
// #END
}
findIndex() {
// #TEST Int32Array.findIndex
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);
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);
// #END
}
foreach() {
// #TEST Int32Array.forEach
new Int32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int32Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Int32Array.entries
let arr = new Int32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
// #END
}
includes() {
// #TEST Int32Array.includes
let int32 = new Int32Array([1, 2, 3]);
let res = int32.includes(2);
expect(res).toEqual(true);
......@@ -148,9 +163,11 @@ export class TInt32Array {
res = int32.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Int32Array.indexOf
let int32 = new Int32Array([2, 5, 9]);
let res = int32.indexOf(2);
expect(res).toEqual(0);
......@@ -166,9 +183,11 @@ export class TInt32Array {
res = int32.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Int32Array.join
let int32 = new Int32Array([1, 2, 3]);
let res = int32.join();
expect(res).toEqual("1,2,3");
......@@ -178,48 +197,60 @@ export class TInt32Array {
res = int32.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Int32Array.keys
let arr = new Int32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
// #END
}
map() {
// #TEST Int32Array.map
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);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Int32Array.reduce
let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array): number => accumulator + currentValue);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array): number => accumulator + currentValue, 8);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Int32Array.reduceRight
let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue : number, _ : number, _a : Int32Array): number => accumulator + currentValue);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue : number, _ : number, _a : Int32Array): number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Int32Array.reverse
let int32 = new Int32Array([1, 2, 3]);
int32.reverse();
expect(int32.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Int32Array.slice
let int32 = new Int32Array([1, 2, 3]);
let res = int32.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -232,18 +263,22 @@ export class TInt32Array {
res = int32.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Int32Array.sort
let numbers = new Int32Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Int32Array.subarray
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
int32.set([1, 2, 3]);
......@@ -251,15 +286,19 @@ export class TInt32Array {
let sub = int32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Int32Array.values
let arr = new Int32Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
int32[3] = 42;
......@@ -268,6 +307,8 @@ export class TInt32Array {
let res = buffer.slice(8);
let sliced = new Int32Array(res);
expect(sliced[1]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import {
export class TInt8Array {
test() {
// #ifdef APP-ANDROID
this.testConstructor();
this.testSet();
this.testCopyWith();
......@@ -31,9 +32,10 @@ export class TInt8Array {
this.subarray();
this.values();
this.arrayBufferSlice();
//#endif
}
// #ifdef APP-ANDROID
testConstructor() {
let buffer = new ArrayBuffer(16);
let int8View = new Int8Array(buffer);
......@@ -42,30 +44,35 @@ export class TInt8Array {
}
testSet() {
// #TEST Int8Array.set
let int8 = new Int8Array(8);
var array = [1, 2, 3]
int8.set(array, 1);
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Int8Array.copyWith
let int8 = new Int8Array(8);
int8.set([1, 2, 3], 1);
console.log("testCopyWith 1")
int8.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// #TEST Int8Array.every
// 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 =>
value < 40); //
let result = new Int8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int8Array) : boolean =>
value < 40);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Int8Array.fill
let int8 = new Int8Array([1, 2, 3]).fill(4);
expect(int8.toString()).toEqual("4,4,4");
......@@ -80,46 +87,58 @@ export class TInt8Array {
int8 = new Int8Array([1, 2, 3]).fill(4, -3, -2);
expect(int8.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// #TEST Int8Array.filter
// 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);
expect(int8.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Int8Array.find
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);
// #END
}
findIndex() {
// #TEST Int8Array.findIndex
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);
int8 = new Int8Array([4, 6, 7, 120]);
res = int8.findIndex((value: number, _: number, _a: Int8Array): boolean => value > 100);
res = int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100);
expect(res).toEqual(3);
// #END
}
foreach() {
new Int8Array([0, 1, 2, 3]).forEach((value: number, index: number, _: Int8Array) => {
// #TEST Int8Array.forEach
new Int8Array([0, 1, 2, 3]).forEach((value : number, index : number, _a : Int8Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Int8Array.entries
let arr = new Int8Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
// #END
}
includes() {
// #TEST Int8Array.includes
let int8 = new Int8Array([1, 2, 3]);
let res = int8.includes(2);
expect(res).toEqual(true);
......@@ -129,9 +148,11 @@ export class TInt8Array {
res = int8.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Int8Array.indexOf
let int8 = new Int8Array([2, 5, 9]);
let res = int8.indexOf(2);
expect(res).toEqual(0);
......@@ -147,9 +168,11 @@ export class TInt8Array {
res = int8.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Int8Array.join
let int8 = new Int8Array([1, 2, 3]);
let res = int8.join();
expect(res).toEqual("1,2,3");
......@@ -159,9 +182,11 @@ export class TInt8Array {
res = int8.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Int8Array.keys
let arr = new Int8Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
......@@ -169,47 +194,57 @@ export class TInt8Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
// #END
}
map() {
// #TEST Int8Array.map
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);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Int8Array.reduce
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);
expect(res).toEqual(6);
total = new Int8Array([0, 1, 2, 3]);
res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Int8Array): number =>
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Int8Array.reduceRight
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);
expect(res).toEqual(6);
total = new Int8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Int8Array):
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Int8Array.reverse
let int8 = new Int8Array([1, 2, 3]);
int8.reverse();
expect(int8.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Int8Array.slice
let int8 = new Int8Array([1, 2, 3]);
let res = int8.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -222,18 +257,22 @@ export class TInt8Array {
res = int8.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Int8Array.sort
let numbers = new Int8Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Int8Array.subarray
let buffer = new ArrayBuffer(8);
let int8 = new Int8Array(buffer);
int8.set([1, 2, 3]);
......@@ -241,24 +280,31 @@ export class TInt8Array {
let sub = int8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Int8Array.values
let arr = new Int8Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int8Array
let buffer = new ArrayBuffer(16);
let int8 = new Int8Array(buffer);
int8[4] = 42;
expect(int8.toString()).toEqual("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, 5);
let sliced = new Int8Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import {
export class TUint8Array {
test() {
// #ifdef APP-ANDROID
this.testMAX();
this.testConstructor();
this.testSet();
......@@ -31,7 +32,9 @@ export class TUint8Array {
this.subarray();
this.values();
this.arrayBufferSlice();
// #endif
}
// #ifdef APP-ANDROID
from() {
var s = new Set([1, 2, 3]);
var unit8 = Uint8Array.from(s);
......@@ -52,29 +55,36 @@ export class TUint8Array {
}
testSet() {
// #TEST Uint8Array.set
let uint8 = new Uint8Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3];
uint8.set(array, 1);
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Uint8Array.copyWithin
console.log("testCopyWith 1");
let uint8 = new Uint8Array(8);
uint8.set([1, 2, 3], 1);
uint8.copyWithin(3, 0, 3);
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// 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 =>
value < 40); //
// #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 =>
value < 40);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Uint8Array.fill
let uint8 = new Uint8Array([1, 2, 3]).fill(4);
expect(uint8.toString()).toEqual("4,4,4");
......@@ -89,46 +99,54 @@ export class TUint8Array {
uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
expect(uint8.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// #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");
// #END
}
find() {
// #TEST Uint8Array.find
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);
// #END
}
findIndex() {
// #TEST Uint8Array.findIndex
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);
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);
// #END
}
foreach() {
new Uint8Array([0, 1, 2, 3]).forEach((value: number, index: number, _: Uint8Array) => {
// #TEST Uint8Array.forEach
new Uint8Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Uint8Array.entries
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
// #END
}
includes() {
// #TEST Uint8Array.includes
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.includes(2);
expect(res).toEqual(true);
......@@ -138,9 +156,11 @@ export class TUint8Array {
res = uint8.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Uint8Array.indexOf
let uint8 = new Uint8Array([2, 5, 9]);
let res = uint8.indexOf(2);
expect(res).toEqual(0);
......@@ -156,9 +176,11 @@ export class TUint8Array {
res = uint8.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Uint8Array.join
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.join();
expect(res).toEqual("1,2,3");
......@@ -168,52 +190,62 @@ export class TUint8Array {
res = uint8.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Uint8Array.keys
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
// #END
}
map() {
// #TEST Uint8Array.map
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);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Uint8Array.reduce
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Uint8Array): number =>
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
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 => accumulator +
currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Uint8Array.reduceRight
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Uint8Array): number =>
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
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);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Uint8Array.reverse
let uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse();
expect(uint8.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Uint8Array.slice
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -226,18 +258,22 @@ export class TUint8Array {
res = uint8.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Uint8Array.sort
let numbers = new Uint8Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Uint8Array.subarray
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]);
......@@ -245,16 +281,19 @@ export class TUint8Array {
let sub = uint8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Uint8Array.values
let arr = new Uint8Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Uint8Array
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
uint8[4] = 42;
......@@ -263,5 +302,8 @@ export class TUint8Array {
let res = buffer.slice(4, 12);
let sliced = new Uint8Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import {
export class TUint8ClampedArray {
test() {
// #ifdef APP-ANDROID
this.testMAX();
this.testConstructor();
this.testSet();
......@@ -31,8 +32,10 @@ export class TUint8ClampedArray {
this.subarray();
this.values();
this.arrayBufferSlice();
// #endif
}
// #ifdef APP-ANDROID
testMAX() {
let uint8Clamped = new Uint8ClampedArray(16);
uint8Clamped[0] = 255;
......@@ -47,29 +50,36 @@ export class TUint8ClampedArray {
}
testSet() {
// #TEST Uint8ClampedArray.set
let uint8Clamped = new Uint8ClampedArray(8);
var array = [1, 2, 3]
var array = [1, 2, 3];
uint8Clamped.set(array, 1);
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
// #TEST Uint8ClampedArray.copyWithin
console.log("testCopyWith 1")
let uint8Clamped = new Uint8ClampedArray(8);
uint8Clamped.set([1, 2, 3], 1);
uint8Clamped.copyWithin(3, 0, 3);
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// #TEST Uint8ClampedArray.every
// 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:
Uint8ClampedArray): boolean => value < 40); //
let result = new Uint8ClampedArray([12, 5, 8, 130, 44]).every((value : number, _ : number, _a :
Uint8ClampedArray) : boolean => value < 40); //
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Uint8ClampedArray.fill
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4);
expect(uint8Clamped.toString()).toEqual("4,4,4");
......@@ -84,46 +94,58 @@ export class TUint8ClampedArray {
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2);
expect(uint8Clamped.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// #TEST Uint8ClampedArray.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value: number, _: number, _a:
Uint8ClampedArray): boolean => value >= 10);
let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value : number, _ : number, _a :
Uint8ClampedArray) : boolean => value >= 10);
expect(uint8Clamped.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Uint8ClampedArray.find
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);
// #END
}
findIndex() {
// #TEST Uint8ClampedArray.findIndex
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);
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);
// #END
}
foreach() {
new Uint8ClampedArray([0, 1, 2, 3]).forEach((value: number, index: number, _: Uint8ClampedArray) => {
// #TEST Uint8ClampedArray.forEach
new Uint8ClampedArray([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8ClampedArray) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Uint8ClampedArray.entries
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
// #END
}
includes() {
// #TEST Uint8ClampedArray.includes
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.includes(2);
expect(res).toEqual(true);
......@@ -133,9 +155,11 @@ export class TUint8ClampedArray {
res = uint8Clamped.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Uint8ClampedArray.indexOf
let uint8Clamped = new Uint8ClampedArray([2, 5, 9]);
let res = uint8Clamped.indexOf(2);
expect(res).toEqual(0);
......@@ -151,9 +175,10 @@ export class TUint8ClampedArray {
res = uint8Clamped.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Uint8ClampedArray.join
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.join();
expect(res).toEqual("1,2,3");
......@@ -163,52 +188,63 @@ export class TUint8ClampedArray {
res = uint8Clamped.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Uint8ClampedArray.keys
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
// #END
}
map() {
// #TEST Uint8ClampedArray.map
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");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Uint8ClampedArray.reduce
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduce((accumulator: number, currentValue: number, _: number, _a:
Uint8ClampedArray): number => accumulator + currentValue);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Uint8ClampedArray):
number => accumulator + currentValue, 8);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Uint8ClampedArray.reduceRight
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a:
Uint8ClampedArray): number => accumulator + currentValue);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a:
Uint8ClampedArray): number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Uint8ClampedArray.reverse
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
uint8Clamped.reverse();
expect(uint8Clamped.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Uint8ClampedArray.slice
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -221,18 +257,21 @@ export class TUint8ClampedArray {
res = uint8Clamped.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Uint8ClampedArray.sort
let numbers = new Uint8ClampedArray([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Uint8ClampedArray.subarray
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped.set([1, 2, 3]);
......@@ -240,16 +279,19 @@ export class TUint8ClampedArray {
let sub = uint8Clamped.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Uint8ClampedArray.values
let arr = new Uint8ClampedArray([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Uint8ClampedArray
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped[4] = 42;
......@@ -258,5 +300,8 @@ export class TUint8ClampedArray {
let res = buffer.slice(4, 12);
let sliced = new Uint8ClampedArray(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -63,30 +63,36 @@ export class TUint16Array {
}
testSet() {
// #TEST Uint16Array.set
let uint16 = new Uint16Array(8);
var array = [1, 2, 3]
uint16.set(array, 1);
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
// #TEST Uint16Array.copyWith
console.log("testCopyWith 1")
let uint16 = new Uint16Array(8);
uint16.set([1, 2, 3], 1);
console.log("testCopyWith 1")
console.log("testCopyWith 2")
uint16.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
console.log("testCopyWith 3")
expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// 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):
boolean => value < 40); //
// #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) :
boolean => value < 40);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Uint16Array.fill
let uint16 = new Uint16Array([1, 2, 3]).fill(4);
expect(uint16.toString()).toEqual("4,4,4");
......@@ -101,46 +107,57 @@ export class TUint16Array {
uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2);
expect(uint16.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// #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);
expect(uint16.toString()).toEqual("12,44");
// #END
}
find() {
// #TEST Uint16Array.find
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);
// #END
}
findIndex() {
// #TEST Uint16Array.findIndex
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);
expect(res).toEqual(-1);
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);
// #END
}
foreach() {
new Uint16Array([0, 1, 2, 3]).forEach((value: number, index: number, _a: Uint16Array) => {
// #TEST Uint16Array.forEach
new Uint16Array([0, 1, 2, 3]).forEach((value : number, index : number, _a : Uint16Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Uint16Array.entries
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
// #END
}
includes() {
// #TEST Uint16Array.includes
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.includes(2);
expect(res).toEqual(true);
......@@ -150,9 +167,10 @@ export class TUint16Array {
res = uint16.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Uint16Array.indexOf
let uint16 = new Uint16Array([2, 5, 9]);
let res = uint16.indexOf(2);
expect(res).toEqual(0);
......@@ -168,9 +186,11 @@ export class TUint16Array {
res = uint16.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Uint16Array.join
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.join();
expect(res).toEqual("1,2,3");
......@@ -180,52 +200,65 @@ export class TUint16Array {
res = uint16.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Uint16Array.keys
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
// #END
}
map() {
// #TEST Uint16Array.map
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);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Uint16Array.reduce
let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Uint16Array):
number => accumulator + currentValue);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]);
res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Uint16Array):
number => accumulator + currentValue, 8);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Uint16Array.reduceRight
let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Uint16Array):
number => accumulator + currentValue);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Uint16Array):
number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Uint16Array.reverse
let uint16 = new Uint16Array([1, 2, 3]);
uint16.reverse();
expect(uint16.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Uint16Array.slice
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -238,18 +271,21 @@ export class TUint16Array {
res = uint16.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Uint16Array.sort
let numbers = new Uint16Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Uint16Array.subarray
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
uint16.set([1, 2, 3]);
......@@ -257,16 +293,19 @@ export class TUint16Array {
let sub = uint16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Uint16Array.values
let arr = new Uint16Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
// #END
}
arrayBufferSlice() {
// #TEST Uint16Array.arrayBufferSlice
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
uint16[4] = 42;
......@@ -275,7 +314,9 @@ export class TUint16Array {
let res = buffer.slice(8);
let sliced = new Uint16Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ export class TUint32Array {
// #endif
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testuint32() {
let uint32 = new Uint32Array(2);
uint32[0] = 42;
......@@ -63,30 +63,36 @@ export class TUint32Array {
}
testSet() {
// #TEST Uint32Array.set
let uint32 = new Uint32Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3];
uint32.set(array, 1);
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Uint32Array.copyWithin
console.log("testCopyWith 1");
let uint32 = new Uint32Array(8);
uint32.set([1, 2, 3], 1);
console.log("testCopyWith 1")
console.log("testCopyWith 1");
uint32.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
console.log("testCopyWith 1");
expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
testEvery() {
// 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); //
// #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);
expect(result).toEqual(false);
// #END
}
testFill() {
// #TEST Uint32Array.fill
let uint32 = new Uint32Array([1, 2, 3]).fill(4);
expect(uint32.toString()).toEqual("4,4,4");
......@@ -101,46 +107,53 @@ export class TUint32Array {
uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2);
expect(uint32.toString()).toEqual("4,2,3");
// #END
}
testFilter() {
// #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");
// #END
}
find() {
// #TEST Uint32Array.find
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);
// #END
}
findIndex() {
// #TEST Uint32Array.findIndex
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);
let uuint32 = new Uint32Array([4, 6, 7, 120]);
res = uuint32.findIndex((value: number, _: number, _a: Uint32Array): boolean => value > 100);
res = uuint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
expect(res).toEqual(3);
// #END
}
foreach() {
new Uint32Array([0, 1, 2, 3]).forEach((value: number, index: number, _a: Uint32Array) => {
// #TEST Uint32Array.forEach
new Uint32Array([0, 1, 2, 3]).forEach((value : number, index : number, _a : Uint32Array) => {
console.log(`a[${index}] = ${value}`);
});
// #END
}
iterator() {
// #TEST Uint32Array.entries
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
// #END
}
includes() {
// #TEST Uint32Array.includes
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.includes(2);
expect(res).toEqual(true);
......@@ -150,9 +163,11 @@ export class TUint32Array {
res = uint32.includes(3, 3);
expect(res).toEqual(false);
// #END
}
indexOf() {
// #TEST Uint32Array.indexOf
let uint32 = new Uint32Array([2, 5, 9]);
let res = uint32.indexOf(2);
expect(res).toEqual(0);
......@@ -168,9 +183,10 @@ export class TUint32Array {
res = uint32.indexOf(2, -3);
expect(res).toEqual(0);
// #END
}
join() {
// #TEST Uint32Array.join
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.join();
expect(res).toEqual("1,2,3");
......@@ -180,52 +196,63 @@ export class TUint32Array {
res = uint32.join("");
expect(res).toEqual("123");
// #END
}
keys() {
// #TEST Uint32Array.keys
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
// #END
}
map() {
// #TEST Uint32Array.map
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");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Uint32Array.reduce
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);
expect(res).toEqual(6);
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);
expect(res).toEqual(14);
// #END
}
reduceRight() {
// #TEST Uint32Array.reduceRight
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);
expect(res).toEqual(6);
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);
expect(res).toEqual(14);
// #END
}
reverse() {
// #TEST Uint32Array.reverse
let uint32 = new Uint32Array([1, 2, 3]);
uint32.reverse();
expect(uint32.toString()).toEqual("3,2,1");
// #END
}
slice() {
// #TEST Uint32Array.slice
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.slice(1);
expect(res.toString()).toEqual("2,3");
......@@ -238,18 +265,21 @@ export class TUint32Array {
res = uint32.slice(0, 1);
expect(res.toString()).toEqual("1");
// #END
}
sort() {
// #TEST Uint32Array.sort
let numbers = new Uint32Array([40, 1, 5]);
numbers.sort();
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");
// #END
}
subarray() {
// #TEST Uint32Array.subarray
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
uint32.set([1, 2, 3]);
......@@ -257,16 +287,19 @@ export class TUint32Array {
let sub = uint32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
values() {
// #TEST Uint32Array.values
let arr = new Uint32Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
// #END
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
uint32[3] = 42;
......@@ -275,6 +308,8 @@ export class TUint32Array {
let res = buffer.slice(8);
let sliced = new Uint32Array(res);
expect(sliced[1]).toEqual(42);
// #END
}
// #endif
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册