提交 f62fd355 编写于 作者: M mahaifeng

[array-buffer]修改命名

上级 bdc81394
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
export class TFloat32Array { export class TFloat32Array {
test() { test() {
// #ifdef APP-ANDROID
this.testfloat32(); this.testfloat32();
this.testConstructor(); this.testConstructor();
this.testSet(); this.testSet();
...@@ -31,10 +32,12 @@ export class TFloat32Array { ...@@ -31,10 +32,12 @@ export class TFloat32Array {
this.subarray(); this.subarray();
this.values(); this.values();
this.arrayBufferSlice(); this.arrayBufferSlice();
// #endif
} }
from(){ // #ifdef APP-ANDROID
var float32Array= Float32Array.from([1, 2, 3], (v: number, _: number):number => v + v); from() {
expect(float32Array.toString()).toEqual('2,4,6'); var float32Array = Float32Array.from([1, 2, 3], (v : number, _ : number) : number => v + v);
expect(float32Array.toString()).toEqual('2,4,6');
} }
testfloat32() { testfloat32() {
...@@ -85,7 +88,7 @@ export class TFloat32Array { ...@@ -85,7 +88,7 @@ export class TFloat32Array {
testEvery() { testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Float32Array): boolean => currentValue < 40; // 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): let result = new Float32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Float32Array) :
boolean => value < 40); // boolean => value < 40); //
expect(result).toEqual(false); expect(result).toEqual(false);
} }
...@@ -110,29 +113,29 @@ export class TFloat32Array { ...@@ -110,29 +113,29 @@ export class TFloat32Array {
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Float32Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Float32Array): let float32 = new Float32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float32Array) :
boolean => value >= 10); boolean => value >= 10);
expect(float32.toString()).toEqual("12,44"); expect(float32.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Float32Array([4, 5, 8, 12]); let float32 = new Float32Array([4, 5, 8, 12]);
let res = float32.find((value: number, _: number, _a: Float32Array): boolean => value > 5); let res = float32.find((value : number, _ : number, _a : Float32Array) : boolean => value > 5);
expect(res).toEqual(8); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Float32Array([4, 6, 8, 12]); let float32 = new Float32Array([4, 6, 8, 12]);
let res = float32.findIndex((value: number, _: number, _a: Float32Array): boolean => value > 100); let res = float32.findIndex((value : number, _ : number, _a : Float32Array) : boolean => value > 100);
expect(res).toEqual(-1); expect(res).toEqual(-1);
let ufloat32 = new Float32Array([4, 6, 7, 120]); let ufloat32 = new Float32Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Float32Array): boolean => value > 100); res = ufloat32.findIndex((value : number, _ : number, _a : Float32Array) : boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
foreach() { foreach() {
new Float32Array([0, 1, 2, 3]).forEach((value: number,index: number, _: Float32Array) => { new Float32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Float32Array) => {
console.log(`a[${index}] = ${value}`); console.log(`a[${index}] = ${value}`);
}); });
} }
...@@ -198,31 +201,31 @@ export class TFloat32Array { ...@@ -198,31 +201,31 @@ export class TFloat32Array {
map() { map() {
let numbers = new Float32Array([1, 4, 9]); let numbers = new Float32Array([1, 4, 9]);
let doubles = numbers.map((value: number, _: number, _a: Float32Array): number => value * 2); let doubles = numbers.map((value : number, _ : number, _a : Float32Array) : number => value * 2);
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");
} }
reduce() { reduce() {
let total = new Float32Array([0, 1, 2, 3]); let total = new Float32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Float32Array): let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) :
number => accumulator + currentValue); number => accumulator + currentValue);
expect(res).toEqual(6); expect(res).toEqual(6);
total = new Float32Array([0, 1, 2, 3]); total = new Float32Array([0, 1, 2, 3]);
res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Float32Array): res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float32Array) :
number => accumulator + currentValue, 8); number => accumulator + currentValue, 8);
expect(res).toEqual(14); expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
let total = new Float32Array([0, 1, 2, 3]); let total = new Float32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a :
Float32Array): number => accumulator + currentValue); Float32Array) : number => accumulator + currentValue);
expect(res).toEqual(6); expect(res).toEqual(6);
total = new Float32Array([0, 1, 2, 3]); total = new Float32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Float32Array): res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float32Array) :
number => accumulator + currentValue, 8); number => accumulator + currentValue, 8);
expect(res).toEqual(14); expect(res).toEqual(14);
} }
...@@ -253,7 +256,7 @@ export class TFloat32Array { ...@@ -253,7 +256,7 @@ export class TFloat32Array {
numbers.sort(); numbers.sort();
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"); expect(numbers.toString()).toEqual("1,5,40");
} }
...@@ -285,4 +288,5 @@ export class TFloat32Array { ...@@ -285,4 +288,5 @@ export class TFloat32Array {
let sliced = new Float32Array(res); let sliced = new Float32Array(res);
expect(sliced[1]).toEqual(42); expect(sliced[1]).toEqual(42);
} }
// #endif
} }
\ No newline at end of file
...@@ -34,10 +34,10 @@ export class TFloat64Array { ...@@ -34,10 +34,10 @@ export class TFloat64Array {
} }
testfloat64() { testfloat64() {
let float32 = new Float64Array(2); let float64 = new Float64Array(2);
float32[0] = 42; float64[0] = 42;
expect(float32[0]).toEqual(42); expect(float64[0]).toEqual(42);
expect(float32.length).toEqual(2); expect(float64.length).toEqual(2);
expect(Float64Array.BYTES_PER_ELEMENT).toEqual(8); expect(Float64Array.BYTES_PER_ELEMENT).toEqual(8);
let x = new Float64Array([21, 31, 3]); let x = new Float64Array([21, 31, 3]);
...@@ -54,23 +54,23 @@ export class TFloat64Array { ...@@ -54,23 +54,23 @@ export class TFloat64Array {
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Float64Array(buffer); let float64 = new Float64Array(buffer);
float32[1] = 42; float64[1] = 42;
expect(float32.toString()).toEqual("0,42"); expect(float64.toString()).toEqual("0,42");
} }
testSet() { testSet() {
let float32 = new Float64Array(8); let float64 = new Float64Array(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); float64.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
let float32 = new Float64Array(8); let float64 = new Float64Array(8);
float32.set([1, 2, 3], 1); float64.set([1, 2, 3], 1);
float32.copyWithin(3, 0, 3); float64.copyWithin(3, 0, 3);
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -81,43 +81,43 @@ export class TFloat64Array { ...@@ -81,43 +81,43 @@ export class TFloat64Array {
} }
testFill() { testFill() {
let float32 = new Float64Array([1, 2, 3]).fill(4); let float64 = new Float64Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(float64.toString()).toEqual("4,4,4");
float32 = new Float64Array([1, 2, 3]).fill(4, 1); float64 = new Float64Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(float64.toString()).toEqual("1,4,4");
float32 = new Float64Array([1, 2, 3]).fill(4, 1, 2); float64 = new Float64Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(float64.toString()).toEqual("1,4,3");
float32 = new Float64Array([1, 2, 3]).fill(4, 1, 1); float64 = new Float64Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(float64.toString()).toEqual("1,2,3");
float32 = new Float64Array([1, 2, 3]).fill(4, -3, -2); float64 = new Float64Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(float64.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Float64Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Float64Array): let float64 = new Float64Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Float64Array):
boolean => value >= 10); boolean => value >= 10);
expect(float32.toString()).toEqual("12,44"); expect(float64.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Float64Array([4, 5, 8, 12]); let float64 = new Float64Array([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Float64Array([4, 6, 8, 12]); let float64 = new Float64Array([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Float64Array([4, 6, 7, 120]); let ufloat64 = new Float64Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Float64Array): boolean => value > 100); res = ufloat64.findIndex((value: number, _: number, _a: Float64Array): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -135,44 +135,44 @@ export class TFloat64Array { ...@@ -135,44 +135,44 @@ export class TFloat64Array {
} }
includes() { includes() {
let float32 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
let res = float32.includes(2); let res = float64.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = float64.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = float64.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Float64Array([2, 5, 9]); let float64 = new Float64Array([2, 5, 9]);
let res = float32.indexOf(2); let res = float64.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = float64.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = float64.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = float64.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = float64.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
let res = float32.join(); let res = float64.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = float64.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = float64.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -219,23 +219,23 @@ export class TFloat64Array { ...@@ -219,23 +219,23 @@ export class TFloat64Array {
} }
reverse() { reverse() {
let float32 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
float32.reverse(); float64.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(float64.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Float64Array([1, 2, 3]); let float64 = new Float64Array([1, 2, 3]);
let res = float32.slice(1); let res = float64.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = float64.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = float64.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = float64.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -250,11 +250,11 @@ export class TFloat64Array { ...@@ -250,11 +250,11 @@ export class TFloat64Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(32); let buffer = new ArrayBuffer(32);
let float32 = new Float64Array(buffer); let float64 = new Float64Array(buffer);
float32.set([1, 2, 3]); float64.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0"); expect(float64.toString()).toEqual("1,2,3,0");
let sub = float32.subarray(0, 4); let sub = float64.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -268,9 +268,9 @@ export class TFloat64Array { ...@@ -268,9 +268,9 @@ export class TFloat64Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Float64Array(buffer); let float64 = new Float64Array(buffer);
float32[1] = 42; float64[1] = 42;
expect(float32.toString()).toEqual("0,42"); expect(float64.toString()).toEqual("0,42");
let res = buffer.slice(8); let res = buffer.slice(8);
let sliced = new Float64Array(res); let sliced = new Float64Array(res);
......
...@@ -35,26 +35,26 @@ export class TInt16Array { ...@@ -35,26 +35,26 @@ export class TInt16Array {
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int16Array(buffer); let int16 = new Int16Array(buffer);
float32[5] = 42; int16[5] = 42;
expect(float32.toString()).toEqual("0,0,0,0,0,42,0,0"); expect(int16.toString()).toEqual("0,0,0,0,0,42,0,0");
} }
testSet() { testSet() {
let float32 = new Int16Array(8); let int16 = new Int16Array(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); int16.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Int16Array(8); let int16 = new Int16Array(8);
float32.set([1, 2, 3], 1); int16.set([1, 2, 3], 1);
console.log("testCopyWith 1") console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3); int16.copyWithin(3, 0, 3);
console.log("testCopyWith 1") console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -64,42 +64,42 @@ export class TInt16Array { ...@@ -64,42 +64,42 @@ export class TInt16Array {
} }
testFill() { testFill() {
let float32 = new Int16Array([1, 2, 3]).fill(4); let int16 = new Int16Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(int16.toString()).toEqual("4,4,4");
float32 = new Int16Array([1, 2, 3]).fill(4, 1); int16 = new Int16Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(int16.toString()).toEqual("1,4,4");
float32 = new Int16Array([1, 2, 3]).fill(4, 1, 2); int16 = new Int16Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(int16.toString()).toEqual("1,4,3");
float32 = new Int16Array([1, 2, 3]).fill(4, 1, 1); int16 = new Int16Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(int16.toString()).toEqual("1,2,3");
float32 = new Int16Array([1, 2, 3]).fill(4, -3, -2); int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(int16.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Int16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int16Array) : boolean => value >= 10); let int16 = new Int16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int16Array) : boolean => value >= 10);
expect(float32.toString()).toEqual("12,44"); expect(int16.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Int16Array([4, 5, 8, 12]); let int16 = new Int16Array([4, 5, 8, 12]);
let res = float32.find((value : number, _ : number, _a : Int16Array) : boolean => value > 5); let res = int16.find((value : number, _ : number, _a : Int16Array) : boolean => value > 5);
expect(res).toEqual(8); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Int16Array([4, 6, 8, 12]); let int16 = new Int16Array([4, 6, 8, 12]);
let res = float32.findIndex((value : number, _ : number, _a : Int16Array) : boolean => value > 100); let res = int16.findIndex((value : number, _ : number, _a : Int16Array) : boolean => value > 100);
expect(res).toEqual(-1); expect(res).toEqual(-1);
let ufloat32 = new Int16Array([4, 6, 7, 120]); int16 = new Int16Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value : number, _ : number, _a : Int16Array) : boolean => value > 100); res = int16.findIndex((value : number, _ : number, _a : Int16Array) : boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -116,44 +116,44 @@ export class TInt16Array { ...@@ -116,44 +116,44 @@ export class TInt16Array {
} }
includes() { includes() {
let float32 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
let res = float32.includes(2); let res = int16.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = int16.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = int16.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Int16Array([2, 5, 9]); let int16 = new Int16Array([2, 5, 9]);
let res = float32.indexOf(2); let res = int16.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = int16.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = int16.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = int16.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = int16.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
let res = float32.join(); let res = int16.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = int16.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = int16.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -195,23 +195,23 @@ export class TInt16Array { ...@@ -195,23 +195,23 @@ export class TInt16Array {
} }
reverse() { reverse() {
let float32 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
float32.reverse(); int16.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(int16.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Int16Array([1, 2, 3]); let int16 = new Int16Array([1, 2, 3]);
let res = float32.slice(1); let res = int16.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = int16.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = int16.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = int16.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -226,11 +226,11 @@ export class TInt16Array { ...@@ -226,11 +226,11 @@ export class TInt16Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int16Array(buffer); let int16 = new Int16Array(buffer);
float32.set([1, 2, 3]); int16.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0,0,0,0,0"); expect(int16.toString()).toEqual("1,2,3,0,0,0,0,0");
let sub = float32.subarray(0, 4); let sub = int16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -242,9 +242,9 @@ export class TInt16Array { ...@@ -242,9 +242,9 @@ export class TInt16Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int16Array(buffer); let int16 = new Int16Array(buffer);
float32[4] = 42; int16[4] = 42;
expect(float32.toString()).toEqual("0,0,0,0,42,0,0,0"); expect(int16.toString()).toEqual("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);
......
...@@ -7,7 +7,8 @@ import { ...@@ -7,7 +7,8 @@ import {
export class TInt32Array { export class TInt32Array {
test() { test() {
this.testfloat32(); // #ifdef APP-ANDROID
this.testInt32Array();
this.testConstructor(); this.testConstructor();
this.testSet(); this.testSet();
this.testCopyWith(); this.testCopyWith();
...@@ -31,13 +32,15 @@ export class TInt32Array { ...@@ -31,13 +32,15 @@ export class TInt32Array {
this.subarray(); this.subarray();
this.values(); this.values();
this.arrayBufferSlice(); this.arrayBufferSlice();
// #endif
} }
testfloat32() { // #ifdef APP-ANDROID
let float32 = new Int32Array(2); testInt32Array() {
float32[0] = 42; let int32 = new Int32Array(2);
expect(float32[0]).toEqual(42); int32[0] = 42;
expect(float32.length).toEqual(2); expect(int32[0]).toEqual(42);
expect(int32.length).toEqual(2);
expect(Int32Array.BYTES_PER_ELEMENT).toEqual(4); expect(Int32Array.BYTES_PER_ELEMENT).toEqual(4);
let x = new Int32Array([21, 31, 3]); let x = new Int32Array([21, 31, 3]);
...@@ -54,26 +57,26 @@ export class TInt32Array { ...@@ -54,26 +57,26 @@ export class TInt32Array {
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int32Array(buffer); let int32 = new Int32Array(buffer);
float32[1] = 42; int32[1] = 42;
expect(float32.toString()).toEqual("0,42,0,0"); expect(int32.toString()).toEqual("0,42,0,0");
} }
testSet() { testSet() {
let float32 = new Int32Array(8); let int32 = new Int32Array(8);
var array =[1, 2, 3] var array =[1, 2, 3]
float32.set(array, 1); int32.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Int32Array(8); let int32 = new Int32Array(8);
float32.set([1, 2, 3], 1); int32.set([1, 2, 3], 1);
console.log("testCopyWith 1") console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3); int32.copyWithin(3, 0, 3);
console.log("testCopyWith 1") console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -83,42 +86,42 @@ export class TInt32Array { ...@@ -83,42 +86,42 @@ export class TInt32Array {
} }
testFill() { testFill() {
let float32 = new Int32Array([1, 2, 3]).fill(4); let int32 = new Int32Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(int32.toString()).toEqual("4,4,4");
float32 = new Int32Array([1, 2, 3]).fill(4, 1); int32 = new Int32Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(int32.toString()).toEqual("1,4,4");
float32 = new Int32Array([1, 2, 3]).fill(4, 1, 2); int32 = new Int32Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(int32.toString()).toEqual("1,4,3");
float32 = new Int32Array([1, 2, 3]).fill(4, 1, 1); int32 = new Int32Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(int32.toString()).toEqual("1,2,3");
float32 = new Int32Array([1, 2, 3]).fill(4, -3, -2); int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(int32.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = 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(float32.toString()).toEqual("12,44"); expect(int32.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Int32Array([4, 5, 8, 12]); let int32 = new Int32Array([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Int32Array([4, 6, 8, 12]); let int32 = new Int32Array([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Int32Array([4, 6, 7, 120]); int32 = new Int32Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value : number, _ : number, _a : Int32Array): boolean => value > 100); res = int32.findIndex((value : number, _ : number, _a : Int32Array): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -136,44 +139,44 @@ export class TInt32Array { ...@@ -136,44 +139,44 @@ export class TInt32Array {
} }
includes() { includes() {
let float32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
let res = float32.includes(2); let res = int32.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = int32.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = int32.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Int32Array([2, 5, 9]); let int32 = new Int32Array([2, 5, 9]);
let res = float32.indexOf(2); let res = int32.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = int32.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = int32.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = int32.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = int32.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
let res = float32.join(); let res = int32.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = int32.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = int32.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -211,23 +214,23 @@ export class TInt32Array { ...@@ -211,23 +214,23 @@ export class TInt32Array {
} }
reverse() { reverse() {
let float32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
float32.reverse(); int32.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(int32.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Int32Array([1, 2, 3]); let int32 = new Int32Array([1, 2, 3]);
let res = float32.slice(1); let res = int32.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = int32.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = int32.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = int32.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -242,11 +245,11 @@ export class TInt32Array { ...@@ -242,11 +245,11 @@ export class TInt32Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int32Array(buffer); let int32 = new Int32Array(buffer);
float32.set([1, 2, 3]); int32.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0"); expect(int32.toString()).toEqual("1,2,3,0");
let sub = float32.subarray(0, 4); let sub = int32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -258,12 +261,13 @@ export class TInt32Array { ...@@ -258,12 +261,13 @@ export class TInt32Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int32Array(buffer); let int32 = new Int32Array(buffer);
float32[3] = 42; int32[3] = 42;
expect(float32.toString()).toEqual("0,0,0,42"); expect(int32.toString()).toEqual("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); expect(sliced[1]).toEqual(42);
} }
// #endif
} }
...@@ -42,20 +42,20 @@ export class TInt8Array { ...@@ -42,20 +42,20 @@ export class TInt8Array {
} }
testSet() { testSet() {
let float32 = new Int8Array(8); let int8 = new Int8Array(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); int8.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Int8Array(8); let int8 = new Int8Array(8);
float32.set([1, 2, 3], 1); int8.set([1, 2, 3], 1);
console.log("testCopyWith 1") console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3); int8.copyWithin(3, 0, 3);
console.log("testCopyWith 1") console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -66,43 +66,43 @@ export class TInt8Array { ...@@ -66,43 +66,43 @@ export class TInt8Array {
} }
testFill() { testFill() {
let float32 = new Int8Array([1, 2, 3]).fill(4); let int8 = new Int8Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(int8.toString()).toEqual("4,4,4");
float32 = new Int8Array([1, 2, 3]).fill(4, 1); int8 = new Int8Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(int8.toString()).toEqual("1,4,4");
float32 = new Int8Array([1, 2, 3]).fill(4, 1, 2); int8 = new Int8Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(int8.toString()).toEqual("1,4,3");
float32 = new Int8Array([1, 2, 3]).fill(4, 1, 1); int8 = new Int8Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(int8.toString()).toEqual("1,2,3");
float32 = new Int8Array([1, 2, 3]).fill(4, -3, -2); int8 = new Int8Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(int8.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = 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(float32.toString()).toEqual("12,44"); expect(int8.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Int8Array([4, 5, 8, 12]); let int8 = new Int8Array([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Int8Array([4, 6, 8, 12]); let int8 = new Int8Array([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Int8Array([4, 6, 7, 120]); int8 = new Int8Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Int8Array): boolean => value > 100); res = int8.findIndex((value: number, _: number, _a: Int8Array): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -120,44 +120,44 @@ export class TInt8Array { ...@@ -120,44 +120,44 @@ export class TInt8Array {
} }
includes() { includes() {
let float32 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
let res = float32.includes(2); let res = int8.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = int8.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = int8.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Int8Array([2, 5, 9]); let int8 = new Int8Array([2, 5, 9]);
let res = float32.indexOf(2); let res = int8.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = int8.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = int8.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = int8.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = int8.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
let res = float32.join(); let res = int8.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = int8.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = int8.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -204,23 +204,23 @@ export class TInt8Array { ...@@ -204,23 +204,23 @@ export class TInt8Array {
} }
reverse() { reverse() {
let float32 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
float32.reverse(); int8.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(int8.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Int8Array([1, 2, 3]); let int8 = new Int8Array([1, 2, 3]);
let res = float32.slice(1); let res = int8.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = int8.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = int8.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = int8.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -235,11 +235,11 @@ export class TInt8Array { ...@@ -235,11 +235,11 @@ export class TInt8Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(8); let buffer = new ArrayBuffer(8);
let float32 = new Int8Array(buffer); let int8 = new Int8Array(buffer);
float32.set([1, 2, 3]); int8.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0,0,0,0,0"); expect(int8.toString()).toEqual("1,2,3,0,0,0,0,0");
let sub = float32.subarray(0, 4); let sub = int8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -253,9 +253,9 @@ export class TInt8Array { ...@@ -253,9 +253,9 @@ export class TInt8Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Int8Array(buffer); let int8 = new Int8Array(buffer);
float32[4] = 42; int8[4] = 42;
expect(float32.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"); 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, 12);
let sliced = new Int8Array(res); let sliced = new Int8Array(res);
......
...@@ -39,32 +39,32 @@ export class TUint8Array { ...@@ -39,32 +39,32 @@ export class TUint8Array {
console.log(unit8.toString()) console.log(unit8.toString())
} }
testMAX() { testMAX() {
let float32 = new Uint8Array(16); let uint8 = new Uint8Array(16);
float32[0] = 255; uint8[0] = 255;
expect(float32[0]).toEqual(255); expect(uint8[0]).toEqual(255);
} }
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint8Array(buffer); let uint8 = new Uint8Array(buffer);
float32[5] = 42; uint8[5] = 42;
expect(float32.toString()).toEqual("0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0"); expect(uint8.toString()).toEqual("0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0");
} }
testSet() { testSet() {
let float32 = new Uint8Array(8); let uint8 = new Uint8Array(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); uint8.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Uint8Array(8); let uint8 = new Uint8Array(8);
float32.set([1, 2, 3], 1); uint8.set([1, 2, 3], 1);
float32.copyWithin(3, 0, 3); uint8.copyWithin(3, 0, 3);
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -75,43 +75,43 @@ export class TUint8Array { ...@@ -75,43 +75,43 @@ export class TUint8Array {
} }
testFill() { testFill() {
let float32 = new Uint8Array([1, 2, 3]).fill(4); let uint8 = new Uint8Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(uint8.toString()).toEqual("4,4,4");
float32 = new Uint8Array([1, 2, 3]).fill(4, 1); uint8 = new Uint8Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(uint8.toString()).toEqual("1,4,4");
float32 = new Uint8Array([1, 2, 3]).fill(4, 1, 2); uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(uint8.toString()).toEqual("1,4,3");
float32 = new Uint8Array([1, 2, 3]).fill(4, 1, 1); uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(uint8.toString()).toEqual("1,2,3");
float32 = new Uint8Array([1, 2, 3]).fill(4, -3, -2); uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(uint8.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Uint8Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Uint8Array): boolean => value >= let uint8 = new Uint8Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Uint8Array): boolean => value >=
10); 10);
expect(float32.toString()).toEqual("12,44"); expect(uint8.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Uint8Array([4, 5, 8, 12]); let uint8 = new Uint8Array([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Uint8Array([4, 6, 8, 12]); let uint8 = new Uint8Array([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Uint8Array([4, 6, 7, 120]); let uuint8 = new Uint8Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Uint8Array): boolean => value > 100); res = uuint8.findIndex((value: number, _: number, _a: Uint8Array): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -129,44 +129,44 @@ export class TUint8Array { ...@@ -129,44 +129,44 @@ export class TUint8Array {
} }
includes() { includes() {
let float32 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
let res = float32.includes(2); let res = uint8.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = uint8.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = uint8.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Uint8Array([2, 5, 9]); let uint8 = new Uint8Array([2, 5, 9]);
let res = float32.indexOf(2); let res = uint8.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = uint8.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = uint8.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = uint8.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = uint8.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
let res = float32.join(); let res = uint8.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = uint8.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = uint8.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -208,23 +208,23 @@ export class TUint8Array { ...@@ -208,23 +208,23 @@ export class TUint8Array {
} }
reverse() { reverse() {
let float32 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
float32.reverse(); uint8.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(uint8.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Uint8Array([1, 2, 3]); let uint8 = new Uint8Array([1, 2, 3]);
let res = float32.slice(1); let res = uint8.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = uint8.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = uint8.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = uint8.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -239,11 +239,11 @@ export class TUint8Array { ...@@ -239,11 +239,11 @@ export class TUint8Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint8Array(buffer); let uint8 = new Uint8Array(buffer);
float32.set([1, 2, 3]); uint8.set([1, 2, 3]);
expect(float32.toString()).toEqual("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 = float32.subarray(0, 4); let sub = uint8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -256,9 +256,9 @@ export class TUint8Array { ...@@ -256,9 +256,9 @@ export class TUint8Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint8Array(buffer); let uint8 = new Uint8Array(buffer);
float32[4] = 42; uint8[4] = 42;
expect(float32.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"); expect(uint8.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, 12);
let sliced = new Uint8Array(res); let sliced = new Uint8Array(res);
......
...@@ -34,32 +34,32 @@ export class TUint8ClampedArray { ...@@ -34,32 +34,32 @@ export class TUint8ClampedArray {
} }
testMAX() { testMAX() {
let float32 = new Uint8ClampedArray(16); let uint8Clamped = new Uint8ClampedArray(16);
float32[0] = 255; uint8Clamped[0] = 255;
expect(float32[0]).toEqual(255); expect(uint8Clamped[0]).toEqual(255);
} }
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint8ClampedArray(buffer); let uint8Clamped = new Uint8ClampedArray(buffer);
float32[5] = 42; uint8Clamped[5] = 42;
expect(float32.toString()).toEqual("0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0"); expect(uint8Clamped.toString()).toEqual("0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0");
} }
testSet() { testSet() {
let float32 = new Uint8ClampedArray(8); let uint8Clamped = new Uint8ClampedArray(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); uint8Clamped.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Uint8ClampedArray(8); let uint8Clamped = new Uint8ClampedArray(8);
float32.set([1, 2, 3], 1); uint8Clamped.set([1, 2, 3], 1);
float32.copyWithin(3, 0, 3); uint8Clamped.copyWithin(3, 0, 3);
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -70,43 +70,43 @@ export class TUint8ClampedArray { ...@@ -70,43 +70,43 @@ export class TUint8ClampedArray {
} }
testFill() { testFill() {
let float32 = new Uint8ClampedArray([1, 2, 3]).fill(4); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(uint8Clamped.toString()).toEqual("4,4,4");
float32 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(uint8Clamped.toString()).toEqual("1,4,4");
float32 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(uint8Clamped.toString()).toEqual("1,4,3");
float32 = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(uint8Clamped.toString()).toEqual("1,2,3");
float32 = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2); uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(uint8Clamped.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = 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(float32.toString()).toEqual("12,44"); expect(uint8Clamped.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Uint8ClampedArray([4, 5, 8, 12]); let uint8Clamped = new Uint8ClampedArray([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Uint8ClampedArray([4, 6, 8, 12]); let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Uint8ClampedArray([4, 6, 7, 120]); let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Uint8ClampedArray): boolean => value > 100); res = uuint8Clamped.findIndex((value: number, _: number, _a: Uint8ClampedArray): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -124,44 +124,44 @@ export class TUint8ClampedArray { ...@@ -124,44 +124,44 @@ export class TUint8ClampedArray {
} }
includes() { includes() {
let float32 = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = float32.includes(2); let res = uint8Clamped.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = uint8Clamped.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = uint8Clamped.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Uint8ClampedArray([2, 5, 9]); let uint8Clamped = new Uint8ClampedArray([2, 5, 9]);
let res = float32.indexOf(2); let res = uint8Clamped.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = uint8Clamped.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = uint8Clamped.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = uint8Clamped.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = uint8Clamped.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = float32.join(); let res = uint8Clamped.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = uint8Clamped.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = uint8Clamped.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -203,23 +203,23 @@ export class TUint8ClampedArray { ...@@ -203,23 +203,23 @@ export class TUint8ClampedArray {
} }
reverse() { reverse() {
let float32 = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
float32.reverse(); uint8Clamped.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(uint8Clamped.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Uint8ClampedArray([1, 2, 3]); let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = float32.slice(1); let res = uint8Clamped.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = uint8Clamped.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = uint8Clamped.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = uint8Clamped.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -234,11 +234,11 @@ export class TUint8ClampedArray { ...@@ -234,11 +234,11 @@ export class TUint8ClampedArray {
subarray() { subarray() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint8ClampedArray(buffer); let uint8Clamped = new Uint8ClampedArray(buffer);
float32.set([1, 2, 3]); uint8Clamped.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"); expect(uint8Clamped.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0");
let sub = float32.subarray(0, 4); let sub = uint8Clamped.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -251,9 +251,9 @@ export class TUint8ClampedArray { ...@@ -251,9 +251,9 @@ export class TUint8ClampedArray {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint8ClampedArray(buffer); let uint8Clamped = new Uint8ClampedArray(buffer);
float32[4] = 42; uint8Clamped[4] = 42;
expect(float32.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"); expect(uint8Clamped.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, 12);
let sliced = new Uint8ClampedArray(res); let sliced = new Uint8ClampedArray(res);
......
...@@ -7,7 +7,8 @@ import { ...@@ -7,7 +7,8 @@ import {
export class TUint16Array { export class TUint16Array {
test() { test() {
this.testfloat32(); // #ifdef APP-ANDROID
this.testuint16();
this.testConstructor(); this.testConstructor();
this.testSet(); this.testSet();
this.testCopyWith(); this.testCopyWith();
...@@ -31,13 +32,15 @@ export class TUint16Array { ...@@ -31,13 +32,15 @@ export class TUint16Array {
this.subarray(); this.subarray();
this.values(); this.values();
this.arrayBufferSlice(); this.arrayBufferSlice();
// #endif
} }
testfloat32() { // #ifdef APP-ANDROID
let float32 = new Uint16Array(2); testuint16() {
float32[0] = 42; let uint16 = new Uint16Array(2);
expect(float32[0]).toEqual(42); uint16[0] = 42;
expect(float32.length).toEqual(2); expect(uint16[0]).toEqual(42);
expect(uint16.length).toEqual(2);
expect(Uint16Array.BYTES_PER_ELEMENT).toEqual(4); expect(Uint16Array.BYTES_PER_ELEMENT).toEqual(4);
let x = new Uint16Array([21, 31, 3]); let x = new Uint16Array([21, 31, 3]);
...@@ -54,26 +57,26 @@ export class TUint16Array { ...@@ -54,26 +57,26 @@ export class TUint16Array {
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint16Array(buffer); let uint16 = new Uint16Array(buffer);
float32[1] = 42; uint16[1] = 42;
expect(float32.toString()).toEqual("0,42,0,0,0,0,0,0"); expect(uint16.toString()).toEqual("0,42,0,0,0,0,0,0");
} }
testSet() { testSet() {
let float32 = new Uint16Array(8); let uint16 = new Uint16Array(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); uint16.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Uint16Array(8); let uint16 = new Uint16Array(8);
float32.set([1, 2, 3], 1); uint16.set([1, 2, 3], 1);
console.log("testCopyWith 1") console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3); uint16.copyWithin(3, 0, 3);
console.log("testCopyWith 1") console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -84,43 +87,43 @@ export class TUint16Array { ...@@ -84,43 +87,43 @@ export class TUint16Array {
} }
testFill() { testFill() {
let float32 = new Uint16Array([1, 2, 3]).fill(4); let uint16 = new Uint16Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(uint16.toString()).toEqual("4,4,4");
float32 = new Uint16Array([1, 2, 3]).fill(4, 1); uint16 = new Uint16Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(uint16.toString()).toEqual("1,4,4");
float32 = new Uint16Array([1, 2, 3]).fill(4, 1, 2); uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(uint16.toString()).toEqual("1,4,3");
float32 = new Uint16Array([1, 2, 3]).fill(4, 1, 1); uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(uint16.toString()).toEqual("1,2,3");
float32 = new Uint16Array([1, 2, 3]).fill(4, -3, -2); uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(uint16.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = 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(float32.toString()).toEqual("12,44"); expect(uint16.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Uint16Array([4, 5, 8, 12]); let uint16 = new Uint16Array([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Uint16Array([4, 6, 8, 12]); let uint16 = new Uint16Array([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Uint16Array([4, 6, 7, 120]); let uuint16 = new Uint16Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Uint16Array): boolean => value > 100); res = uuint16.findIndex((value: number, _: number, _a: Uint16Array): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -138,44 +141,44 @@ export class TUint16Array { ...@@ -138,44 +141,44 @@ export class TUint16Array {
} }
includes() { includes() {
let float32 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
let res = float32.includes(2); let res = uint16.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = uint16.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = uint16.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Uint16Array([2, 5, 9]); let uint16 = new Uint16Array([2, 5, 9]);
let res = float32.indexOf(2); let res = uint16.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = uint16.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = uint16.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = uint16.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = uint16.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
let res = float32.join(); let res = uint16.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = uint16.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = uint16.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -217,23 +220,23 @@ export class TUint16Array { ...@@ -217,23 +220,23 @@ export class TUint16Array {
} }
reverse() { reverse() {
let float32 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
float32.reverse(); uint16.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(uint16.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Uint16Array([1, 2, 3]); let uint16 = new Uint16Array([1, 2, 3]);
let res = float32.slice(1); let res = uint16.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = uint16.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = uint16.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = uint16.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -248,11 +251,11 @@ export class TUint16Array { ...@@ -248,11 +251,11 @@ export class TUint16Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint16Array(buffer); let uint16 = new Uint16Array(buffer);
float32.set([1, 2, 3]); uint16.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0,0,0,0,0"); expect(uint16.toString()).toEqual("1,2,3,0,0,0,0,0");
let sub = float32.subarray(0, 4); let sub = uint16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -265,12 +268,14 @@ export class TUint16Array { ...@@ -265,12 +268,14 @@ export class TUint16Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint16Array(buffer); let uint16 = new Uint16Array(buffer);
float32[4] = 42; uint16[4] = 42;
expect(float32.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); expect(sliced[0]).toEqual(42);
} }
// #endif
} }
\ No newline at end of file
...@@ -7,7 +7,8 @@ import { ...@@ -7,7 +7,8 @@ import {
export class TUint32Array { export class TUint32Array {
test() { test() {
this.testfloat32(); // #ifdef APP-ANDROID
this.testuint32();
this.testConstructor(); this.testConstructor();
this.testSet(); this.testSet();
this.testCopyWith(); this.testCopyWith();
...@@ -31,13 +32,15 @@ export class TUint32Array { ...@@ -31,13 +32,15 @@ export class TUint32Array {
this.subarray(); this.subarray();
this.values(); this.values();
this.arrayBufferSlice(); this.arrayBufferSlice();
// #endif
} }
testfloat32() { // #ifdef APP-ANDROID
let float32 = new Uint32Array(2); testuint32() {
float32[0] = 42; let uint32 = new Uint32Array(2);
expect(float32[0]).toEqual(42); uint32[0] = 42;
expect(float32.length).toEqual(2); expect(uint32[0]).toEqual(42);
expect(uint32.length).toEqual(2);
expect(Uint32Array.BYTES_PER_ELEMENT).toEqual(4); expect(Uint32Array.BYTES_PER_ELEMENT).toEqual(4);
let x = new Uint32Array([21, 31, 3]); let x = new Uint32Array([21, 31, 3]);
...@@ -54,26 +57,26 @@ export class TUint32Array { ...@@ -54,26 +57,26 @@ export class TUint32Array {
testConstructor() { testConstructor() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint32Array(buffer); let uint32 = new Uint32Array(buffer);
float32[1] = 42; uint32[1] = 42;
expect(float32.toString()).toEqual("0,42,0,0"); expect(uint32.toString()).toEqual("0,42,0,0");
} }
testSet() { testSet() {
let float32 = new Uint32Array(8); let uint32 = new Uint32Array(8);
var array = [1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); uint32.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
testCopyWith() { testCopyWith() {
console.log("testCopyWith 1") console.log("testCopyWith 1")
let float32 = new Uint32Array(8); let uint32 = new Uint32Array(8);
float32.set([1, 2, 3], 1); uint32.set([1, 2, 3], 1);
console.log("testCopyWith 1") console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3); uint32.copyWithin(3, 0, 3);
console.log("testCopyWith 1") console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
...@@ -84,43 +87,43 @@ export class TUint32Array { ...@@ -84,43 +87,43 @@ export class TUint32Array {
} }
testFill() { testFill() {
let float32 = new Uint32Array([1, 2, 3]).fill(4); let uint32 = new Uint32Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4"); expect(uint32.toString()).toEqual("4,4,4");
float32 = new Uint32Array([1, 2, 3]).fill(4, 1); uint32 = new Uint32Array([1, 2, 3]).fill(4, 1);
expect(float32.toString()).toEqual("1,4,4"); expect(uint32.toString()).toEqual("1,4,4");
float32 = new Uint32Array([1, 2, 3]).fill(4, 1, 2); uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 2);
expect(float32.toString()).toEqual("1,4,3"); expect(uint32.toString()).toEqual("1,4,3");
float32 = new Uint32Array([1, 2, 3]).fill(4, 1, 1); uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 1);
expect(float32.toString()).toEqual("1,2,3"); expect(uint32.toString()).toEqual("1,2,3");
float32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2); uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3"); expect(uint32.toString()).toEqual("4,2,3");
} }
testFilter() { testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10; // const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Uint32Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Uint32Array): let uint32 = new Uint32Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Uint32Array):
boolean => value >= 10); boolean => value >= 10);
expect(float32.toString()).toEqual("12,44"); expect(uint32.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Uint32Array([4, 5, 8, 12]); let uint32 = new Uint32Array([4, 5, 8, 12]);
let res = float32.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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Uint32Array([4, 6, 8, 12]); let uint32 = new Uint32Array([4, 6, 8, 12]);
let res = float32.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); expect(res).toEqual(-1);
let ufloat32 = new Uint32Array([4, 6, 7, 120]); let uuint32 = new Uint32Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value: number, _: number, _a: Uint32Array): boolean => value > 100); res = uuint32.findIndex((value: number, _: number, _a: Uint32Array): boolean => value > 100);
expect(res).toEqual(3); expect(res).toEqual(3);
} }
...@@ -138,44 +141,44 @@ export class TUint32Array { ...@@ -138,44 +141,44 @@ export class TUint32Array {
} }
includes() { includes() {
let float32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
let res = float32.includes(2); let res = uint32.includes(2);
expect(res).toEqual(true); expect(res).toEqual(true);
res = float32.includes(4); res = uint32.includes(4);
expect(res).toEqual(false); expect(res).toEqual(false);
res = float32.includes(3, 3); res = uint32.includes(3, 3);
expect(res).toEqual(false); expect(res).toEqual(false);
} }
indexOf() { indexOf() {
let float32 = new Uint32Array([2, 5, 9]); let uint32 = new Uint32Array([2, 5, 9]);
let res = float32.indexOf(2); let res = uint32.indexOf(2);
expect(res).toEqual(0); expect(res).toEqual(0);
res = float32.indexOf(7); res = uint32.indexOf(7);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(9, 2); res = uint32.indexOf(9, 2);
expect(res).toEqual(2); expect(res).toEqual(2);
res = float32.indexOf(2, -1); res = uint32.indexOf(2, -1);
expect(res).toEqual(-1); expect(res).toEqual(-1);
res = float32.indexOf(2, -3); res = uint32.indexOf(2, -3);
expect(res).toEqual(0); expect(res).toEqual(0);
} }
join() { join() {
let float32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
let res = float32.join(); let res = uint32.join();
expect(res).toEqual("1,2,3"); expect(res).toEqual("1,2,3");
res = float32.join(" / "); res = uint32.join(" / ");
expect(res).toEqual("1 / 2 / 3"); expect(res).toEqual("1 / 2 / 3");
res = float32.join(""); res = uint32.join("");
expect(res).toEqual("123"); expect(res).toEqual("123");
} }
...@@ -217,23 +220,23 @@ export class TUint32Array { ...@@ -217,23 +220,23 @@ export class TUint32Array {
} }
reverse() { reverse() {
let float32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
float32.reverse(); uint32.reverse();
expect(float32.toString()).toEqual("3,2,1"); expect(uint32.toString()).toEqual("3,2,1");
} }
slice() { slice() {
let float32 = new Uint32Array([1, 2, 3]); let uint32 = new Uint32Array([1, 2, 3]);
let res = float32.slice(1); let res = uint32.slice(1);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(2); res = uint32.slice(2);
expect(res.toString()).toEqual("3"); expect(res.toString()).toEqual("3");
res = float32.slice(-2); res = uint32.slice(-2);
expect(res.toString()).toEqual("2,3"); expect(res.toString()).toEqual("2,3");
res = float32.slice(0, 1); res = uint32.slice(0, 1);
expect(res.toString()).toEqual("1"); expect(res.toString()).toEqual("1");
} }
...@@ -248,11 +251,11 @@ export class TUint32Array { ...@@ -248,11 +251,11 @@ export class TUint32Array {
subarray() { subarray() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint32Array(buffer); let uint32 = new Uint32Array(buffer);
float32.set([1, 2, 3]); uint32.set([1, 2, 3]);
expect(float32.toString()).toEqual("1,2,3,0"); expect(uint32.toString()).toEqual("1,2,3,0");
let sub = float32.subarray(0, 4); let sub = uint32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0"); expect(sub.toString()).toEqual("1,2,3,0");
} }
...@@ -265,12 +268,13 @@ export class TUint32Array { ...@@ -265,12 +268,13 @@ export class TUint32Array {
arrayBufferSlice() { arrayBufferSlice() {
let buffer = new ArrayBuffer(16); let buffer = new ArrayBuffer(16);
let float32 = new Uint32Array(buffer); let uint32 = new Uint32Array(buffer);
float32[3] = 42; uint32[3] = 42;
expect(float32.toString()).toEqual("0,0,0,42"); expect(uint32.toString()).toEqual("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); expect(sliced[1]).toEqual(42);
} }
// #endif
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册