提交 45b71291 编写于 作者: M mahaifeng

[array-buffer]添加测试用例

上级 52c49ade
......@@ -75,6 +75,9 @@ export function testArrayBuffer() : Result {
test('float32_testSet', () => {
float32.testSet()
})
test('float32_testFrom', () => {
float32.from()
})
test('float32_testCopyWith', () => {
float32.testCopyWith()
})
......@@ -434,6 +437,9 @@ export function testArrayBuffer() : Result {
test('uint8_testConstructor', () => {
uint8.testConstructor()
})
test('uint8_from', () => {
uint8.from()
})
test('uint8_testSet', () => {
uint8.testSet()
})
......
......@@ -32,6 +32,10 @@ export class TFloat32Array {
this.values();
this.arrayBufferSlice();
}
from(){
var float32Array= Float32Array.from([1, 2, 3], (v: number, _: number):number => v + v);
expect(float32Array.toString()).toEqual('2,4,6');
}
testfloat32() {
let float32 = new Float32Array(2);
......
......@@ -32,7 +32,12 @@ export class TUint8Array {
this.values();
this.arrayBufferSlice();
}
from() {
var s = new Set([1, 2, 3]);
var unit8 = Uint8Array.from(s);
expect(unit8.toString()).toEqual('1,2,3');
console.log(unit8.toString())
}
testMAX() {
let float32 = new Uint8Array(16);
float32[0] = 255;
......@@ -48,7 +53,7 @@ export class TUint8Array {
testSet() {
let float32 = new Uint8Array(8);
var array =[1, 2, 3]
var array = [1, 2, 3]
float32.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0");
}
......@@ -64,7 +69,8 @@ export class TUint8Array {
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, _ : Uint8Array): boolean => value< 40); //
let result = new Uint8Array([12, 5, 8, 130, 44]).every((value: number, _: number, _: Uint8Array): boolean =>
value < 40); //
expect(result).toEqual(false);
}
......@@ -88,28 +94,29 @@ export class TUint8Array {
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let float32 = new Uint8Array([12, 5, 8, 44]).filter((value : number, _ : number, _ : Uint8Array): boolean => value>= 10);
let float32 = new Uint8Array([12, 5, 8, 44]).filter((value: number, _: number, _: Uint8Array): boolean => value >=
10);
expect(float32.toString()).toEqual("12,44");
}
find() {
let float32 = new Uint8Array([4, 5, 8, 12]);
let res = float32.find((value : number, _ : number, _ : Uint8Array): boolean => value > 5);
let res = float32.find((value: number, _: number, _: Uint8Array): boolean => value > 5);
expect(res).toEqual(8);
}
findIndex() {
let float32 = new Uint8Array([4, 6, 8, 12]);
let res = float32.findIndex((value : number, _ : number, _ : Uint8Array): boolean => value > 100);
let res = float32.findIndex((value: number, _: number, _: Uint8Array): boolean => value > 100);
expect(res).toEqual(-1);
let ufloat32 = new Uint8Array([4, 6, 7, 120]);
res = ufloat32.findIndex((value : number, _ : number, _ : Uint8Array): boolean => value > 100);
res = ufloat32.findIndex((value: number, _: number, _: Uint8Array): boolean => value > 100);
expect(res).toEqual(3);
}
foreach() {
new Uint8Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Uint8Array) => {
new Uint8Array([0, 1, 2, 3]).forEach((value: number, index: number, _: Uint8Array) => {
console.log(`a[${index}] = ${value}`);
});
}
......@@ -171,28 +178,32 @@ export class TUint8Array {
map() {
let numbers = new Uint8Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _ : Uint8Array): number => value * 2);
let doubles = numbers.map((value: number, _: number, _: Uint8Array): number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
}
reduce() {
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue);
let res = total.reduce((accumulator: number, currentValue: number, _: number, _: Uint8Array): number =>
accumulator + currentValue);
expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue, 8);
res = total.reduce((accumulator: number, currentValue: number, _: number, _: Uint8Array): number => accumulator +
currentValue, 8);
expect(res).toEqual(14);
}
reduceRight() {
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue);
let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _: Uint8Array): number =>
accumulator + currentValue);
expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _: Uint8Array): number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
}
......@@ -222,7 +233,7 @@ export class TUint8Array {
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");
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册