Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
f36cdd44
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
f36cdd44
编写于
7月 12, 2024
作者:
WOSHIMAHAIFENG
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev_buffer' into 'dev'
[array-buffer]添加#TEST 注释 See merge request
!17
上级
cc739400
6e882dd5
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
561 addition
and
209 deletion
+561
-209
uni_modules/uts-tests/utssdk/TFloat32Array.uts
uni_modules/uts-tests/utssdk/TFloat32Array.uts
+54
-18
uni_modules/uts-tests/utssdk/TFloat64Array.uts
uni_modules/uts-tests/utssdk/TFloat64Array.uts
+62
-24
uni_modules/uts-tests/utssdk/TInt16Array.uts
uni_modules/uts-tests/utssdk/TInt16Array.uts
+59
-20
uni_modules/uts-tests/utssdk/TInt32Array.uts
uni_modules/uts-tests/utssdk/TInt32Array.uts
+63
-22
uni_modules/uts-tests/utssdk/TInt8Array.uts
uni_modules/uts-tests/utssdk/TInt8Array.uts
+62
-19
uni_modules/uts-tests/utssdk/TUInt8Array.uts
uni_modules/uts-tests/utssdk/TUInt8Array.uts
+62
-24
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
+67
-26
uni_modules/uts-tests/utssdk/TUint16Array.uts
uni_modules/uts-tests/utssdk/TUint16Array.uts
+69
-28
uni_modules/uts-tests/utssdk/TUint32Array.uts
uni_modules/uts-tests/utssdk/TUint32Array.uts
+63
-28
未找到文件。
uni_modules/uts-tests/utssdk/TFloat32Array.uts
浏览文件 @
f36cdd44
...
@@ -63,6 +63,7 @@ export class TFloat32Array {
...
@@ -63,6 +63,7 @@ export class TFloat32Array {
}
}
testConstructor() {
testConstructor() {
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let float32 = new Float32Array(buffer);
let float32 = new Float32Array(buffer);
float32[1] = 42;
float32[1] = 42;
...
@@ -70,30 +71,33 @@ export class TFloat32Array {
...
@@ -70,30 +71,33 @@ export class TFloat32Array {
}
}
testSet() {
testSet() {
// #TEST Float32Array.set
let float32 = new Float32Array(8);
let float32 = new Float32Array(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");
// #END
}
}
testCopyWith() {
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Float32Array.copyWithin
let float32 = new Float32Array(8);
let float32 = new Float32Array(8);
float32.set([1, 2, 3], 1);
float32.set([1, 2, 3], 1);
console.log("testCopyWith 1")
float32.copyWithin(3, 0, 3);
float32.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(float32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Float32Array): boolean => currentValue < 40;
// #TEST Float32Array.every
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);
// #END
}
}
testFill() {
testFill() {
// #TEST Float32Array.fill
let float32 = new Float32Array([1, 2, 3]).fill(4);
let float32 = new Float32Array([1, 2, 3]).fill(4);
expect(float32.toString()).toEqual("4,4,4");
expect(float32.toString()).toEqual("4,4,4");
...
@@ -108,23 +112,26 @@ export class TFloat32Array {
...
@@ -108,23 +112,26 @@ export class TFloat32Array {
float32 = new Float32Array([1, 2, 3]).fill(4, -3, -2);
float32 = new Float32Array([1, 2, 3]).fill(4, -3, -2);
expect(float32.toString()).toEqual("4,2,3");
expect(float32.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// #TEST Float32Array.filter
let float32 = new Float32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float32Array) : boolean => value >= 10);
let float32 = new Float32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float32Array) :
boolean => value >= 10);
expect(float32.toString()).toEqual("12,44");
expect(float32.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Float32Array.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);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Float32Array.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);
...
@@ -132,22 +139,28 @@ export class TFloat32Array {
...
@@ -132,22 +139,28 @@ export class TFloat32Array {
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);
// #END
}
}
foreach() {
foreach() {
// #TEST Float32Array.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}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Float32Array.entries
let arr = new Float32Array([10, 20, 30, 40, 50]);
let arr = new Float32Array([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);
expect(entries.next().value[1]).toEqual(20);
expect(entries.next().value[1]).toEqual(20);
// #END
}
}
includes() {
includes() {
// #TEST Float32Array.includes
let float32 = new Float32Array([1, 2, 3]);
let float32 = new Float32Array([1, 2, 3]);
let res = float32.includes(2.0);
let res = float32.includes(2.0);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -157,9 +170,11 @@ export class TFloat32Array {
...
@@ -157,9 +170,11 @@ export class TFloat32Array {
res = float32.includes(3.0, 3);
res = float32.includes(3.0, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Float32Array.indexOf
let float32 = new Float32Array([2, 5, 9]);
let float32 = new Float32Array([2, 5, 9]);
let res = float32.indexOf(2);
let res = float32.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -175,9 +190,11 @@ export class TFloat32Array {
...
@@ -175,9 +190,11 @@ export class TFloat32Array {
res = float32.indexOf(2, -3);
res = float32.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Float32Array.join
let float32 = new Float32Array([1, 2, 3]);
let float32 = new Float32Array([1, 2, 3]);
let res = float32.join();
let res = float32.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -187,9 +204,11 @@ export class TFloat32Array {
...
@@ -187,9 +204,11 @@ export class TFloat32Array {
res = float32.join("");
res = float32.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Float32Array.keys
let arr = new Float32Array([10, 20, 30, 40, 50]);
let arr = new Float32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
...
@@ -197,46 +216,53 @@ export class TFloat32Array {
...
@@ -197,46 +216,53 @@ export class TFloat32Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
expect(keys.next().value).toEqual(4);
// #END
}
}
map() {
map() {
// #TEST Float32Array.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");
// #END
}
}
reduce() {
reduce() {
// #TEST Float32Array.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);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Float32Array.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);
// #END
}
}
reverse() {
reverse() {
// #TEST Float32Array.reverse
let float32 = new Float32Array([1, 2, 3]);
let float32 = new Float32Array([1, 2, 3]);
float32.reverse();
float32.reverse();
expect(float32.toString()).toEqual("3,2,1");
expect(float32.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Float32Array.slice
let float32 = new Float32Array([1, 2, 3]);
let float32 = new Float32Array([1, 2, 3]);
let res = float32.slice(1);
let res = float32.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -249,18 +275,22 @@ export class TFloat32Array {
...
@@ -249,18 +275,22 @@ export class TFloat32Array {
res = float32.slice(0, 1);
res = float32.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Float32Array.sort
let numbers = new Float32Array([40, 1, 5]);
let numbers = new Float32Array([40, 1, 5]);
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Float32Array.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let float32 = new Float32Array(buffer);
let float32 = new Float32Array(buffer);
float32.set([1, 2, 3]);
float32.set([1, 2, 3]);
...
@@ -268,17 +298,21 @@ export class TFloat32Array {
...
@@ -268,17 +298,21 @@ export class TFloat32Array {
let sub = float32.subarray(0, 4);
let sub = float32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
expect(sub.toString()).toEqual("1,2,3,0");
// #END
}
}
values() {
values() {
// #TEST Float32Array.values
let arr = new Float32Array([1, 2, 3]);
let arr = new Float32Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
expect(values.next().value).toEqual(3);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let float32 = new Float32Array(buffer);
let float32 = new Float32Array(buffer);
float32[3] = 42;
float32[3] = 42;
...
@@ -287,6 +321,8 @@ export class TFloat32Array {
...
@@ -287,6 +321,8 @@ export class TFloat32Array {
let res = buffer.slice(8);
let res = buffer.slice(8);
let sliced = new Float32Array(res);
let sliced = new Float32Array(res);
expect(sliced[1]).toEqual(42);
expect(sliced[1]).toEqual(42);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TFloat64Array.uts
浏览文件 @
f36cdd44
...
@@ -34,7 +34,7 @@ export class TFloat64Array {
...
@@ -34,7 +34,7 @@ export class TFloat64Array {
this.arrayBufferSlice();
this.arrayBufferSlice();
// #endif
// #endif
}
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testfloat64() {
testfloat64() {
let float64 = new Float64Array(2);
let float64 = new Float64Array(2);
float64[0] = 42;
float64[0] = 42;
...
@@ -62,27 +62,32 @@ export class TFloat64Array {
...
@@ -62,27 +62,32 @@ export class TFloat64Array {
}
}
testSet() {
testSet() {
// #TEST Float64Array.set
let float64 = new Float64Array(8);
let float64 = new Float64Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
float64.set(array, 1);
float64.set(array, 1);
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
// #TEST Float64Array.copyWithin
let float64 = new Float64Array(8);
let float64 = new Float64Array(8);
float64.set([1, 2, 3], 1);
float64.set([1, 2, 3], 1);
float64.copyWithin(3, 0, 3);
float64.copyWithin(3, 0, 3);
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Float64Array): boolean => currentValue < 40;
// #TEST Float64Array.every
let result = new Float64Array([-10, -20, -30, -40, -50]).every((value: number, _: number, _a:
let result = new Float64Array([-10, -20, -30, -40, -50]).every((value : number, _ : number, _a : Float64Array) : boolean => value < 0);
Float64Array): boolean => value < 0); //
expect(result).toEqual(true);
expect(result).toEqual(true);
// #END
}
}
testFill() {
testFill() {
// #TEST Float64Array.fill
let float64 = new Float64Array([1, 2, 3]).fill(4);
let float64 = new Float64Array([1, 2, 3]).fill(4);
expect(float64.toString()).toEqual("4,4,4");
expect(float64.toString()).toEqual("4,4,4");
...
@@ -97,46 +102,56 @@ export class TFloat64Array {
...
@@ -97,46 +102,56 @@ export class TFloat64Array {
float64 = new Float64Array([1, 2, 3]).fill(4, -3, -2);
float64 = new Float64Array([1, 2, 3]).fill(4, -3, -2);
expect(float64.toString()).toEqual("4,2,3");
expect(float64.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// #TEST Float64Array.filter
let float64 = new Float64Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float64Array) : boolean => value >= 10);
let float64 = new Float64Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Float64Array):
boolean => value >= 10);
expect(float64.toString()).toEqual("12,44");
expect(float64.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Float64Array.find
let float64 = new Float64Array([4, 5, 8, 12]);
let float64 = new Float64Array([4, 5, 8, 12]);
let res = float64.find((value
: number, _: number, _a: Float64Array)
: boolean => value > 5);
let res = float64.find((value
: number, _ : number, _a : Float64Array)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Float64Array.findIndex
let float64 = new Float64Array([4, 6, 8, 12]);
let float64 = new Float64Array([4, 6, 8, 12]);
let res = float64.findIndex((value
: number, _: number, _a: Float64Array)
: boolean => value > 100);
let res = float64.findIndex((value
: number, _ : number, _a : Float64Array)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
let ufloat64 = new Float64Array([4, 6, 7, 120]);
let ufloat64 = new Float64Array([4, 6, 7, 120]);
res = ufloat64.findIndex((value
: number, _: number, _a: Float64Array)
: boolean => value > 100);
res = ufloat64.findIndex((value
: number, _ : number, _a : Float64Array)
: boolean => value > 100);
expect(res).toEqual(3);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Float64Array.entries
let arr = new Float64Array([10, 20, 30, 40, 50]);
let arr = new Float64Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
expect(entries.next().value[1]).toEqual(20);
// #END
}
}
includes() {
includes() {
// #TEST Float64Array.includes
let float64 = new Float64Array([1, 2, 3]);
let float64 = new Float64Array([1, 2, 3]);
let res = float64.includes(2);
let res = float64.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -146,9 +161,11 @@ export class TFloat64Array {
...
@@ -146,9 +161,11 @@ export class TFloat64Array {
res = float64.includes(3, 3);
res = float64.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Float64Array.indexOf
let float64 = new Float64Array([2, 5, 9]);
let float64 = new Float64Array([2, 5, 9]);
let res = float64.indexOf(2);
let res = float64.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -164,9 +181,11 @@ export class TFloat64Array {
...
@@ -164,9 +181,11 @@ export class TFloat64Array {
res = float64.indexOf(2, -3);
res = float64.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Float64Array.join
let float64 = new Float64Array([1, 2, 3]);
let float64 = new Float64Array([1, 2, 3]);
let res = float64.join();
let res = float64.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -176,10 +195,12 @@ export class TFloat64Array {
...
@@ -176,10 +195,12 @@ export class TFloat64Array {
res = float64.join("");
res = float64.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
//
todo 有差异 js 是keys.next().value
//
#TEST Float64Array.keys
let arr = new Float64Array([10, 20, 30, 40, 50]);
let arr = new Float64Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
...
@@ -187,46 +208,52 @@ export class TFloat64Array {
...
@@ -187,46 +208,52 @@ export class TFloat64Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
expect(keys.next().value).toEqual(4);
// #END
}
}
map() {
map() {
// #TEST Float64Array.map
let numbers = new Float64Array([1, 4, 9]);
let numbers = new Float64Array([1, 4, 9]);
let doubles = numbers.map((value
: number, _: number, _a: Float64Array)
: number => value * 2);
let doubles = numbers.map((value
: number, _ : number, _a : Float64Array)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Float64Array.reduce
let total = new Float64Array([0, 1, 2, 3]);
let total = new Float64Array([0, 1, 2, 3]);
let res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Float64Array):
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue);
number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Float64Array([0, 1, 2, 3]);
total = new Float64Array([0, 1, 2, 3]);
res = total.reduce((accumulator: number, currentValue: number, _: number, _a: Float64Array):
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Float64Array.reduceRight
let total = new Float64Array([0, 1, 2, 3]);
let total = new Float64Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a:
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue);
Float64Array): number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Float64Array([0, 1, 2, 3]);
total = new Float64Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator: number, currentValue: number, _: number, _a: Float64Array):
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Float64Array.reverse
let float64 = new Float64Array([1, 2, 3]);
let float64 = new Float64Array([1, 2, 3]);
float64.reverse();
float64.reverse();
expect(float64.toString()).toEqual("3,2,1");
expect(float64.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Float64Array.slice
let float64 = new Float64Array([1, 2, 3]);
let float64 = new Float64Array([1, 2, 3]);
let res = float64.slice(1);
let res = float64.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -239,18 +266,23 @@ export class TFloat64Array {
...
@@ -239,18 +266,23 @@ export class TFloat64Array {
res = float64.slice(0, 1);
res = float64.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Float64Array.sort
let numbers = new Float64Array([40, 1, 5]);
let numbers = new Float64Array([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Float64Array.subarray
let buffer = new ArrayBuffer(32);
let buffer = new ArrayBuffer(32);
let float64 = new Float64Array(buffer);
let float64 = new Float64Array(buffer);
float64.set([1, 2, 3]);
float64.set([1, 2, 3]);
...
@@ -258,17 +290,21 @@ export class TFloat64Array {
...
@@ -258,17 +290,21 @@ export class TFloat64Array {
let sub = float64.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");
// #END
}
}
values() {
values() {
// #TEST Float64Array.values
let arr = new Float64Array([1, 2, 3]);
let arr = new Float64Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
expect(values.next().value).toEqual(3);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST Float64Array with ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let float64 = new Float64Array(buffer);
let float64 = new Float64Array(buffer);
float64[1] = 42;
float64[1] = 42;
...
@@ -277,6 +313,8 @@ export class TFloat64Array {
...
@@ -277,6 +313,8 @@ export class TFloat64Array {
let res = buffer.slice(8);
let res = buffer.slice(8);
let sliced = new Float64Array(res);
let sliced = new Float64Array(res);
expect(sliced[0]).toEqual(42);
expect(sliced[0]).toEqual(42);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt16Array.uts
浏览文件 @
f36cdd44
...
@@ -34,7 +34,7 @@ export class TInt16Array {
...
@@ -34,7 +34,7 @@ export class TInt16Array {
// #endif
// #endif
}
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testConstructor() {
testConstructor() {
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
let int16 = new Int16Array(buffer);
...
@@ -43,29 +43,32 @@ export class TInt16Array {
...
@@ -43,29 +43,32 @@ export class TInt16Array {
}
}
testSet() {
testSet() {
// #TEST Int16Array.set
let int16 = new Int16Array(8);
let int16 = new Int16Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
int16.set(array, 1);
int16.set(array, 1);
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Int16Array.copyWithin
let int16 = new Int16Array(8);
let int16 = new Int16Array(8);
int16.set([1, 2, 3], 1);
int16.set([1, 2, 3], 1);
console.log("testCopyWith 1")
int16.copyWithin(3, 0, 3);
int16.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
//
const isBelowThreshold = (currentValue: number, index: number, array:Int16Array): boolean => currentValue < 40;
//
#TEST Int16Array.every
let result = new Int16Array([12, 5, 8, 130, 44]).every((value
: number, _ : number, _a : Int16Array) : boolean => value < 40); //
let result = new Int16Array([12, 5, 8, 130, 44]).every((value
, _, _a:Int16Array):boolean => value < 40);
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Int16Array.fill
let int16 = new Int16Array([1, 2, 3]).fill(4);
let int16 = new Int16Array([1, 2, 3]).fill(4);
expect(int16.toString()).toEqual("4,4,4");
expect(int16.toString()).toEqual("4,4,4");
...
@@ -80,44 +83,54 @@ export class TInt16Array {
...
@@ -80,44 +83,54 @@ export class TInt16Array {
int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
expect(int16.toString()).toEqual("4,2,3");
expect(int16.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// #TEST Int16Array.filter
let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a:Int16Array):boolean => value >= 10);
let int16 = new Int16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int16Array) : boolean => value >= 10);
expect(int16.toString()).toEqual("12,44");
expect(int16.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Int16Array.find
let int16 = new Int16Array([4, 5, 8, 12]);
let int16 = new Int16Array([4, 5, 8, 12]);
let res = int16.find((value
: number, _ : number, _a : Int16Array) :
boolean => value > 5);
let res = int16.find((value
, _, _a:Int16Array):
boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Int16Array.findIndex
let int16 = new Int16Array([4, 6, 8, 12]);
let int16 = new Int16Array([4, 6, 8, 12]);
let res = int16.findIndex((value
: number, _ : number, _a : Int16Array) :
boolean => value > 100);
let res = int16.findIndex((value
, _, _a:Int16Array):
boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
int16 = new Int16Array([4, 6, 7, 120]);
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);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Int16Array.entries
let arr = new Int16Array([10, 20, 30, 40, 50]);
let arr = new Int16Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
// #END
}
}
includes() {
includes() {
// #TEST Int16Array.includes
let int16 = new Int16Array([1, 2, 3]);
let int16 = new Int16Array([1, 2, 3]);
let res = int16.includes(2);
let res = int16.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -127,9 +140,11 @@ export class TInt16Array {
...
@@ -127,9 +140,11 @@ export class TInt16Array {
res = int16.includes(3, 3);
res = int16.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Int16Array.indexOf
let int16 = new Int16Array([2, 5, 9]);
let int16 = new Int16Array([2, 5, 9]);
let res = int16.indexOf(2);
let res = int16.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -145,9 +160,11 @@ export class TInt16Array {
...
@@ -145,9 +160,11 @@ export class TInt16Array {
res = int16.indexOf(2, -3);
res = int16.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Int16Array.join
let int16 = new Int16Array([1, 2, 3]);
let int16 = new Int16Array([1, 2, 3]);
let res = int16.join();
let res = int16.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -157,9 +174,11 @@ export class TInt16Array {
...
@@ -157,9 +174,11 @@ export class TInt16Array {
res = int16.join("");
res = int16.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Int16Array.keys
let arr = new Int16Array([10, 20, 30, 40, 50]);
let arr = new Int16Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
...
@@ -167,42 +186,52 @@ export class TInt16Array {
...
@@ -167,42 +186,52 @@ export class TInt16Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
expect(keys.next().value).toEqual(4);
// #END
}
}
map() {
map() {
// #TEST Int16Array.map
let numbers = new Int16Array([1, 4, 9]);
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(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Int16Array.reduce
let total = new Int16Array([0, 1, 2, 3]);
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);
expect(res).toEqual(6);
total = new Int16Array([0, 1, 2, 3]);
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);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Int16Array.reduceRight
let total = new Int16Array([0, 1, 2, 3]);
let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int16Array) :
number => accumulator + currentValue);
let res = total.reduceRight((accumulator
, currentValue, _, _a:Int16Array):
number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Int16Array([0, 1, 2, 3]);
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);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Int16Array.reverse
let int16 = new Int16Array([1, 2, 3]);
let int16 = new Int16Array([1, 2, 3]);
int16.reverse();
int16.reverse();
expect(int16.toString()).toEqual("3,2,1");
expect(int16.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Int16Array.slice
let int16 = new Int16Array([1, 2, 3]);
let int16 = new Int16Array([1, 2, 3]);
let res = int16.slice(1);
let res = int16.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -215,18 +244,22 @@ export class TInt16Array {
...
@@ -215,18 +244,22 @@ export class TInt16Array {
res = int16.slice(0, 1);
res = int16.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Int16Array.sort
let numbers = new Int16Array([40, 1, 5]);
let numbers = new Int16Array([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Int16Array.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
let int16 = new Int16Array(buffer);
int16.set([1, 2, 3]);
int16.set([1, 2, 3]);
...
@@ -234,15 +267,19 @@ export class TInt16Array {
...
@@ -234,15 +267,19 @@ export class TInt16Array {
let sub = int16.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");
// #END
}
}
values() {
values() {
// #TEST Int16Array.values
let arr = new Int16Array([1, 2, 3]);
let arr = new Int16Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int16Array
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
let int16 = new Int16Array(buffer);
int16[4] = 42;
int16[4] = 42;
...
@@ -251,6 +288,8 @@ export class TInt16Array {
...
@@ -251,6 +288,8 @@ export class TInt16Array {
let res = buffer.slice(8, 12);
let res = buffer.slice(8, 12);
let sliced = new Int16Array(res);
let sliced = new Int16Array(res);
expect(sliced[0]).toEqual(42);
expect(sliced[0]).toEqual(42);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt32Array.uts
浏览文件 @
f36cdd44
...
@@ -35,7 +35,7 @@ export class TInt32Array {
...
@@ -35,7 +35,7 @@ export class TInt32Array {
// #endif
// #endif
}
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testInt32Array() {
testInt32Array() {
let int32 = new Int32Array(2);
let int32 = new Int32Array(2);
int32[0] = 42;
int32[0] = 42;
...
@@ -63,13 +63,16 @@ export class TInt32Array {
...
@@ -63,13 +63,16 @@ export class TInt32Array {
}
}
testSet() {
testSet() {
// #TEST Int32Array.set
let int32 = new Int32Array(8);
let int32 = new Int32Array(8);
var array =[1, 2, 3]
var array =
[1, 2, 3]
int32.set(array, 1);
int32.set(array, 1);
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
// #TEST Int32Array.copyWithin
console.log("testCopyWith 1")
console.log("testCopyWith 1")
let int32 = new Int32Array(8);
let int32 = new Int32Array(8);
int32.set([1, 2, 3], 1);
int32.set([1, 2, 3], 1);
...
@@ -77,15 +80,18 @@ export class TInt32Array {
...
@@ -77,15 +80,18 @@ export class TInt32Array {
int32.copyWithin(3, 0, 3);
int32.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
console.log("testCopyWith 1")
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
//
const isBelowThreshold = (currentValue: number, index: number, array:Int32Array): boolean => currentValue < 40;
//
#TEST Int32Array.every
let result = new Int32Array([12, 5, 8, 130, 44]).every((value
:number,_ : number, _a : Int32Array): boolean => value< 40); //
let result = new Int32Array([12, 5, 8, 130, 44]).every((value
: number, _ : number, _a : Int32Array) : boolean => value < 40);
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Int32Array.fill
let int32 = new Int32Array([1, 2, 3]).fill(4);
let int32 = new Int32Array([1, 2, 3]).fill(4);
expect(int32.toString()).toEqual("4,4,4");
expect(int32.toString()).toEqual("4,4,4");
...
@@ -100,45 +106,54 @@ export class TInt32Array {
...
@@ -100,45 +106,54 @@ export class TInt32Array {
int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
expect(int32.toString()).toEqual("4,2,3");
expect(int32.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// #TEST Int32Array.filter
let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array) : boolean => value >= 10);
let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array): boolean => value>= 10);
expect(int32.toString()).toEqual("12,44");
expect(int32.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Int32Array.find
let int32 = new Int32Array([4, 5, 8, 12]);
let int32 = new Int32Array([4, 5, 8, 12]);
let res = int32.find((value : number, _ : number, _a : Int32Array): boolean => value > 5);
let res = int32.find((value : number, _ : number, _a : Int32Array)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Int32Array.findIndex
let int32 = new Int32Array([4, 6, 8, 12]);
let int32 = new Int32Array([4, 6, 8, 12]);
let res = int32.findIndex((value : number, _ : number, _a : Int32Array): boolean => value > 100);
let res = int32.findIndex((value : number, _ : number, _a : Int32Array)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
int32 = new Int32Array([4, 6, 7, 120]);
int32 = new Int32Array([4, 6, 7, 120]);
res = int32.findIndex((value : number, _ : number, _a : Int32Array): boolean => value > 100);
res = int32.findIndex((value : number, _ : number, _a : Int32Array)
: boolean => value > 100);
expect(res).toEqual(3);
expect(res).toEqual(3);
// #END
}
}
foreach() {
foreach() {
// #TEST Int32Array.forEach
new Int32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int32Array) => {
new Int32Array([0, 1, 2, 3]).forEach((value : number, index : number, _ : Int32Array) => {
console.log(`a[${index}] = ${value}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Int32Array.entries
let arr = new Int32Array([10, 20, 30, 40, 50]);
let arr = new Int32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
// #END
}
}
includes() {
includes() {
// #TEST Int32Array.includes
let int32 = new Int32Array([1, 2, 3]);
let int32 = new Int32Array([1, 2, 3]);
let res = int32.includes(2);
let res = int32.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -148,9 +163,11 @@ export class TInt32Array {
...
@@ -148,9 +163,11 @@ export class TInt32Array {
res = int32.includes(3, 3);
res = int32.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Int32Array.indexOf
let int32 = new Int32Array([2, 5, 9]);
let int32 = new Int32Array([2, 5, 9]);
let res = int32.indexOf(2);
let res = int32.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -166,9 +183,11 @@ export class TInt32Array {
...
@@ -166,9 +183,11 @@ export class TInt32Array {
res = int32.indexOf(2, -3);
res = int32.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Int32Array.join
let int32 = new Int32Array([1, 2, 3]);
let int32 = new Int32Array([1, 2, 3]);
let res = int32.join();
let res = int32.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -178,48 +197,60 @@ export class TInt32Array {
...
@@ -178,48 +197,60 @@ export class TInt32Array {
res = int32.join("");
res = int32.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Int32Array.keys
let arr = new Int32Array([10, 20, 30, 40, 50]);
let arr = new Int32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
// #END
}
}
map() {
map() {
// #TEST Int32Array.map
let numbers = new Int32Array([1, 4, 9]);
let numbers = new Int32Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Int32Array): number => value * 2);
let doubles = numbers.map((value : number, _ : number, _a : Int32Array)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Int32Array.reduce
let total = new Int32Array([0, 1, 2, 3]);
let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array): number => accumulator + currentValue);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array)
: number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]);
total = new Int32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array): number => accumulator + currentValue, 8);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array)
: number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Int32Array.reduceRight
let total = new Int32Array([0, 1, 2, 3]);
let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int32Array)
: number => accumulator + currentValue);
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int32Array)
: number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]);
total = new Int32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int32Array)
: number => accumulator + currentValue, 8);
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int32Array)
: number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Int32Array.reverse
let int32 = new Int32Array([1, 2, 3]);
let int32 = new Int32Array([1, 2, 3]);
int32.reverse();
int32.reverse();
expect(int32.toString()).toEqual("3,2,1");
expect(int32.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Int32Array.slice
let int32 = new Int32Array([1, 2, 3]);
let int32 = new Int32Array([1, 2, 3]);
let res = int32.slice(1);
let res = int32.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -232,18 +263,22 @@ export class TInt32Array {
...
@@ -232,18 +263,22 @@ export class TInt32Array {
res = int32.slice(0, 1);
res = int32.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Int32Array.sort
let numbers = new Int32Array([40, 1, 5]);
let numbers = new Int32Array([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Int32Array.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
let int32 = new Int32Array(buffer);
int32.set([1, 2, 3]);
int32.set([1, 2, 3]);
...
@@ -251,15 +286,19 @@ export class TInt32Array {
...
@@ -251,15 +286,19 @@ export class TInt32Array {
let sub = int32.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");
// #END
}
}
values() {
values() {
// #TEST Int32Array.values
let arr = new Int32Array([1, 2, 3]);
let arr = new Int32Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
let int32 = new Int32Array(buffer);
int32[3] = 42;
int32[3] = 42;
...
@@ -268,6 +307,8 @@ export class TInt32Array {
...
@@ -268,6 +307,8 @@ export class TInt32Array {
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);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt8Array.uts
浏览文件 @
f36cdd44
...
@@ -35,7 +35,7 @@ export class TInt8Array {
...
@@ -35,7 +35,7 @@ export class TInt8Array {
//#endif
//#endif
}
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testConstructor() {
testConstructor() {
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int8View = new Int8Array(buffer);
let int8View = new Int8Array(buffer);
...
@@ -44,30 +44,35 @@ export class TInt8Array {
...
@@ -44,30 +44,35 @@ export class TInt8Array {
}
}
testSet() {
testSet() {
// #TEST Int8Array.set
let int8 = new Int8Array(8);
let int8 = new Int8Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
int8.set(array, 1);
int8.set(array, 1);
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Int8Array.copyWith
let int8 = new Int8Array(8);
let int8 = new Int8Array(8);
int8.set([1, 2, 3], 1);
int8.set([1, 2, 3], 1);
console.log("testCopyWith 1")
int8.copyWithin(3, 0, 3);
int8.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
// #TEST Int8Array.every
// const isBelowThreshold = (currentValue: number, index: number, array:Int8Array): boolean => currentValue < 40;
// const isBelowThreshold = (currentValue: number, index: number, array:Int8Array): boolean => currentValue < 40;
let result = new Int8Array([12, 5, 8, 130, 44]).every((value
: number, _: number, _a: Int8Array)
: boolean =>
let result = new Int8Array([12, 5, 8, 130, 44]).every((value
: number, _ : number, _a : Int8Array)
: boolean =>
value < 40);
//
value < 40);
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Int8Array.fill
let int8 = new Int8Array([1, 2, 3]).fill(4);
let int8 = new Int8Array([1, 2, 3]).fill(4);
expect(int8.toString()).toEqual("4,4,4");
expect(int8.toString()).toEqual("4,4,4");
...
@@ -82,46 +87,58 @@ export class TInt8Array {
...
@@ -82,46 +87,58 @@ export class TInt8Array {
int8 = new Int8Array([1, 2, 3]).fill(4, -3, -2);
int8 = new Int8Array([1, 2, 3]).fill(4, -3, -2);
expect(int8.toString()).toEqual("4,2,3");
expect(int8.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// #TEST Int8Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let int8 = new Int8Array([12, 5, 8, 44]).filter((value
: number, _: number, _a: Int8Array)
: boolean =>
let int8 = new Int8Array([12, 5, 8, 44]).filter((value
: number, _ : number, _a : Int8Array)
: boolean =>
value >= 10);
value >= 10);
expect(int8.toString()).toEqual("12,44");
expect(int8.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Int8Array.find
let int8 = new Int8Array([4, 5, 8, 12]);
let int8 = new Int8Array([4, 5, 8, 12]);
let res = int8.find((value
: number, _: number, _a: Int8Array)
: boolean => value > 5);
let res = int8.find((value
: number, _ : number, _a : Int8Array)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Int8Array.findIndex
let int8 = new Int8Array([4, 6, 8, 12]);
let int8 = new Int8Array([4, 6, 8, 12]);
let res = int8.findIndex((value
: number, _: number, _a: Int8Array)
: boolean => value > 100);
let res = int8.findIndex((value
: number, _ : number, _a : Int8Array)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
int8 = new Int8Array([4, 6, 7, 120]);
int8 = new Int8Array([4, 6, 7, 120]);
res = int8.findIndex((value
: number, _: number, _a: Int8Array)
: boolean => value > 100);
res = int8.findIndex((value
: number, _ : number, _a : Int8Array)
: boolean => value > 100);
expect(res).toEqual(3);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Int8Array.entries
let arr = new Int8Array([10, 20, 30, 40, 50]);
let arr = new Int8Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
expect(entries.next().value[1]).toEqual(20);
// #END
}
}
includes() {
includes() {
// #TEST Int8Array.includes
let int8 = new Int8Array([1, 2, 3]);
let int8 = new Int8Array([1, 2, 3]);
let res = int8.includes(2);
let res = int8.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -131,9 +148,11 @@ export class TInt8Array {
...
@@ -131,9 +148,11 @@ export class TInt8Array {
res = int8.includes(3, 3);
res = int8.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Int8Array.indexOf
let int8 = new Int8Array([2, 5, 9]);
let int8 = new Int8Array([2, 5, 9]);
let res = int8.indexOf(2);
let res = int8.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -149,9 +168,11 @@ export class TInt8Array {
...
@@ -149,9 +168,11 @@ export class TInt8Array {
res = int8.indexOf(2, -3);
res = int8.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Int8Array.join
let int8 = new Int8Array([1, 2, 3]);
let int8 = new Int8Array([1, 2, 3]);
let res = int8.join();
let res = int8.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -161,9 +182,11 @@ export class TInt8Array {
...
@@ -161,9 +182,11 @@ export class TInt8Array {
res = int8.join("");
res = int8.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Int8Array.keys
let arr = new Int8Array([10, 20, 30, 40, 50]);
let arr = new Int8Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
...
@@ -171,47 +194,57 @@ export class TInt8Array {
...
@@ -171,47 +194,57 @@ export class TInt8Array {
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
expect(keys.next().value).toEqual(4);
// #END
}
}
map() {
map() {
// #TEST Int8Array.map
let numbers = new Int8Array([1, 4, 9]);
let numbers = new Int8Array([1, 4, 9]);
let doubles = numbers.map((value
: number, _: number, _a: Int8Array)
: number => value * 2);
let doubles = numbers.map((value
: number, _ : number, _a : Int8Array)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Int8Array.reduce
let total = new Int8Array([0, 1, 2, 3]);
let total = new Int8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Int8Array)
:
let res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Int8Array)
:
number => accumulator + currentValue);
number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Int8Array([0, 1, 2, 3]);
total = new Int8Array([0, 1, 2, 3]);
res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Int8Array)
: number =>
res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Int8Array)
: number =>
accumulator + currentValue, 8);
accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Int8Array.reduceRight
let total = new Int8Array([0, 1, 2, 3]);
let total = new Int8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a: Int8Array)
:
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int8Array)
:
number => accumulator + currentValue);
number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Int8Array([0, 1, 2, 3]);
total = new Int8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a: Int8Array)
:
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Int8Array)
:
number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Int8Array.reverse
let int8 = new Int8Array([1, 2, 3]);
let int8 = new Int8Array([1, 2, 3]);
int8.reverse();
int8.reverse();
expect(int8.toString()).toEqual("3,2,1");
expect(int8.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Int8Array.slice
let int8 = new Int8Array([1, 2, 3]);
let int8 = new Int8Array([1, 2, 3]);
let res = int8.slice(1);
let res = int8.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -224,18 +257,22 @@ export class TInt8Array {
...
@@ -224,18 +257,22 @@ export class TInt8Array {
res = int8.slice(0, 1);
res = int8.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Int8Array.sort
let numbers = new Int8Array([40, 1, 5]);
let numbers = new Int8Array([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Int8Array.subarray
let buffer = new ArrayBuffer(8);
let buffer = new ArrayBuffer(8);
let int8 = new Int8Array(buffer);
let int8 = new Int8Array(buffer);
int8.set([1, 2, 3]);
int8.set([1, 2, 3]);
...
@@ -243,25 +280,31 @@ export class TInt8Array {
...
@@ -243,25 +280,31 @@ export class TInt8Array {
let sub = int8.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");
// #END
}
}
values() {
values() {
// #TEST Int8Array.values
let arr = new Int8Array([1, 2, 3]);
let arr = new Int8Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
expect(values.next().value).toEqual(3);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int8Array
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let int8 = new Int8Array(buffer);
let int8 = new Int8Array(buffer);
int8[4] = 42;
int8[4] = 42;
expect(int8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0");
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);
let sliced = new Int8Array(res);
expect(sliced[0]).toEqual(42);
expect(sliced[0]).toEqual(42);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUInt8Array.uts
浏览文件 @
f36cdd44
...
@@ -55,29 +55,36 @@ export class TUint8Array {
...
@@ -55,29 +55,36 @@ export class TUint8Array {
}
}
testSet() {
testSet() {
// #TEST Uint8Array.set
let uint8 = new Uint8Array(8);
let uint8 = new Uint8Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
uint8.set(array, 1);
uint8.set(array, 1);
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Uint8Array.copyWithin
console.log("testCopyWith 1");
let uint8 = new Uint8Array(8);
let uint8 = new Uint8Array(8);
uint8.set([1, 2, 3], 1);
uint8.set([1, 2, 3], 1);
uint8.copyWithin(3, 0, 3);
uint8.copyWithin(3, 0, 3);
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8Array): boolean => currentValue < 40;
// #TEST Uint8Array.every
let result = new Uint8Array([12, 5, 8, 130, 44]).every((value: number, _: number, _a: Uint8Array): boolean =>
// const isBelowThreshold = (currentValue: number, index: number, array: Uint8Array): boolean => currentValue < 40;
value < 40); //
let result = new Uint8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint8Array) : boolean =>
value < 40);
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Uint8Array.fill
let uint8 = new Uint8Array([1, 2, 3]).fill(4);
let uint8 = new Uint8Array([1, 2, 3]).fill(4);
expect(uint8.toString()).toEqual("4,4,4");
expect(uint8.toString()).toEqual("4,4,4");
...
@@ -92,46 +99,54 @@ export class TUint8Array {
...
@@ -92,46 +99,54 @@ export class TUint8Array {
uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
expect(uint8.toString()).toEqual("4,2,3");
expect(uint8.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// #TEST Uint8Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// 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 >=
let uint8 = new Uint8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint8Array) : boolean => value >= 10);
10);
expect(uint8.toString()).toEqual("12,44");
expect(uint8.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Uint8Array.find
let uint8 = new Uint8Array([4, 5, 8, 12]);
let uint8 = new Uint8Array([4, 5, 8, 12]);
let res = uint8.find((value
: number, _: number, _a: Uint8Array)
: boolean => value > 5);
let res = uint8.find((value
: number, _ : number, _a : Uint8Array)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Uint8Array.findIndex
let uint8 = new Uint8Array([4, 6, 8, 12]);
let uint8 = new Uint8Array([4, 6, 8, 12]);
let res = uint8.findIndex((value
: number, _: number, _a: Uint8Array)
: boolean => value > 100);
let res = uint8.findIndex((value
: number, _ : number, _a : Uint8Array)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
let uuint8 = new Uint8Array([4, 6, 7, 120]);
let uuint8 = new Uint8Array([4, 6, 7, 120]);
res = uuint8.findIndex((value
: number, _: number, _a: Uint8Array)
: boolean => value > 100);
res = uuint8.findIndex((value
: number, _ : number, _a : Uint8Array)
: boolean => value > 100);
expect(res).toEqual(3);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Uint8Array.entries
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
// #END
}
}
includes() {
includes() {
// #TEST Uint8Array.includes
let uint8 = new Uint8Array([1, 2, 3]);
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.includes(2);
let res = uint8.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -141,9 +156,11 @@ export class TUint8Array {
...
@@ -141,9 +156,11 @@ export class TUint8Array {
res = uint8.includes(3, 3);
res = uint8.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Uint8Array.indexOf
let uint8 = new Uint8Array([2, 5, 9]);
let uint8 = new Uint8Array([2, 5, 9]);
let res = uint8.indexOf(2);
let res = uint8.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -159,9 +176,11 @@ export class TUint8Array {
...
@@ -159,9 +176,11 @@ export class TUint8Array {
res = uint8.indexOf(2, -3);
res = uint8.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Uint8Array.join
let uint8 = new Uint8Array([1, 2, 3]);
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.join();
let res = uint8.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -171,52 +190,62 @@ export class TUint8Array {
...
@@ -171,52 +190,62 @@ export class TUint8Array {
res = uint8.join("");
res = uint8.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Uint8Array.keys
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
// #END
}
}
map() {
map() {
// #TEST Uint8Array.map
let numbers = new Uint8Array([1, 4, 9]);
let numbers = new Uint8Array([1, 4, 9]);
let doubles = numbers.map((value
: number, _: number, _a: Uint8Array)
: number => value * 2);
let doubles = numbers.map((value
: number, _ : number, _a : Uint8Array)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Uint8Array.reduce
let total = new Uint8Array([0, 1, 2, 3]);
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint8Array)
: number =>
let res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint8Array)
: number =>
accumulator + currentValue);
accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]);
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint8Array)
: number => accumulator +
res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint8Array)
: number => accumulator +
currentValue, 8);
currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Uint8Array.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, _a: Uint8Array)
: number =>
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint8Array)
: number =>
accumulator + currentValue);
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, _a: Uint8Array)
: number =>
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint8Array)
: number =>
accumulator + currentValue, 8);
accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Uint8Array.reverse
let uint8 = new Uint8Array([1, 2, 3]);
let uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse();
uint8.reverse();
expect(uint8.toString()).toEqual("3,2,1");
expect(uint8.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Uint8Array.slice
let uint8 = new Uint8Array([1, 2, 3]);
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.slice(1);
let res = uint8.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -229,18 +258,22 @@ export class TUint8Array {
...
@@ -229,18 +258,22 @@ export class TUint8Array {
res = uint8.slice(0, 1);
res = uint8.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Uint8Array.sort
let numbers = new Uint8Array([40, 1, 5]);
let numbers = new Uint8Array([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Uint8Array.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
let uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]);
uint8.set([1, 2, 3]);
...
@@ -248,16 +281,19 @@ export class TUint8Array {
...
@@ -248,16 +281,19 @@ export class TUint8Array {
let sub = uint8.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");
// #END
}
}
values() {
values() {
// #TEST Uint8Array.values
let arr = new Uint8Array([1, 2, 3]);
let arr = new Uint8Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Uint8Array
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
let uint8 = new Uint8Array(buffer);
uint8[4] = 42;
uint8[4] = 42;
...
@@ -266,6 +302,8 @@ export class TUint8Array {
...
@@ -266,6 +302,8 @@ export class TUint8Array {
let res = buffer.slice(4, 12);
let res = buffer.slice(4, 12);
let sliced = new Uint8Array(res);
let sliced = new Uint8Array(res);
expect(sliced[0]).toEqual(42);
expect(sliced[0]).toEqual(42);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
浏览文件 @
f36cdd44
...
@@ -35,7 +35,7 @@ export class TUint8ClampedArray {
...
@@ -35,7 +35,7 @@ export class TUint8ClampedArray {
// #endif
// #endif
}
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testMAX() {
testMAX() {
let uint8Clamped = new Uint8ClampedArray(16);
let uint8Clamped = new Uint8ClampedArray(16);
uint8Clamped[0] = 255;
uint8Clamped[0] = 255;
...
@@ -50,29 +50,36 @@ export class TUint8ClampedArray {
...
@@ -50,29 +50,36 @@ export class TUint8ClampedArray {
}
}
testSet() {
testSet() {
// #TEST Uint8ClampedArray.set
let uint8Clamped = new Uint8ClampedArray(8);
let uint8Clamped = new Uint8ClampedArray(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
uint8Clamped.set(array, 1);
uint8Clamped.set(array, 1);
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
// #TEST Uint8ClampedArray.copyWithin
console.log("testCopyWith 1")
console.log("testCopyWith 1")
let uint8Clamped = new Uint8ClampedArray(8);
let uint8Clamped = new Uint8ClampedArray(8);
uint8Clamped.set([1, 2, 3], 1);
uint8Clamped.set([1, 2, 3], 1);
uint8Clamped.copyWithin(3, 0, 3);
uint8Clamped.copyWithin(3, 0, 3);
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
// #TEST Uint8ClampedArray.every
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8ClampedArray): boolean => currentValue < 40;
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8ClampedArray): boolean => currentValue < 40;
let result = new Uint8ClampedArray([12, 5, 8, 130, 44]).every((value
: number, _: number, _a
:
let result = new Uint8ClampedArray([12, 5, 8, 130, 44]).every((value
: number, _ : number, _a
:
Uint8ClampedArray): boolean => value < 40); //
Uint8ClampedArray)
: boolean => value < 40); //
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Uint8ClampedArray.fill
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4);
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4);
expect(uint8Clamped.toString()).toEqual("4,4,4");
expect(uint8Clamped.toString()).toEqual("4,4,4");
...
@@ -87,46 +94,58 @@ export class TUint8ClampedArray {
...
@@ -87,46 +94,58 @@ export class TUint8ClampedArray {
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2);
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2);
expect(uint8Clamped.toString()).toEqual("4,2,3");
expect(uint8Clamped.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// #TEST Uint8ClampedArray.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value
: number, _: number, _a
:
let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value
: number, _ : number, _a
:
Uint8ClampedArray): boolean => value >= 10);
Uint8ClampedArray)
: boolean => value >= 10);
expect(uint8Clamped.toString()).toEqual("12,44");
expect(uint8Clamped.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Uint8ClampedArray.find
let uint8Clamped = new Uint8ClampedArray([4, 5, 8, 12]);
let uint8Clamped = new Uint8ClampedArray([4, 5, 8, 12]);
let res = uint8Clamped.find((value
: number, _: number, _a: Uint8ClampedArray)
: boolean => value > 5);
let res = uint8Clamped.find((value
: number, _ : number, _a : Uint8ClampedArray)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Uint8ClampedArray.findIndex
let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]);
let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]);
let res = uint8Clamped.findIndex((value
: number, _: number, _a: Uint8ClampedArray)
: boolean => value > 100);
let res = uint8Clamped.findIndex((value
: number, _ : number, _a : Uint8ClampedArray)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]);
let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]);
res = uuint8Clamped.findIndex((value
: number, _: number, _a: Uint8ClampedArray)
: boolean => value > 100);
res = uuint8Clamped.findIndex((value
: number, _ : number, _a : Uint8ClampedArray)
: boolean => value > 100);
expect(res).toEqual(3);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Uint8ClampedArray.entries
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
// #END
}
}
includes() {
includes() {
// #TEST Uint8ClampedArray.includes
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.includes(2);
let res = uint8Clamped.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -136,9 +155,11 @@ export class TUint8ClampedArray {
...
@@ -136,9 +155,11 @@ export class TUint8ClampedArray {
res = uint8Clamped.includes(3, 3);
res = uint8Clamped.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Uint8ClampedArray.indexOf
let uint8Clamped = new Uint8ClampedArray([2, 5, 9]);
let uint8Clamped = new Uint8ClampedArray([2, 5, 9]);
let res = uint8Clamped.indexOf(2);
let res = uint8Clamped.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -154,9 +175,10 @@ export class TUint8ClampedArray {
...
@@ -154,9 +175,10 @@ export class TUint8ClampedArray {
res = uint8Clamped.indexOf(2, -3);
res = uint8Clamped.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Uint8ClampedArray.join
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.join();
let res = uint8Clamped.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -166,52 +188,63 @@ export class TUint8ClampedArray {
...
@@ -166,52 +188,63 @@ export class TUint8ClampedArray {
res = uint8Clamped.join("");
res = uint8Clamped.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Uint8ClampedArray.keys
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
// #END
}
}
map() {
map() {
// #TEST Uint8ClampedArray.map
let numbers = new Uint8ClampedArray([1, 4, 9]);
let numbers = new Uint8ClampedArray([1, 4, 9]);
let doubles = numbers.map((value
: number, _: number, _a: Uint8ClampedArray)
: number => value * 2);
let doubles = numbers.map((value
: number, _ : number, _a : Uint8ClampedArray)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Uint8ClampedArray.reduce
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduce((accumulator
: number, currentValue: number, _: number, _a:
let res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
Uint8ClampedArray): number =>
accumulator + currentValue);
accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint8ClampedArray([0, 1, 2, 3]);
total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint8ClampedArray):
res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
number =>
accumulator + currentValue, 8);
accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Uint8ClampedArray.reduceRight
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a:
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
Uint8ClampedArray): number =>
accumulator + currentValue);
accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint8ClampedArray([0, 1, 2, 3]);
total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a:
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
Uint8ClampedArray): number =>
accumulator + currentValue, 8);
accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Uint8ClampedArray.reverse
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
uint8Clamped.reverse();
uint8Clamped.reverse();
expect(uint8Clamped.toString()).toEqual("3,2,1");
expect(uint8Clamped.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Uint8ClampedArray.slice
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.slice(1);
let res = uint8Clamped.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -224,18 +257,21 @@ export class TUint8ClampedArray {
...
@@ -224,18 +257,21 @@ export class TUint8ClampedArray {
res = uint8Clamped.slice(0, 1);
res = uint8Clamped.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Uint8ClampedArray.sort
let numbers = new Uint8ClampedArray([40, 1, 5]);
let numbers = new Uint8ClampedArray([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Uint8ClampedArray.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped.set([1, 2, 3]);
uint8Clamped.set([1, 2, 3]);
...
@@ -243,16 +279,19 @@ export class TUint8ClampedArray {
...
@@ -243,16 +279,19 @@ export class TUint8ClampedArray {
let sub = uint8Clamped.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");
// #END
}
}
values() {
values() {
// #TEST Uint8ClampedArray.values
let arr = new Uint8ClampedArray([1, 2, 3]);
let arr = new Uint8ClampedArray([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Uint8ClampedArray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped[4] = 42;
uint8Clamped[4] = 42;
...
@@ -261,6 +300,8 @@ export class TUint8ClampedArray {
...
@@ -261,6 +300,8 @@ export class TUint8ClampedArray {
let res = buffer.slice(4, 12);
let res = buffer.slice(4, 12);
let sliced = new Uint8ClampedArray(res);
let sliced = new Uint8ClampedArray(res);
expect(sliced[0]).toEqual(42);
expect(sliced[0]).toEqual(42);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUint16Array.uts
浏览文件 @
f36cdd44
...
@@ -63,30 +63,36 @@ export class TUint16Array {
...
@@ -63,30 +63,36 @@ export class TUint16Array {
}
}
testSet() {
testSet() {
// #TEST Uint16Array.set
let uint16 = new Uint16Array(8);
let uint16 = new Uint16Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
uint16.set(array, 1);
uint16.set(array, 1);
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
// #TEST Uint16Array.copyWith
console.log("testCopyWith 1")
console.log("testCopyWith 1")
let uint16 = new Uint16Array(8);
let uint16 = new Uint16Array(8);
uint16.set([1, 2, 3], 1);
uint16.set([1, 2, 3], 1);
console.log("testCopyWith
1
")
console.log("testCopyWith
2
")
uint16.copyWithin(3, 0, 3);
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");
expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
// const isBelowThreshold = (currentValue: number, index: number, array:Uint16Array): boolean => currentValue < 40;
// #TEST Uint16Array.every
let result = new Uint16Array([12, 5, 8, 130, 44]).every((value: number, _: number, _a: Uint16Array):
// const isBelowThreshold = (currentValue: number, index: number, array: Uint16Array): boolean => currentValue < 40;
boolean => value < 40); //
let result = new Uint16Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint16Array) :
boolean => value < 40);
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Uint16Array.fill
let uint16 = new Uint16Array([1, 2, 3]).fill(4);
let uint16 = new Uint16Array([1, 2, 3]).fill(4);
expect(uint16.toString()).toEqual("4,4,4");
expect(uint16.toString()).toEqual("4,4,4");
...
@@ -101,46 +107,57 @@ export class TUint16Array {
...
@@ -101,46 +107,57 @@ export class TUint16Array {
uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2);
uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2);
expect(uint16.toString()).toEqual("4,2,3");
expect(uint16.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// #TEST Uint16Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint16 = new Uint16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint16Array) :
let uint16 = new Uint16Array([12, 5, 8, 44]).filter((value: number, _: number, _a: Uint16Array):
boolean => value >= 10);
boolean => value >= 10);
expect(uint16.toString()).toEqual("12,44");
expect(uint16.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Uint16Array.find
let uint16 = new Uint16Array([4, 5, 8, 12]);
let uint16 = new Uint16Array([4, 5, 8, 12]);
let res = uint16.find((value
: number, _: number, _a: Uint16Array)
: boolean => value > 5);
let res = uint16.find((value
: number, _ : number, _a : Uint16Array)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Uint16Array.findIndex
let uint16 = new Uint16Array([4, 6, 8, 12]);
let uint16 = new Uint16Array([4, 6, 8, 12]);
let res = uint16.findIndex((value
: number, _: number, _a: Uint16Array)
: boolean => value > 100);
let res = uint16.findIndex((value
: number, _ : number, _a : Uint16Array)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
let uuint16 = new Uint16Array([4, 6, 7, 120]);
let uuint16 = new Uint16Array([4, 6, 7, 120]);
res = uuint16.findIndex((value
: number, _: number, _a: Uint16Array)
: boolean => value > 100);
res = uuint16.findIndex((value
: number, _ : number, _a : Uint16Array)
: boolean => value > 100);
expect(res).toEqual(3);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Uint16Array.entries
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
// #END
}
}
includes() {
includes() {
// #TEST Uint16Array.includes
let uint16 = new Uint16Array([1, 2, 3]);
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.includes(2);
let res = uint16.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -150,9 +167,10 @@ export class TUint16Array {
...
@@ -150,9 +167,10 @@ export class TUint16Array {
res = uint16.includes(3, 3);
res = uint16.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Uint16Array.indexOf
let uint16 = new Uint16Array([2, 5, 9]);
let uint16 = new Uint16Array([2, 5, 9]);
let res = uint16.indexOf(2);
let res = uint16.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -168,9 +186,11 @@ export class TUint16Array {
...
@@ -168,9 +186,11 @@ export class TUint16Array {
res = uint16.indexOf(2, -3);
res = uint16.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Uint16Array.join
let uint16 = new Uint16Array([1, 2, 3]);
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.join();
let res = uint16.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -180,52 +200,65 @@ export class TUint16Array {
...
@@ -180,52 +200,65 @@ export class TUint16Array {
res = uint16.join("");
res = uint16.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Uint16Array.keys
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
// #END
}
}
map() {
map() {
// #TEST Uint16Array.map
let numbers = new Uint16Array([1, 4, 9]);
let numbers = new Uint16Array([1, 4, 9]);
let doubles = numbers.map((value
: number, _: number, _a: Uint16Array)
: number => value * 2);
let doubles = numbers.map((value
: number, _ : number, _a : Uint16Array)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Uint16Array.reduce
let total = new Uint16Array([0, 1, 2, 3]);
let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint16Array):
let res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint16Array) : number =>
number =>
accumulator + currentValue);
accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]);
total = new Uint16Array([0, 1, 2, 3]);
res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint16Array):
res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint16Array) : number =>
number =>
accumulator + currentValue, 8);
accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Uint16Array.reduceRight
let total = new Uint16Array([0, 1, 2, 3]);
let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a: Uint16Array):
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint16Array) : number =>
number =>
accumulator + currentValue);
accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]);
total = new Uint16Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a: Uint16Array):
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint16Array) : number =>
number =>
accumulator + currentValue, 8);
accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Uint16Array.reverse
let uint16 = new Uint16Array([1, 2, 3]);
let uint16 = new Uint16Array([1, 2, 3]);
uint16.reverse();
uint16.reverse();
expect(uint16.toString()).toEqual("3,2,1");
expect(uint16.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Uint16Array.slice
let uint16 = new Uint16Array([1, 2, 3]);
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.slice(1);
let res = uint16.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -238,18 +271,21 @@ export class TUint16Array {
...
@@ -238,18 +271,21 @@ export class TUint16Array {
res = uint16.slice(0, 1);
res = uint16.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Uint16Array.sort
let numbers = new Uint16Array([40, 1, 5]);
let numbers = new Uint16Array([40, 1, 5]);
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Uint16Array.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
let uint16 = new Uint16Array(buffer);
uint16.set([1, 2, 3]);
uint16.set([1, 2, 3]);
...
@@ -257,16 +293,19 @@ export class TUint16Array {
...
@@ -257,16 +293,19 @@ export class TUint16Array {
let sub = uint16.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");
// #END
}
}
values() {
values() {
// #TEST Uint16Array.values
let arr = new Uint16Array([1, 2, 3]);
let arr = new Uint16Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST Uint16Array.arrayBufferSlice
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
let uint16 = new Uint16Array(buffer);
uint16[4] = 42;
uint16[4] = 42;
...
@@ -275,7 +314,9 @@ export class TUint16Array {
...
@@ -275,7 +314,9 @@ export class TUint16Array {
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);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUint32Array.uts
浏览文件 @
f36cdd44
...
@@ -35,7 +35,7 @@ export class TUint32Array {
...
@@ -35,7 +35,7 @@ export class TUint32Array {
// #endif
// #endif
}
}
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
testuint32() {
testuint32() {
let uint32 = new Uint32Array(2);
let uint32 = new Uint32Array(2);
uint32[0] = 42;
uint32[0] = 42;
...
@@ -63,30 +63,36 @@ export class TUint32Array {
...
@@ -63,30 +63,36 @@ export class TUint32Array {
}
}
testSet() {
testSet() {
// #TEST Uint32Array.set
let uint32 = new Uint32Array(8);
let uint32 = new Uint32Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
uint32.set(array, 1);
uint32.set(array, 1);
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
// #END
}
}
testCopyWith() {
testCopyWith() {
console.log("testCopyWith 1")
// #TEST Uint32Array.copyWithin
console.log("testCopyWith 1");
let uint32 = new Uint32Array(8);
let uint32 = new Uint32Array(8);
uint32.set([1, 2, 3], 1);
uint32.set([1, 2, 3], 1);
console.log("testCopyWith 1")
console.log("testCopyWith 1")
;
uint32.copyWithin(3, 0, 3);
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");
expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0");
// #END
}
}
testEvery() {
testEvery() {
//
const isBelowThreshold = (currentValue: number, index: number, array:Uint32Array): boolean => currentValue < 40;
//
#TEST Uint32Array.every
let result = new Uint32Array([12, 5, 8, 130, 44]).every((value: number, _: number, _a: Uint32Array):
// const isBelowThreshold = (currentValue: number, index: number, array: Uint32Array): boolean => currentValue < 40;
boolean => value < 40); //
let result = new Uint32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint32Array) : boolean => value < 40);
expect(result).toEqual(false);
expect(result).toEqual(false);
// #END
}
}
testFill() {
testFill() {
// #TEST Uint32Array.fill
let uint32 = new Uint32Array([1, 2, 3]).fill(4);
let uint32 = new Uint32Array([1, 2, 3]).fill(4);
expect(uint32.toString()).toEqual("4,4,4");
expect(uint32.toString()).toEqual("4,4,4");
...
@@ -101,46 +107,53 @@ export class TUint32Array {
...
@@ -101,46 +107,53 @@ export class TUint32Array {
uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2);
uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2);
expect(uint32.toString()).toEqual("4,2,3");
expect(uint32.toString()).toEqual("4,2,3");
// #END
}
}
testFilter() {
testFilter() {
// #TEST Uint32Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
// 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");
expect(uint32.toString()).toEqual("12,44");
// #END
}
}
find() {
find() {
// #TEST Uint32Array.find
let uint32 = new Uint32Array([4, 5, 8, 12]);
let uint32 = new Uint32Array([4, 5, 8, 12]);
let res = uint32.find((value
: number, _: number, _a: Uint32Array)
: boolean => value > 5);
let res = uint32.find((value
: number, _ : number, _a : Uint32Array)
: boolean => value > 5);
expect(res).toEqual(8);
expect(res).toEqual(8);
// #END
}
}
findIndex() {
findIndex() {
// #TEST Uint32Array.findIndex
let uint32 = new Uint32Array([4, 6, 8, 12]);
let uint32 = new Uint32Array([4, 6, 8, 12]);
let res = uint32.findIndex((value
: number, _: number, _a: Uint32Array)
: boolean => value > 100);
let res = uint32.findIndex((value
: number, _ : number, _a : Uint32Array)
: boolean => value > 100);
expect(res).toEqual(-1);
expect(res).toEqual(-1);
let uuint32 = new Uint32Array([4, 6, 7, 120]);
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);
expect(res).toEqual(3);
// #END
}
}
foreach() {
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}`);
console.log(`a[${index}] = ${value}`);
});
});
// #END
}
}
iterator() {
iterator() {
// #TEST Uint32Array.entries
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(10);
// #END
}
}
includes() {
includes() {
// #TEST Uint32Array.includes
let uint32 = new Uint32Array([1, 2, 3]);
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.includes(2);
let res = uint32.includes(2);
expect(res).toEqual(true);
expect(res).toEqual(true);
...
@@ -150,9 +163,11 @@ export class TUint32Array {
...
@@ -150,9 +163,11 @@ export class TUint32Array {
res = uint32.includes(3, 3);
res = uint32.includes(3, 3);
expect(res).toEqual(false);
expect(res).toEqual(false);
// #END
}
}
indexOf() {
indexOf() {
// #TEST Uint32Array.indexOf
let uint32 = new Uint32Array([2, 5, 9]);
let uint32 = new Uint32Array([2, 5, 9]);
let res = uint32.indexOf(2);
let res = uint32.indexOf(2);
expect(res).toEqual(0);
expect(res).toEqual(0);
...
@@ -168,9 +183,10 @@ export class TUint32Array {
...
@@ -168,9 +183,10 @@ export class TUint32Array {
res = uint32.indexOf(2, -3);
res = uint32.indexOf(2, -3);
expect(res).toEqual(0);
expect(res).toEqual(0);
// #END
}
}
join() {
join() {
// #TEST Uint32Array.join
let uint32 = new Uint32Array([1, 2, 3]);
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.join();
let res = uint32.join();
expect(res).toEqual("1,2,3");
expect(res).toEqual("1,2,3");
...
@@ -180,52 +196,63 @@ export class TUint32Array {
...
@@ -180,52 +196,63 @@ export class TUint32Array {
res = uint32.join("");
res = uint32.join("");
expect(res).toEqual("123");
expect(res).toEqual("123");
// #END
}
}
keys() {
keys() {
// #TEST Uint32Array.keys
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(0);
// #END
}
}
map() {
map() {
// #TEST Uint32Array.map
let numbers = new Uint32Array([1, 4, 9]);
let numbers = new Uint32Array([1, 4, 9]);
let doubles = numbers.map((value
: number, _: number, _a: Uint32Array)
: number => value * 2);
let doubles = numbers.map((value
: number, _ : number, _a : Uint32Array)
: number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
}
reduce() {
reduce() {
// #TEST Uint32Array.reduce
let total = new Uint32Array([0, 1, 2, 3]);
let total = new Uint32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint32Array)
:
let res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint32Array)
:
number => accumulator + currentValue);
number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint32Array([0, 1, 2, 3]);
total = new Uint32Array([0, 1, 2, 3]);
res = total.reduce((accumulator
: number, currentValue: number, _: number, _a: Uint32Array)
:
res = total.reduce((accumulator
: number, currentValue : number, _ : number, _a : Uint32Array)
:
number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reduceRight() {
reduceRight() {
// #TEST Uint32Array.reduceRight
let total = new Uint32Array([0, 1, 2, 3]);
let total = new Uint32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a: Uint32Array)
:
let res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint32Array)
:
number => accumulator + currentValue);
number => accumulator + currentValue);
expect(res).toEqual(6);
expect(res).toEqual(6);
total = new Uint32Array([0, 1, 2, 3]);
total = new Uint32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator
: number, currentValue: number, _: number, _a: Uint32Array)
:
res = total.reduceRight((accumulator
: number, currentValue : number, _ : number, _a : Uint32Array)
:
number => accumulator + currentValue, 8);
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
expect(res).toEqual(14);
// #END
}
}
reverse() {
reverse() {
// #TEST Uint32Array.reverse
let uint32 = new Uint32Array([1, 2, 3]);
let uint32 = new Uint32Array([1, 2, 3]);
uint32.reverse();
uint32.reverse();
expect(uint32.toString()).toEqual("3,2,1");
expect(uint32.toString()).toEqual("3,2,1");
// #END
}
}
slice() {
slice() {
// #TEST Uint32Array.slice
let uint32 = new Uint32Array([1, 2, 3]);
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.slice(1);
let res = uint32.slice(1);
expect(res.toString()).toEqual("2,3");
expect(res.toString()).toEqual("2,3");
...
@@ -238,18 +265,21 @@ export class TUint32Array {
...
@@ -238,18 +265,21 @@ export class TUint32Array {
res = uint32.slice(0, 1);
res = uint32.slice(0, 1);
expect(res.toString()).toEqual("1");
expect(res.toString()).toEqual("1");
// #END
}
}
sort() {
sort() {
// #TEST Uint32Array.sort
let numbers = new Uint32Array([40, 1, 5]);
let numbers = new Uint32Array([40, 1, 5]);
numbers.sort();
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
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");
// #END
}
}
subarray() {
subarray() {
// #TEST Uint32Array.subarray
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
let uint32 = new Uint32Array(buffer);
uint32.set([1, 2, 3]);
uint32.set([1, 2, 3]);
...
@@ -257,16 +287,19 @@ export class TUint32Array {
...
@@ -257,16 +287,19 @@ export class TUint32Array {
let sub = uint32.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");
// #END
}
}
values() {
values() {
// #TEST Uint32Array.values
let arr = new Uint32Array([1, 2, 3]);
let arr = new Uint32Array([1, 2, 3]);
let values = arr.values();
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(1);
// #END
}
}
arrayBufferSlice() {
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
let uint32 = new Uint32Array(buffer);
uint32[3] = 42;
uint32[3] = 42;
...
@@ -275,6 +308,8 @@ export class TUint32Array {
...
@@ -275,6 +308,8 @@ export class TUint32Array {
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);
// #END
}
}
// #endif
// #endif
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录