提交 175d3a51 编写于 作者: M mahaifeng

[array-buffer]添加测试用例

上级 bcb5b721
...@@ -75,6 +75,9 @@ export function testArrayBuffer() : Result { ...@@ -75,6 +75,9 @@ export function testArrayBuffer() : Result {
test('float32_testSet', () => { test('float32_testSet', () => {
float32.testSet() float32.testSet()
}) })
test('float32_testFrom', () => {
float32.from()
})
test('float32_testCopyWith', () => { test('float32_testCopyWith', () => {
float32.testCopyWith() float32.testCopyWith()
}) })
...@@ -434,6 +437,9 @@ export function testArrayBuffer() : Result { ...@@ -434,6 +437,9 @@ export function testArrayBuffer() : Result {
test('uint8_testConstructor', () => { test('uint8_testConstructor', () => {
uint8.testConstructor() uint8.testConstructor()
}) })
test('uint8_from', () => {
uint8.from()
})
test('uint8_testSet', () => { test('uint8_testSet', () => {
uint8.testSet() uint8.testSet()
}) })
......
...@@ -32,6 +32,10 @@ export class TFloat32Array { ...@@ -32,6 +32,10 @@ export class TFloat32Array {
this.values(); this.values();
this.arrayBufferSlice(); this.arrayBufferSlice();
} }
from(){
var float32Array= Float32Array.from([1, 2, 3], (v: number, _: number):number => v + v);
expect(float32Array.toString()).toEqual('2,4,6');
}
testfloat32() { testfloat32() {
let float32 = new Float32Array(2); let float32 = new Float32Array(2);
......
...@@ -32,7 +32,12 @@ export class TUint8Array { ...@@ -32,7 +32,12 @@ export class TUint8Array {
this.values(); this.values();
this.arrayBufferSlice(); 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() { testMAX() {
let float32 = new Uint8Array(16); let float32 = new Uint8Array(16);
float32[0] = 255; float32[0] = 255;
...@@ -48,7 +53,7 @@ export class TUint8Array { ...@@ -48,7 +53,7 @@ export class TUint8Array {
testSet() { testSet() {
let float32 = new Uint8Array(8); let float32 = new Uint8Array(8);
var array =[1, 2, 3] var array = [1, 2, 3]
float32.set(array, 1); float32.set(array, 1);
expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0"); expect(float32.toString()).toEqual("0,1,2,3,0,0,0,0");
} }
...@@ -58,13 +63,14 @@ export class TUint8Array { ...@@ -58,13 +63,14 @@ export class TUint8Array {
let float32 = new Uint8Array(8); let float32 = new Uint8Array(8);
float32.set([1, 2, 3], 1); float32.set([1, 2, 3], 1);
float32.copyWithin(3, 0, 3); float32.copyWithin(3, 0, 3);
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0"); expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0");
} }
testEvery() { testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8Array): boolean => currentValue < 40; // 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); expect(result).toEqual(false);
} }
...@@ -87,29 +93,30 @@ export class TUint8Array { ...@@ -87,29 +93,30 @@ export class TUint8Array {
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, _ : 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"); expect(float32.toString()).toEqual("12,44");
} }
find() { find() {
let float32 = new Uint8Array([4, 5, 8, 12]); 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); expect(res).toEqual(8);
} }
findIndex() { findIndex() {
let float32 = new Uint8Array([4, 6, 8, 12]); 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); expect(res).toEqual(-1);
let ufloat32 = new Uint8Array([4, 6, 7, 120]); 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); expect(res).toEqual(3);
} }
foreach() { 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}`); console.log(`a[${index}] = ${value}`);
}); });
} }
...@@ -118,7 +125,7 @@ export class TUint8Array { ...@@ -118,7 +125,7 @@ export class TUint8Array {
let arr = new Uint8Array([10, 20, 30, 40, 50]); let arr = new Uint8Array([10, 20, 30, 40, 50]);
let entries = arr.entries(); let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10); expect(entries.next().value[1]).toEqual(10);
} }
includes() { includes() {
...@@ -171,28 +178,32 @@ export class TUint8Array { ...@@ -171,28 +178,32 @@ export class TUint8Array {
map() { map() {
let numbers = new Uint8Array([1, 4, 9]); 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(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 Uint8Array([0, 1, 2, 3]); 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); expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]); total = new Uint8Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue, 8); res = total.reduce((accumulator: number, currentValue: number, _: number, _: Uint8Array): number => accumulator +
currentValue, 8);
expect(res).toEqual(14); expect(res).toEqual(14);
} }
reduceRight() { reduceRight() {
let total = new Uint8Array([0, 1, 2, 3]); let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue); let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _: Uint8Array): number =>
accumulator + currentValue);
expect(res).toEqual(6); expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]); total = new Uint8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue : number, _ : number, _ : Uint8Array): number => accumulator + currentValue, 8); res = total.reduceRight((accumulator: number, currentValue: number, _: number, _: Uint8Array): number =>
accumulator + currentValue, 8);
expect(res).toEqual(14); expect(res).toEqual(14);
} }
...@@ -222,7 +233,7 @@ export class TUint8Array { ...@@ -222,7 +233,7 @@ export class TUint8Array {
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");
} }
...@@ -240,7 +251,7 @@ export class TUint8Array { ...@@ -240,7 +251,7 @@ export class TUint8Array {
let arr = new Uint8Array([1, 2, 3]); let arr = new Uint8Array([1, 2, 3]);
let values = arr.values(); let values = arr.values();
expect(values.next().value).toEqual(1); expect(values.next().value).toEqual(1);
} }
arrayBufferSlice() { arrayBufferSlice() {
...@@ -253,4 +264,4 @@ export class TUint8Array { ...@@ -253,4 +264,4 @@ export class TUint8Array {
let sliced = new Uint8Array(res); let sliced = new Uint8Array(res);
expect(sliced[0]).toEqual(42); expect(sliced[0]).toEqual(42);
} }
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册