Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
0c883eb7
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
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看板
提交
0c883eb7
编写于
7月 31, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[array-buffer]添加console
上级
78314af2
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
946 addition
and
500 deletion
+946
-500
uni_modules/uts-tests/utssdk/TFloat64Array.uts
uni_modules/uts-tests/utssdk/TFloat64Array.uts
+141
-73
uni_modules/uts-tests/utssdk/TInt16Array.uts
uni_modules/uts-tests/utssdk/TInt16Array.uts
+139
-68
uni_modules/uts-tests/utssdk/TInt32Array.uts
uni_modules/uts-tests/utssdk/TInt32Array.uts
+115
-56
uni_modules/uts-tests/utssdk/TInt8Array.uts
uni_modules/uts-tests/utssdk/TInt8Array.uts
+156
-80
uni_modules/uts-tests/utssdk/TUInt8Array.uts
uni_modules/uts-tests/utssdk/TUInt8Array.uts
+110
-58
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
+89
-51
uni_modules/uts-tests/utssdk/TUint16Array.uts
uni_modules/uts-tests/utssdk/TUint16Array.uts
+99
-35
uni_modules/uts-tests/utssdk/TUint32Array.uts
uni_modules/uts-tests/utssdk/TUint32Array.uts
+97
-79
未找到文件。
uni_modules/uts-tests/utssdk/TFloat64Array.uts
浏览文件 @
0c883eb7
...
...
@@ -66,8 +66,9 @@ export class TFloat64Array {
let float64 = new Float64Array(8);
var array = [1, 2, 3];
float64.set(array, 1);
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(float64.toString()); // 0,1,2,3,0,0,0,0
// #END
expect(float64.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
...
...
@@ -75,61 +76,74 @@ export class TFloat64Array {
let float64 = new Float64Array(8);
float64.set([1, 2, 3], 1);
float64.copyWithin(3, 0, 3);
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log(float64.toString()); // 0,1,2,0,1,2,0,0
// #END
expect(float64.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Float64Array.every
let result = new Float64Array([-10, -20, -30, -40, -50]).every((value : number, _ : number, _a : Float64Array) : boolean => value < 0);
expect(result).toEqual(true);
console.log(result); // true
// #END
expect(result).toEqual(true);
}
testFill() {
// #TEST Float64Array.fill
let float64 = new Float64Array([1, 2, 3]).fill(4);
expect(float64.toString()).toEqual("4,4,4");
let float64
_t1
= new Float64Array([1, 2, 3]).fill(4);
console.log(float64_t1.toString()); // 4,4,4
float64
= new Float64Array([1, 2, 3]).fill(4, 1);
expect(float64.toString()).toEqual("1,4,4");
let float64_t2
= new Float64Array([1, 2, 3]).fill(4, 1);
console.log(float64_t2.toString()); // 1,4,4
float64
= new Float64Array([1, 2, 3]).fill(4, 1, 2);
expect(float64.toString()).toEqual("1,4,3");
let float64_t3
= new Float64Array([1, 2, 3]).fill(4, 1, 2);
console.log(float64_t3.toString()); // 1,4,3
float6
4 = new Float64Array([1, 2, 3]).fill(4, 1, 1);
expect(float64.toString()).toEqual("1,2,3");
let float64_t
4 = new Float64Array([1, 2, 3]).fill(4, 1, 1);
console.log(float64_t4.toString()); // 1,2,3
float64
= new Float64Array([1, 2, 3]).fill(4, -3, -2);
expect(float64.toString()).toEqual("4,2,3");
let float64_t5
= new Float64Array([1, 2, 3]).fill(4, -3, -2);
console.log(float64_t5.toString()); // 4,2,3
// #END
expect(float64_t4.toString()).toEqual("1,2,3");
expect(float64_t3.toString()).toEqual("1,4,3");
expect(float64_t2.toString()).toEqual("1,4,4");
expect(float64_t1.toString()).toEqual("4,4,4");
expect(float64_t5.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Float64Array.filter
let float64 = new Float64Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Float64Array) : boolean => value >= 10);
expect(float64.toString()).toEqual("12,44");
console.log(float64.toString()); // 12,44
// #END
expect(float64.toString()).toEqual("12,44");
}
find() {
// #TEST Float64Array.find
let float64 = new Float64Array([4, 5, 8, 12]);
let res = float64.find((value : number, _ : number, _a : Float64Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Float64Array.findIndex
let float64 = new Float64Array([4, 6, 8, 12]);
let res = float64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100);
expect(res).toEqual(-1);
console.log(res); // -1
let ufloat64 = new Float64Array([4, 6, 7, 120]);
res = ufloat64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100);
expect(res).toEqual(3);
console.log(res); // 3
// #END
expect(res).toEqual(3);
expect(float64.findIndex((value : number, _ : number, _a : Float64Array) : boolean => value > 100)).toEqual(-1);
}
...
...
@@ -145,129 +159,162 @@ export class TFloat64Array {
// #TEST Float64Array.entries
let arr = new Float64Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
console.log(entries.next().value[1]); // 10
console.log(entries.next().value[1]); // 20
// #END
expect(entries.next().value[1]).toEqual(30);
expect(entries.next().value[1]).toEqual(40);
}
includes() {
// #TEST Float64Array.includes
let float64 = new Float64Array([1, 2, 3]);
let res = float64.includes(2);
expect(res).toEqual(true);
console.log(res); // true
res = float64.includes(4);
expect(res).toEqual(false);
console.log(res); // false
res = float64.includes(3, 3);
expect(res).toEqual(false);
console.log(res); // false
// #END
expect(res).toEqual(false);
expect(float64.includes(4)).toEqual(false);
expect(float64.includes(2)).toEqual(true);
}
indexOf() {
// #TEST Float64Array.indexOf
let float64 = new Float64Array([2, 5, 9]);
let res = float64.indexOf(2);
expect(res).toEqual(0);
console.log(res); // 0
res = float64.indexOf(7);
expect(res).toEqual(-1);
res = float64.indexOf(9, 2
);
expect(res).toEqual(2);
let res1 = float64.indexOf(7
);
console.log(res1); // -1
res = float64.indexOf(2, -1
);
expect(res).toEqual(-1);
let res2 = float64.indexOf(9, 2
);
console.log(res2); // 2
res = float64.indexOf(2, -3);
expect(res).toEqual(0);
let res3 = float64.indexOf(2, -1);
console.log(res3); // -1
let res4 = float64.indexOf(2, -3);
console.log(res); // 0
// #END
expect(res).toEqual(0);
expect(res).toEqual(0);
expect(res1).toEqual(-1);
expect(res2).toEqual(2);
expect(res3).toEqual(-1);
}
join() {
// #TEST Float64Array.join
let float64 = new Float64Array([1, 2, 3]);
let res = float64.join();
expect(res).toEqual("1,2,3");
console.log(res); // 1,2,3
res
= float64.join(" / ");
expect(res).toEqual("1 / 2 / 3");
let res1
= float64.join(" / ");
console.log(res1); // 1 / 2 / 3
res = float64.join("");
expect(res).toEqual("123");
let res2 = float64.join("");
console.log(res2); // 123
// #END
expect(res2).toEqual("123");
expect(res).toEqual("1,2,3");
expect(res1).toEqual("1 / 2 / 3");
}
keys() {
// #TEST Float64Array.keys
let arr = new Float64Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(1);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
console.log(keys.next().value); // 0
console.log(keys.next().value); // 1
console.log(keys.next().value); // 2
console.log(keys.next().value); // 3
console.log(keys.next().value); // 4
// #END
expect(keys.next().value).toEqual(-1);
}
map() {
// #TEST Float64Array.map
let numbers = new Float64Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Float64Array) : number => value * 2);
console.log(numbers.toString()); // 1,4,9
console.log(doubles.toString()); // 2,8,18
// #END
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Float64Array.reduce
let total = new Float64Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
total = new Float64Array([0, 1, 2, 3]);
res
= total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
let res1
= total.reduce((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
console.log(res1); // 14
// #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
}
reduceRight() {
// #TEST Float64Array.reduceRight
let total = new Float64Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
total = new Float64Array([0, 1, 2, 3]);
res
= total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
let res1
= total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Float64Array) : number => accumulator + currentValue, 8);
console.log(res1); // 14
// #END
expect(res).toEqual(6);
expect(res1).toEqual(14);
}
reverse() {
// #TEST Float64Array.reverse
let float64 = new Float64Array([1, 2, 3]);
float64.reverse();
expect(float64.toString()).toEqual("3,2,1");
console.log(float64.toString()); // 3,2,1
// #END
expect(float64.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Float64Array.slice
let float64 = new Float64Array([1, 2, 3]);
let res = float64.slice(1);
expect(res.toString()).toEqual("2,3");
let ret1 = res.toString()
console.log(ret1); // 2,3
res = float64.slice(2);
expect(res.toString()).toEqual("3");
let ret2 = res.toString()
console.log(ret2); // 3
res = float64.slice(-2);
expect(res.toString()).toEqual("2,3");
let ret3 = res.toString()
console.log(ret3); // 2,3
res = float64.slice(0, 1);
expect(res.toString()).toEqual("1");
let ret4 = res.toString()
console.log(ret4); // 1
const size = 1000;
const initialFloat64Array = new Float64Array(size);
...
...
@@ -279,36 +326,46 @@ export class TFloat64Array {
let new_arr : Float64Array;
arr = new Float64Array(initialFloat64Array);
new_arr = arr.slice(1, -1);
let ret5 = true
for (let i = 1; i < size - 1; ++i) {
if (arr[i] !== new_arr[i - 1]) {
expect(true).toEqual(false);
break
ret5 = false
break
;
}
}
console.log(ret5); // true;
// #END
expect(ret4).toEqual("1");
expect(ret3.toString()).toEqual("2,3");
expect(ret2).toEqual("3");
expect(ret1.toString()).toEqual("2,3");
expect(true).toEqual(ret5);
}
sort() {
// #TEST Float64Array.sort
let numbers = new Float64Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
let ret = numbers.toString()
console.log(ret); // 1,5,40
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // 1,5,40
// #END
expect(ret).toEqual("1,5,40");
expect(numbers.toString()).toEqual("1,5,40");
}
subarray() {
// #TEST Float64Array.subarray
let buffer = new ArrayBuffer(32);
let float64 = new Float64Array(buffer);
float64.set([1, 2, 3]);
expect(float64.toString()).toEqual("1,2,3,0");
console.log(float64.toString()); // 1,2,3,0
let sub = float64.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // 1,2,3,0
const size = 1000;
const initialFloat64Array = new Float64Array(size);
...
...
@@ -317,52 +374,63 @@ export class TFloat64Array {
}
let arr = new Float64Array(initialFloat64Array);
let new_arr = arr.subarray(1, size - 1);
let ret = true
for (let i = 1; i < size - 1; ++i) {
if (arr[i] !== new_arr[i - 1]) {
expect(true).toEqual(false);
ret = false
break
}
}
// #END
expect(true).toEqual(ret);
}
values() {
// #TEST Float64Array.values
let arr = new Float64Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
console.log(values.next().value); // 1
console.log(values.next().value); // 2
console.log(values.next().value); // 3
// #END
expect(values.next().value).toEqual(-1);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let float64 = new Float64Array(buffer);
float64[1] = 42;
expect(float64.toString()).toEqual("0,42");
console.log(float64.toString()); // 0,42
let res = buffer.slice(8);
let sliced = new Float64Array(res);
expect(sliced[0]).toEqual(42);
console.log(sliced[0]); // 42
// #END
expect(sliced[0]).toEqual(42);
}
testSome() {
// #TEST Float64Array.some
const float64 = new Float64Array([-10, 20, -30, 40, -50]);
const positives = new Float64Array([10, 20, 30, 40, 50]);
console.log(float64.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0
)); // true
console.log(positives.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0
)); // false
// #END
expect(float64.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0
)).toEqual(true);
expect(positives.some((element : number, index : number, array : Float64Array) : boolean =>
element < 0
)).toEqual(false);
// #END
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt16Array.uts
浏览文件 @
0c883eb7
...
...
@@ -48,8 +48,9 @@ export class TInt16Array {
let int16 = new Int16Array(8);
var array = [1, 2, 3];
int16.set(array, 1);
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(int16.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(int16.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
...
...
@@ -57,61 +58,77 @@ export class TInt16Array {
let int16 = new Int16Array(8);
int16.set([1, 2, 3], 1);
int16.copyWithin(3, 0, 3);
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log(int16.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(int16.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Int16Array.every
let result = new Int16Array([12, 5, 8, 130, 44]).every((value, _, _a : Int16Array) : boolean => value < 40);
expect(result).toEqual(false);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Int16Array.fill
let int16 = new Int16Array([1, 2, 3]).fill(4);
expect(int16.toString()).toEqual("4,4,4");
console.log(int16.toString()); // "4,4,4"
// expect(int16.toString()).toEqual("4,4,4");
int16 = new Int16Array([1, 2, 3]).fill(4, 1);
expect(int16.toString()).toEqual("1,4,4");
console.log(int16.toString()); // "1,4,4"
// expect(int16.toString()).toEqual("1,4,4");
int16 = new Int16Array([1, 2, 3]).fill(4, 1, 2);
expect(int16.toString()).toEqual("1,4,3");
console.log(int16.toString()); // "1,4,3"
// expect(int16.toString()).toEqual("1,4,3");
int16 = new Int16Array([1, 2, 3]).fill(4, 1, 1);
expect(int16.toString()).toEqual("1,2,3");
console.log(int16.toString()); // "1,2,3"
// expect(int16.toString()).toEqual("1,2,3");
int16 = new Int16Array([1, 2, 3]).fill(4, -3, -2);
expect(int16.toString()).toEqual("4,2,3");
console.log(int16.toString()); // "4,2,3"
// #END
expect(int16.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Int16Array.filter
let int16 = new Int16Array([12, 5, 8, 44]).filter((value, _, _a : Int16Array) : boolean => value >= 10);
expect(int16.toString()).toEqual("12,44");
console.log(int16.toString()); // "12,44"
// #END
expect(int16.toString()).toEqual("12,44");
}
find() {
// #TEST Int16Array.find
let int16 = new Int16Array([4, 5, 8, 12]);
let res = int16.find((value, _, _a : Int16Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Int16Array.findIndex
let int16 = new Int16Array([4, 6, 8, 12]);
let res = int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100);
expect(res).toEqual(-1);
console.log(res); // -1
int16 = new Int16Array([4, 6, 7, 120]);
res
= int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100);
expect(res).toEqual(3);
let res1
= int16.findIndex((value, _, _a : Int16Array) : boolean => value > 100);
console.log(res1); // 3
// #END
expect(res1).toEqual(3);
expect(res).toEqual(-1);
}
foreach() {
...
...
@@ -126,137 +143,184 @@ export class TInt16Array {
// #TEST Int16Array.entries
let arr = new Int16Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
let firstEntry = entries.next().value[1];
console.log(firstEntry); // 10
// #END
expect(firstEntry).toEqual(10);
}
includes() {
// #TEST Int16Array.includes
let int16 = new Int16Array([1, 2, 3]);
let res = int16.includes(2);
expect(res).toEqual(true);
console.log(res); // true
res
= int16.includes(4);
expect(res).toEqual(false);
let res1
= int16.includes(4);
console.log(res1); // false
res = int16.includes(3, 3);
expect(res).toEqual(false);
let res2 = int16.includes(3, 3);
console.log(res2); // false
// #END
expect(res2).toEqual(false);
expect(res).toEqual(true);
expect(res1).toEqual(false);
}
indexOf() {
// #TEST Int16Array.indexOf
let int16 = new Int16Array([2, 5, 9]);
let res = int16.indexOf(2);
expect(res).toEqual(0);
console.log(res); // 0
res = int16.indexOf(7);
expect(res).toEqual(-1);
res = int16.indexOf(9, 2
);
expect(res).toEqual(2);
let res1 = int16.indexOf(7
);
console.log(res1); // -1
res = int16.indexOf(2, -1);
expect(res).toEqual(-1);
res = int16.indexOf(2, -3);
expect(res).toEqual(0);
let res2 = int16.indexOf(9, 2);
console.log(res2); // 2
let res3 = int16.indexOf(2, -1);
console.log(res3); // -1
let res4 = int16.indexOf(2, -3);
console.log(res4); // 0
// #END
expect(res4).toEqual(0);
expect(res).toEqual(0);
expect(res1).toEqual(-1);
expect(res2).toEqual(2);
expect(res3).toEqual(-1);
}
join() {
// #TEST Int16Array.join
let int16 = new Int16Array([1, 2, 3]);
let res = int16.join();
expect(res).toEqual("1,2,3");
console.log(res); // "1,2,3"
res
= int16.join(" / ");
expect(res).toEqual("1 / 2 / 3");
let res1
= int16.join(" / ");
console.log(res1); // "1 / 2 / 3"
res
= int16.join("");
expect(res).toEqual("123");
let res2
= int16.join("");
console.log(res2); // "123"
// #END
expect(res2).toEqual("123");
expect(res).toEqual("1,2,3");
expect(res1).toEqual("1 / 2 / 3");
}
keys() {
// #TEST Int16Array.keys
let arr = new Int16Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(1);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
let value1 = keys.next().value
console.log(value1); // 0
console.log(keys.next().value); // 1
console.log(keys.next().value); // 2
console.log(keys.next().value); // 3
console.log(keys.next().value); // 4
// #END
expect(value1).toEqual(0);
}
map() {
// #TEST Int16Array.map
let numbers = new Int16Array([1, 4, 9]);
let doubles = numbers.map((value, _, _a : Int16Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Int16Array.reduce
let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
total = new Int16Array([0, 1, 2, 3]);
res
= total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
let res1
= total.reduce((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8);
console.log(res1); // 14
// #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
}
reduceRight() {
// #TEST Int16Array.reduceRight
let total = new Int16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
total = new Int16Array([0, 1, 2, 3]);
res
= total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
let res1
= total.reduceRight((accumulator, currentValue, _, _a : Int16Array) : number => accumulator + currentValue, 8);
console.log(res1); // 14
// #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
}
reverse() {
// #TEST Int16Array.reverse
let int16 = new Int16Array([1, 2, 3]);
int16.reverse();
expect(int16.toString()).toEqual("3,2,1");
console.log(int16.toString()); // "3,2,1"
// #END
expect(int16.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Int16Array.slice
let int16 = new Int16Array([1, 2, 3]);
let res = int16.slice(1);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
res = int16.slice(2);
expect(res.toString()).toEqual("3");
res = int16.slice(-2);
expect(res.toString()).toEqual("2,3");
let res1 = int16.slice(2);
console.log(res1.toString()); // "3"
let res2 = int16.slice(-2);
console.log(res2.toString()); // "2,3"
res = int16.slice(0, 1);
expect(res.toString()).toEqual("1");
let res3 = int16.slice(0, 1);
console.log(res3.toString()); // "1"
// #END
expect(res3.toString()).toEqual("1");
expect(res.toString()).toEqual("2,3");
expect(res1.toString()).toEqual("3");
expect(res2.toString()).toEqual("2,3");
}
sort() {
// #TEST Int16Array.sort
let numbers = new Int16Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
let res = numbers.toString()
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
expect(res).toEqual("1,5,40");
}
subarray() {
...
...
@@ -264,49 +328,56 @@ export class TInt16Array {
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
int16.set([1, 2, 3]);
expect(int16.toString()).toEqual("1,2,3,0,0,0,0,0");
let res = int16.toString()
console.log(res); // "1,2,3,0,0,0,0,0"
let sub = int16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
expect(res).toEqual("1,2,3,0,0,0,0,0");
}
values() {
// #TEST Int16Array.values
let arr = new Int16Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
let res = values.next().value
console.log(res); // 1
// #END
expect(res).toEqual(1);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int16Array
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
int16[4] = 42;
expect(int16.toString()).toEqual("0,0,0,0,42,0,0,0");
console.log(int16.toString()); // "0,0,0,0,42,0,0,0"
let res = buffer.slice(8, 12);
let sliced = new Int16Array(res);
expect(sliced[0]).toEqual(42);
console.log(sliced[0]); // 42
// #END
expect(sliced[0]).toEqual(42);
expect(int16.toString()).toEqual("0,0,0,0,42,0,0,0");
}
testSome() {
// #TEST Int16Array.some
const int16 = new Int16Array([-10, 20, -30, 40, -50]);
const positives = new Int16Array([10, 20, 30, 40, 50]);
expect(int16.some((element : number, index : number, array : Int16Array) : boolean =>
element < 0
)).toEqual(true);
console.log(int16.some((element : number, index : number, array : Int16Array) : boolean => element < 0)); // true
expect(positives.some((element : number, index : number, array : Int16Array) : boolean =>
element < 0
)).toEqual(false);
console.log(positives.some((element : number, index : number, array : Int16Array) : boolean => element < 0)); // false
// #END
expect(positives.some((element : number, index : number, array : Int16Array) : boolean => element < 0)).toEqual(false);
expect(int16.some((element : number, index : number, array : Int16Array) : boolean => element < 0)).toEqual(true);
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt32Array.uts
浏览文件 @
0c883eb7
...
...
@@ -67,75 +67,91 @@ export class TInt32Array {
testSet() {
// #TEST Int32Array.set
let int32 = new Int32Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
int32.set(array, 1);
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(int32.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(int32.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
// #TEST Int32Array.copyWithin
console.log("testCopyWith
1")
console.log("testCopyWith
start");
let int32 = new Int32Array(8);
int32.set([1, 2, 3], 1);
console.log(
"testCopyWith 1")
console.log(
int32.toString()); // "0,1,2,0,0,0,0,0"
int32.copyWithin(3, 0, 3);
console.log("testCopyWith 1")
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log(int32.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(int32.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Int32Array.every
let result = new Int32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int32Array) : boolean => value < 40);
expect(result).toEqual(false);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Int32Array.fill
let int32 = new Int32Array([1, 2, 3]).fill(4);
expect(int32.toString()).toEqual("4,4,4");
console.log(int32.toString()); // "4,4,4"
// expect(int32.toString()).toEqual("4,4,4");
int32 = new Int32Array([1, 2, 3]).fill(4, 1);
expect(int32.toString()).toEqual("1,4,4");
console.log(int32.toString()); // "1,4,4"
// expect(int32.toString()).toEqual("1,4,4");
int32 = new Int32Array([1, 2, 3]).fill(4, 1, 2);
expect(int32.toString()).toEqual("1,4,3");
console.log(int32.toString()); // "1,4,3"
// expect(int32.toString()).toEqual("1,4,3");
int32 = new Int32Array([1, 2, 3]).fill(4, 1, 1);
expect(int32.toString()).toEqual("1,2,3");
console.log(int32.toString()); // "1,2,3"
// expect(int32.toString()).toEqual("1,2,3");
int32 = new Int32Array([1, 2, 3]).fill(4, -3, -2);
expect(int32.toString()).toEqual("4,2,3");
console.log(int32.toString()); // "4,2,3"
// #END
expect(int32.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Int32Array.filter
let int32 = new Int32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int32Array) : boolean => value >= 10);
expect(int32.toString()).toEqual("12,44");
console.log(int32.toString()); // "12,44"
// #END
expect(int32.toString()).toEqual("12,44");
}
find() {
// #TEST Int32Array.find
let int32 = new Int32Array([4, 5, 8, 12]);
let res = int32.find((value : number, _ : number, _a : Int32Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Int32Array.findIndex
let int32 = new Int32Array([4, 6, 8, 12]);
let res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
expect(res).toEqual(-1);
console.log(res); // -1
// expect(res).toEqual(-1);
int32 = new Int32Array([4, 6, 7, 120]);
res = int32.findIndex((value : number, _ : number, _a : Int32Array) : boolean => value > 100);
expect(res).toEqual(3);
console.log(res); // 3
// #END
expect(res).toEqual(3);
}
foreach() {
...
...
@@ -150,133 +166,174 @@ export class TInt32Array {
// #TEST Int32Array.entries
let arr = new Int32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
let entry = entries.next();
console.log(entry.value[1]); // 10
// #END
expect(entry.value[1]).toEqual(10);
}
includes() {
// #TEST Int32Array.includes
let int32 = new Int32Array([1, 2, 3]);
let res = int32.includes(2);
expect(res).toEqual(true);
console.log(res); // true
// expect(res).toEqual(true);
res = int32.includes(4);
expect(res).toEqual(false);
console.log(res); // false
// expect(res).toEqual(false);
res = int32.includes(3, 3);
expect(res).toEqual(false);
console.log(res); // false
// #END
expect(res).toEqual(false);
}
indexOf() {
// #TEST Int32Array.indexOf
let int32 = new Int32Array([2, 5, 9]);
let res = int32.indexOf(2);
expect(res).toEqual(0);
console.log(res); // 0
// expect(res).toEqual(0);
res = int32.indexOf(7);
expect(res).toEqual(-1);
console.log(res); // -1
// expect(res).toEqual(-1);
res = int32.indexOf(9, 2);
expect(res).toEqual(2);
console.log(res); // 2
// expect(res).toEqual(2);
res = int32.indexOf(2, -1);
expect(res).toEqual(-1);
console.log(res); // -1
// expect(res).toEqual(-1);
res = int32.indexOf(2, -3);
expect(res).toEqual(0);
console.log(res); // 0
// #END
expect(res).toEqual(0);
}
join() {
// #TEST Int32Array.join
let int32 = new Int32Array([1, 2, 3]);
let res = int32.join();
expect(res).toEqual("1,2,3");
console.log(res); // "1,2,3"
// expect(res).toEqual("1,2,3");
res = int32.join(" / ");
expect(res).toEqual("1 / 2 / 3");
console.log(res); // "1 / 2 / 3"
// expect(res).toEqual("1 / 2 / 3");
res = int32.join("");
expect(res).toEqual("123");
console.log(res); // "123"
// #END
expect(res).toEqual("123");
}
keys() {
// #TEST Int32Array.keys
let arr = new Int32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
let key = keys.next();
console.log(key.value); // 0
// #END
expect(key.value).toEqual(0);
}
map() {
// #TEST Int32Array.map
let numbers = new Int32Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Int32Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Int32Array.reduce
let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
// expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reduceRight() {
// #TEST Int32Array.reduceRight
let total = new Int32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
// expect(res).toEqual(6);
total = new Int32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int32Array) : number => accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reverse() {
// #TEST Int32Array.reverse
let int32 = new Int32Array([1, 2, 3]);
int32.reverse();
expect(int32.toString()).toEqual("3,2,1");
console.log(int32.toString()); // "3,2,1"
// #END
expect(int32.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Int32Array.slice
let int32 = new Int32Array([1, 2, 3]);
let res = int32.slice(1);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = int32.slice(2);
expect(res.toString()).toEqual("3");
console.log(res.toString()); // "3"
// expect(res.toString()).toEqual("3");
res = int32.slice(-2);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = int32.slice(0, 1);
expect(res.toString()).toEqual("1");
console.log(res.toString()); // "1"
// #END
expect(res.toString()).toEqual("1");
}
sort() {
// #TEST Int32Array.sort
let numbers = new Int32Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
}
subarray() {
...
...
@@ -284,49 +341,51 @@ export class TInt32Array {
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
int32.set([1, 2, 3]);
expect(int32.toString()).toEqual("1,2,3,0");
console.log(int32.toString()); // "1,2,3,0"
let sub = int32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
}
values() {
// #TEST Int32Array.values
let arr = new Int32Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
let value = values.next().value
console.log(value); // 1
// #END
expect(value).toEqual(1);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
int32[3] = 42;
expect(int32.toString()).toEqual("0,0,0,42");
console.log(int32.toString()); // "0,0,0,42"
let res = buffer.slice(8);
let sliced = new Int32Array(res);
expect(sliced[1]).toEqual(42);
console.log(sliced[1]); // 42
// #END
expect(sliced[1]).toEqual(42);
}
testSome() {
// #TEST Int32Array.some
const int32 = new Int32Array([-10, 20, -30, 40, -50]);
const positives = new Int32Array([10, 20, 30, 40, 50]);
expect(int32.some((element : number, index : number, array : Int32Array) : boolean =>
element < 0
)).toEqual(true);
console.log(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // true
// expect(int32.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(true);
expect(positives.some((element : number, index : number, array : Int32Array) : boolean =>
element < 0
)).toEqual(false);
console.log(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)); // false
// #END
expect(positives.some((element : number, index : number, array : Int32Array) : boolean => element < 0)).toEqual(false);
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt8Array.uts
浏览文件 @
0c883eb7
...
...
@@ -48,10 +48,11 @@ export class TInt8Array {
testSet() {
// #TEST Int8Array.set
let int8 = new Int8Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
int8.set(array, 1);
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(int8.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(int8.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
...
...
@@ -59,67 +60,81 @@ export class TInt8Array {
let int8 = new Int8Array(8);
int8.set([1, 2, 3], 1);
int8.copyWithin(3, 0, 3);
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log(int8.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(int8.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Int8Array.every
// const isBelowThreshold = (currentValue: number, index: number, array:Int8Array): boolean => currentValue < 40;
let result = new Int8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Int8Array) : boolean =>
value < 40);
expect(result).toEqual(false);
value < 40
);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Int8Array.fill
let int8 = new Int8Array([1, 2, 3]).fill(4);
expect(int8.toString()).toEqual("4,4,4");
console.log(int8.toString()); // "4,4,4"
int8
= new Int8Array([1, 2, 3]).fill(4, 1);
expect(int8.toString()).toEqual("1,4,4");
let int8_t1
= new Int8Array([1, 2, 3]).fill(4, 1);
console.log(int8_t1.toString()); // "1,4,4"
int8
= new Int8Array([1, 2, 3]).fill(4, 1, 2);
expect(int8.toString()).toEqual("1,4,3");
let int8_t2
= new Int8Array([1, 2, 3]).fill(4, 1, 2);
console.log(int8_t2.toString()); // "1,4,3"
int8
= new Int8Array([1, 2, 3]).fill(4, 1, 1);
expect(int8.toString()).toEqual("1,2,3");
let int8_t3
= new Int8Array([1, 2, 3]).fill(4, 1, 1);
console.log(int8_t3.toString()); // "1,2,3"
int8
= new Int8Array([1, 2, 3]).fill(4, -3, -2);
expect(int8.toString()).toEqual("4,2,3");
let int8_t4
= new Int8Array([1, 2, 3]).fill(4, -3, -2);
console.log(int8_t4.toString()); // "4,2,3"
// #END
expect(int8_t4.toString()).toEqual("4,2,3");
expect(int8.toString()).toEqual("4,4,4");
expect(int8_t1.toString()).toEqual("1,4,4");
expect(int8_t2.toString()).toEqual("1,4,3");
expect(int8_t3.toString()).toEqual("1,2,3");
}
testFilter() {
// #TEST Int8Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let int8 = new Int8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Int8Array) : boolean =>
value >= 10);
expect(int8.toString()).toEqual("12,44");
value >= 10
);
console.log(int8.toString()); // "12,44"
// #END
expect(int8.toString()).toEqual("12,44");
}
find() {
// #TEST Int8Array.find
let int8 = new Int8Array([4, 5, 8, 12]);
let res = int8.find((value : number, _ : number, _a : Int8Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Int8Array.findIndex
let int8 = new Int8Array([4, 6, 8, 12]);
let res = int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100);
expect(res).toEqual(-1);
console.log(res); // -1
int8 = new Int8Array([4, 6, 7, 120]);
res
= int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100);
expect(res).toEqual(3);
let res1
= int8.findIndex((value : number, _ : number, _a : Int8Array) : boolean => value > 100);
console.log(res1); // 3
// #END
expect(res1).toEqual(3);
expect(res).toEqual(-1);
}
foreach() {
...
...
@@ -129,83 +144,119 @@ export class TInt8Array {
});
// #END
}
iterator() {
// #TEST Int8Array.entries
let arr = new Int8Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
expect(entries.next().value[1]).toEqual(20);
let ret1 = entries.next().value[1]
let ret2 = entries.next().value[1]
console.log(ret1); // Output: 10
console.log(ret2); // Output: 20
// #END
expect(ret1).toEqual(10);
expect(ret2).toEqual(20);
}
includes() {
// #TEST Int8Array.includes
let int8 = new Int8Array([1, 2, 3]);
let res = int8.includes(2);
expect(res).toEqual(true);
console.log(res); // Output: true
let res1 = int8.includes(4);
console.log(res1); // Output: false
res = int8.includes(4);
expect(res).toEqual(false);
res = int8.includes(3, 3);
expect(res).toEqual(false);
let res2 = int8.includes(3, 3);
console.log(res2); // Output: false
// #END
expect(res).toEqual(true);
expect(res1).toEqual(false);
expect(res2).toEqual(false);
}
indexOf() {
// #TEST Int8Array.indexOf
let int8 = new Int8Array([2, 5, 9]);
let res = int8.indexOf(2);
expect(res).toEqual(0);
console.log(res); // Output: 0
res = int8.indexOf(7);
expect(res).toEqual(-1);
res = int8.indexOf(9, 2);
expect(res).toEqual(2);
let res1 = int8.indexOf(7);
console.log(res1); // Output: -1
let res2 = int8.indexOf(9, 2);
console.log(res2); // Output: 2
let res3 = int8.indexOf(2, -1);
console.log(res3); // Output: -1
let res4 = int8.indexOf(2, -3);
console.log(res4); // Output: 0
res = int8.indexOf(2, -1);
expect(res).toEqual(-1);
res = int8.indexOf(2, -3);
expect(res).toEqual(0);
// #END
expect(res).toEqual(0);
expect(res1).toEqual(-1);
expect(res2).toEqual(2);
expect(res3).toEqual(-1);
expect(res4).toEqual(0);
}
join() {
// #TEST Int8Array.join
let int8 = new Int8Array([1, 2, 3]);
let res = int8.join();
expect(res).toEqual("1,2,3");
console.log(res); // Output: "1,2,3"
res
= int8.join(" / ");
expect(res).toEqual("1 / 2 / 3");
let res1
= int8.join(" / ");
console.log(res1); // Output: "1 / 2 / 3"
res = int8.join("");
expect(res).toEqual("123");
let res2 = int8.join("");
console.log(res2); // Output: "123"
// #END
expect(res2).toEqual("123");
expect(res).toEqual("1,2,3");
expect(res1).toEqual("1 / 2 / 3");
}
keys() {
// #TEST Int8Array.keys
let arr = new Int8Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
expect(keys.next().value).toEqual(1);
expect(keys.next().value).toEqual(2);
expect(keys.next().value).toEqual(3);
expect(keys.next().value).toEqual(4);
let value1 = keys.next().value
let value2 = keys.next().value
let value3 = keys.next().value
let value4 = keys.next().value
let value5 = keys.next().value
console.log(value1); // Output: 0
console.log(value2); // Output: 1
console.log(value3); // Output: 2
console.log(value4); // Output: 3
console.log(value5); // Output: 4
// #END
expect(value1).toEqual(0);
expect(value2).toEqual(1);
expect(value3).toEqual(2);
expect(value4).toEqual(3);
expect(value5).toEqual(4);
}
map() {
// #TEST Int8Array.map
let numbers = new Int8Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Int8Array) : number => value * 2);
console.log(numbers.toString()); // Output: "1,4,9"
console.log(doubles.toString()); // Output: "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
...
...
@@ -213,13 +264,16 @@ export class TInt8Array {
let total = new Int8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // Output: 6
total = new Int8Array([0, 1, 2, 3]);
res
= total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : number =>
let res1
= total.reduce((accumulator : number, currentValue : number, _ : number, _a : Int8Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res1); // Output: 14
// #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
}
reduceRight() {
...
...
@@ -227,50 +281,59 @@ export class TInt8Array {
let total = new Int8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // Output: 6
total = new Int8Array([0, 1, 2, 3]);
res
= total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
let res1
= total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Int8Array) :
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res1); // Output: 14
// #END
expect(res1).toEqual(14);
expect(res).toEqual(6);
}
reverse() {
// #TEST Int8Array.reverse
let int8 = new Int8Array([1, 2, 3]);
int8.reverse();
expect(int8.toString()).toEqual("3,2,1");
console.log(int8.toString()); // Output: "3,2,1"
// #END
expect(int8.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Int8Array.slice
let int8 = new Int8Array([1, 2, 3]);
let res = int8.slice(1);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // Output: "2,3"
res
= int8.slice(2);
expect(res.toString()).toEqual("3");
let res1
= int8.slice(2);
console.log(res1.toString()); // Output: "3"
res
= int8.slice(-2);
expect(res.toString()).toEqual("2,3");
let res2
= int8.slice(-2);
console.log(res2.toString()); // Output: "2,3"
res
= int8.slice(0, 1);
expect(res.toString()).toEqual("1");
let res3
= int8.slice(0, 1);
console.log(res3.toString()); // Output: "1"
// #END
expect(res3.toString()).toEqual("1");
expect(res.toString()).toEqual("2,3");
expect(res1.toString()).toEqual("3");
expect(res2.toString()).toEqual("2,3");
}
sort() {
// #TEST Int8Array.sort
let numbers = new Int8Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // Output: "1,5,40"
let res = numbers.toString()
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // Output: "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
expect(res).toEqual("1,5,40");
}
subarray() {
...
...
@@ -278,36 +341,45 @@ export class TInt8Array {
let buffer = new ArrayBuffer(8);
let int8 = new Int8Array(buffer);
int8.set([1, 2, 3]);
expect(int8.toString()).toEqual("1,2,3,0,0,0,0,0");
console.log(int8.toString()); // Output: "1,2,3,0,0,0,0,0"
let sub = int8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // Output: "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
expect(int8.toString()).toEqual("1,2,3,0,0,0,0,0");
}
values() {
// #TEST Int8Array.values
let arr = new Int8Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
expect(values.next().value).toEqual(2);
expect(values.next().value).toEqual(3);
let value1 = values.next().value
let value2 = values.next().value
let value3 = values.next().value
console.log(value1); // Output: 1
console.log(value2); // Output: 2
console.log(value3); // Output: 3
// #END
expect(value1).toEqual(1);
expect(value2).toEqual(2);
expect(value3).toEqual(3);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let int8 = new Int8Array(buffer);
int8[4] = 42;
expect(int8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0");
console.log(int8.toString()); // Output: "0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"
let res = buffer.slice(4, 5);
let sliced = new Int8Array(res);
expect(sliced[0]).toEqual(42);
console.log(sliced[0]); // Output: 42
// #END
expect(sliced[0]).toEqual(42);
expect(int8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0");
}
testSome() {
...
...
@@ -315,15 +387,19 @@ export class TInt8Array {
const int8 = new Int8Array([-10, 20, -30, 40, -50]);
const positives = new Int8Array([10, 20, 30, 40, 50]);
expect(
int8.some((element : number, index : number, array : Int8Array) : boolean =>
let res =
int8.some((element : number, index : number, array : Int8Array) : boolean =>
element < 0
)).toEqual(true);
);
console.log(res); // Output: true
expect(
positives.some((element : number, index : number, array : Int8Array) : boolean =>
let res1 =
positives.some((element : number, index : number, array : Int8Array) : boolean =>
element < 0
)).toEqual(false);
);
console.log(res1); // Output: false
// #END
expect(res1).toEqual(false);
expect(res).toEqual(true);
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUInt8Array.uts
浏览文件 @
0c883eb7
...
...
@@ -61,8 +61,9 @@ export class TUint8Array {
let uint8 = new Uint8Array(8);
var array = [1, 2, 3];
uint8.set(array, 1);
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(uint8.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(uint8.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
...
...
@@ -71,65 +72,68 @@ export class TUint8Array {
let uint8 = new Uint8Array(8);
uint8.set([1, 2, 3], 1);
uint8.copyWithin(3, 0, 3);
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log(uint8.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(uint8.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Uint8Array.every
// const isBelowThreshold = (currentValue: number, index: number, array: Uint8Array): boolean => currentValue < 40;
let result = new Uint8Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint8Array) : boolean =>
value < 40);
expect(result).toEqual(false);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Uint8Array.fill
let uint8 = new Uint8Array([1, 2, 3]).fill(4);
expect(uint8.toString()).toEqual("4,4,4");
console.log(uint8.toString()); // "4,4,4"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1);
expect(uint8.toString()).toEqual("1,4,4");
console.log(uint8.toString()); // "1,4,4"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 2);
expect(uint8.toString()).toEqual("1,4,3");
console.log(uint8.toString()); // "1,4,3"
uint8 = new Uint8Array([1, 2, 3]).fill(4, 1, 1);
expect(uint8.toString()).toEqual("1,2,3");
console.log(uint8.toString()); // "1,2,3"
uint8 = new Uint8Array([1, 2, 3]).fill(4, -3, -2);
expect(uint8.toString()).toEqual("4,2,3");
console.log(uint8.toString()); // "4,2,3"
// #END
expect(uint8.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Uint8Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint8 = new Uint8Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint8Array) : boolean => value >= 10);
expect(uint8.toString()).toEqual("12,44");
console.log(uint8.toString()); // "12,44"
// #END
expect(uint8.toString()).toEqual("12,44");
}
find() {
// #TEST Uint8Array.find
let uint8 = new Uint8Array([4, 5, 8, 12]);
let res = uint8.find((value : number, _ : number, _a : Uint8Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Uint8Array.findIndex
let uint8 = new Uint8Array([4, 6, 8, 12]);
let res = uint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100);
expect(res).toEqual(-1);
console.log(res); // -1
let uuint8 = new Uint8Array([4, 6, 7, 120]);
res = uuint8.findIndex((value : number, _ : number, _a : Uint8Array) : boolean => value > 100);
expect(res).toEqual(3);
console.log(res); // 3
// #END
expect(res).toEqual(3);
}
foreach() {
...
...
@@ -139,90 +143,115 @@ export class TUint8Array {
});
// #END
}
iterator() {
// #TEST Uint8Array.entries
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
let entry = entries.next().value;
console.log(entry[1]); // 10
// #END
expect(entry[1]).toEqual(10);
}
includes() {
// #TEST Uint8Array.includes
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.includes(2);
expect(res).toEqual(true);
console.log(res); // true
res = uint8.includes(4);
expect(res).toEqual(false);
console.log(res); // false
res = uint8.includes(3, 3);
expect(res).toEqual(false);
console.log(res); // false
// #END
expect(res).toEqual(false);
}
indexOf() {
// #TEST Uint8Array.indexOf
let uint8 = new Uint8Array([2, 5, 9]);
let res = uint8.indexOf(2);
expect(res).toEqual(0);
console.log(res); // 0
// expect(res).toEqual(0);
res = uint8.indexOf(7);
expect(res).toEqual(-1);
console.log(res); // -1
// expect(res).toEqual(-1);
res = uint8.indexOf(9, 2);
expect(res).toEqual(2);
console.log(res); // 2
// expect(res).toEqual(2);
res = uint8.indexOf(2, -1);
expect(res).toEqual(-1);
console.log(res); // -1
// expect(res).toEqual(-1);
res = uint8.indexOf(2, -3);
expect(res).toEqual(0);
console.log(res); // 0
// #END
expect(res).toEqual(0);
}
join() {
// #TEST Uint8Array.join
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.join();
expect(res).toEqual("1,2,3");
console.log(res); // "1,2,3"
// expect(res).toEqual("1,2,3");
res = uint8.join(" / ");
expect(res).toEqual("1 / 2 / 3");
console.log(res); // "1 / 2 / 3"
// expect(res).toEqual("1 / 2 / 3");
res = uint8.join("");
expect(res).toEqual("123");
console.log(res); // "123"
// #END
expect(res).toEqual("123");
}
keys() {
// #TEST Uint8Array.keys
let arr = new Uint8Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
let value = keys.next().value
console.log(value); // 0
// #END
expect(value).toEqual(0);
}
map() {
// #TEST Uint8Array.map
let numbers = new Uint8Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint8Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Uint8Array.reduce
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
// expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator +
currentValue, 8);
expect(res).toEqual(14);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator +
currentValue, 8);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reduceRight() {
...
...
@@ -230,48 +259,63 @@ export class TUint8Array {
let total = new Uint8Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
// expect(res).toEqual(6);
total = new Uint8Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reverse() {
// #TEST Uint8Array.reverse
let uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse();
expect(uint8.toString()).toEqual("3,2,1");
console.log(uint8.toString()); // "3,2,1"
// #END
expect(uint8.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Uint8Array.slice
let uint8 = new Uint8Array([1, 2, 3]);
let res = uint8.slice(1);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = uint8.slice(2);
expect(res.toString()).toEqual("3");
console.log(res.toString()); // "3"
// expect(res.toString()).toEqual("3");
res = uint8.slice(-2);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
// expect(res.toString()).toEqual("2,3");
res = uint8.slice(0, 1);
expect(res.toString()).toEqual("1");
console.log(res.toString()); // "1"
// #END
expect(res.toString()).toEqual("1");
}
sort() {
// #TEST Uint8Array.sort
let numbers = new Uint8Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
}
subarray() {
...
...
@@ -279,50 +323,58 @@ export class TUint8Array {
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]);
expect(uint8.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0");
console.log(uint8.toString()); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"
// expect(uint8.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0");
let sub = uint8.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
}
values() {
// #TEST Uint8Array.values
let arr = new Uint8Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
let value = values.next().value
console.log(value); // 1
// #END
expect(value).toEqual(1);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
uint8[4] = 42;
expect(uint8.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0");
console.log(uint8.toString()); // "0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"
let res = buffer.slice(4, 12);
let sliced = new Uint8Array(res);
expect(sliced[0]).toEqual(42);
console.log(sliced[0]); // 42
// #END
expect(sliced[0]).toEqual(42);
}
testSome() {
// #TEST Uint8Array.some
const uint8 = new Uint8Array([8, 20, 30, 40, 50]);
const positives = new Uint8Array([10, 20, 30, 40, 50]);
var res = uint8.some((element : number, index : number, array : Uint8Array) : boolean =>
element < 10
)
expect(res).toEqual(true);
console.log('uint8', res)
);
console.log('uint8', res); // true
// expect(res).toEqual(true);
res = positives.some((element : number, index : number, array : Uint8Array) : boolean =>
element < 0
)
console.log('uint8', res)
expect(res).toEqual(false);
);
console.log('positives', res); // false
// #END
expect(res).toEqual(false);
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
浏览文件 @
0c883eb7
...
...
@@ -56,79 +56,84 @@ export class TUint8ClampedArray {
let uint8Clamped = new Uint8ClampedArray(8);
var array = [1, 2, 3];
uint8Clamped.set(array, 1);
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(uint8Clamped.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(uint8Clamped.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
// #TEST Uint8ClampedArray.copyWithin
console.log("testCopyWith 1")
console.log("testCopyWith 1")
;
let uint8Clamped = new Uint8ClampedArray(8);
uint8Clamped.set([1, 2, 3], 1);
uint8Clamped.copyWithin(3, 0, 3);
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log(uint8Clamped.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(uint8Clamped.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Uint8ClampedArray.every
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8ClampedArray): boolean => currentValue < 40;
let result = new Uint8ClampedArray([12, 5, 8, 130, 44]).every((value : number, _ : number, _a :
Uint8ClampedArray) : boolean => value < 40);
//
expect(result).toEqual(false);
Uint8ClampedArray) : boolean => value < 40);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Uint8ClampedArray.fill
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4);
expect(uint8Clamped.toString()).toEqual("4,4,4");
console.log(uint8Clamped.toString()); // "4,4,4"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1);
expect(uint8Clamped.toString()).toEqual("1,4,4");
console.log(uint8Clamped.toString()); // "1,4,4"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 2);
expect(uint8Clamped.toString()).toEqual("1,4,3");
console.log(uint8Clamped.toString()); // "1,4,3"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, 1, 1);
expect(uint8Clamped.toString()).toEqual("1,2,3");
console.log(uint8Clamped.toString()); // "1,2,3"
uint8Clamped = new Uint8ClampedArray([1, 2, 3]).fill(4, -3, -2);
expect(uint8Clamped.toString()).toEqual("4,2,3");
console.log(uint8Clamped.toString()); // "4,2,3"
// #END
expect(uint8Clamped.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Uint8ClampedArray.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint8Clamped = new Uint8ClampedArray([12, 5, 8, 44]).filter((value : number, _ : number, _a :
Uint8ClampedArray) : boolean => value >= 10);
expect(uint8Clamped.toString()).toEqual("12,44");
console.log(uint8Clamped.toString()); // "12,44"
// #END
expect(uint8Clamped.toString()).toEqual("12,44");
}
find() {
// #TEST Uint8ClampedArray.find
let uint8Clamped = new Uint8ClampedArray([4, 5, 8, 12]);
let res = uint8Clamped.find((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Uint8ClampedArray.findIndex
let uint8Clamped = new Uint8ClampedArray([4, 6, 8, 12]);
let res = uint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100);
expect(res).toEqual(-1);
console.log(res); // -1
let uuint8Clamped = new Uint8ClampedArray([4, 6, 7, 120]);
res = uuint8Clamped.findIndex((value : number, _ : number, _a : Uint8ClampedArray) : boolean => value > 100);
expect(res).toEqual(3);
console.log(res); // 3
// #END
expect(res).toEqual(3);
}
foreach() {
...
...
@@ -138,89 +143,101 @@ export class TUint8ClampedArray {
});
// #END
}
iterator() {
// #TEST Uint8ClampedArray.entries
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
let entry = entries.next().value;
console.log(entry[1]); // 10
// #END
expect(entry[1]).toEqual(10);
}
includes() {
// #TEST Uint8ClampedArray.includes
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.includes(2);
expect(res).toEqual(true);
console.log(res); // true
res = uint8Clamped.includes(4);
expect(res).toEqual(false);
console.log(res); // false
res = uint8Clamped.includes(3, 3);
expect(res).toEqual(false);
console.log(res); // false
// #END
expect(res).toEqual(false);
}
indexOf() {
// #TEST Uint8ClampedArray.indexOf
let uint8Clamped = new Uint8ClampedArray([2, 5, 9]);
let res = uint8Clamped.indexOf(2);
expect(res).toEqual(0);
console.log(res); // 0
res = uint8Clamped.indexOf(7);
expect(res).toEqual(-1);
console.log(res); // -1
res = uint8Clamped.indexOf(9, 2);
expect(res).toEqual(2);
console.log(res); // 2
res = uint8Clamped.indexOf(2, -1);
expect(res).toEqual(-1);
console.log(res); // -1
res = uint8Clamped.indexOf(2, -3);
expect(res).toEqual(0);
console.log(res); // 0
// #END
expect(res).toEqual(0);
}
join() {
// #TEST Uint8ClampedArray.join
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.join();
expect(res).toEqual("1,2,3");
console.log(res); // "1,2,3"
res = uint8Clamped.join(" / ");
expect(res).toEqual("1 / 2 / 3");
console.log(res); // "1 / 2 / 3"
res = uint8Clamped.join("");
expect(res).toEqual("123");
console.log(res); // "123"
// #END
expect(res).toEqual("123");
}
keys() {
// #TEST Uint8ClampedArray.keys
let arr = new Uint8ClampedArray([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
let value = keys.next().value
console.log(value); // 0
// #END
expect(value).toEqual(0);
}
map() {
// #TEST Uint8ClampedArray.map
let numbers = new Uint8ClampedArray([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint8ClampedArray) : number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(doubles.toString()).toEqual("2,8,18");
}
reduce() {
// #TEST Uint8ClampedArray.reduce
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reduceRight() {
...
...
@@ -228,97 +245,118 @@ export class TUint8ClampedArray {
let total = new Uint8ClampedArray([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue);
expect(res).toEqual(6);
console.log(res); // 6
total = new Uint8ClampedArray([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint8ClampedArray) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reverse() {
// #TEST Uint8ClampedArray.reverse
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
uint8Clamped.reverse();
expect(uint8Clamped.toString()).toEqual("3,2,1");
console.log(uint8Clamped.toString()); // "3,2,1"
// #END
expect(uint8Clamped.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Uint8ClampedArray.slice
let uint8Clamped = new Uint8ClampedArray([1, 2, 3]);
let res = uint8Clamped.slice(1);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
res = uint8Clamped.slice(2);
expect(res.toString()).toEqual("3");
console.log(res.toString()); // "3"
res = uint8Clamped.slice(-2);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
res = uint8Clamped.slice(0, 1);
expect(res.toString()).toEqual("1");
console.log(res.toString()); // "1"
// #END
expect(res.toString()).toEqual("1");
}
sort() {
// #TEST Uint8ClampedArray.sort
let numbers = new Uint8ClampedArray([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
}
subarray() {
// #TEST Uint8ClampedArray.subarray
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped.set([1, 2, 3]);
expect(uint8Clamped.toString()).toEqual("1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0");
console.log(uint8Clamped.toString()); // "1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0"
let sub = uint8Clamped.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
}
values() {
// #TEST Uint8ClampedArray.values
let arr = new Uint8ClampedArray([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
let value = values.next().value
console.log(value); // 1
// #END
expect(value).toEqual(1);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped[4] = 42;
expect(uint8Clamped.toString()).toEqual("0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0");
console.log(uint8Clamped.toString()); // "0,0,0,0,42,0,0,0,0,0,0,0,0,0,0,0"
let res = buffer.slice(4, 12);
let sliced = new Uint8ClampedArray(res);
expect(sliced[0]).toEqual(42);
console.log(sliced[0]); // 42
// #END
expect(sliced[0]).toEqual(42);
}
testSome() {
// #TEST Uint8ClampedArray.some
const uint8Clamped = new Uint8ClampedArray([8, 20, 30, 40, 50]);
const positives = new Uint8ClampedArray([10, 20, 30, 40, 50]);
expect
(uint8Clamped.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
console.log
(uint8Clamped.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 10
))
.toEqual(true);
))
; // true
console.log(positives.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 0
)); // false
// #END
expect(positives.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 0
)).toEqual(false);
// #END
expect(uint8Clamped.some((element : number, index : number, array : Uint8ClampedArray) : boolean =>
element < 10
)).toEqual(true);
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUint16Array.uts
浏览文件 @
0c883eb7
...
...
@@ -65,79 +65,94 @@ export class TUint16Array {
testSet() {
// #TEST Uint16Array.set
let uint16 = new Uint16Array(8);
var array = [1, 2, 3]
var array = [1, 2, 3]
;
uint16.set(array, 1);
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(uint16.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(uint16.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
// #TEST Uint16Array.copyWith
console.log("testCopyWith 1")
// #TEST Uint16Array.copyWith
in
console.log("testCopyWith 1")
;
let uint16 = new Uint16Array(8);
uint16.set([1, 2, 3], 1);
console.log("testCopyWith 2")
console.log("testCopyWith 2")
;
uint16.copyWithin(3, 0, 3);
console.log("testCopyWith 3")
expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log("testCopyWith 3")
;
console.log(uint16.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(uint16.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Uint16Array.every
// const isBelowThreshold = (currentValue: number, index: number, array: Uint16Array): boolean => currentValue < 40;
let result = new Uint16Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint16Array) :
boolean => value < 40);
expect(result).toEqual(false);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Uint16Array.fill
let uint16 = new Uint16Array([1, 2, 3]).fill(4);
console.log(uint16.toString()); // "4,4,4"
// #END
expect(uint16.toString()).toEqual("4,4,4");
uint16 = new Uint16Array([1, 2, 3]).fill(4, 1);
console.log(uint16.toString()); // "1,4,4"
// #END
expect(uint16.toString()).toEqual("1,4,4");
uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 2);
console.log(uint16.toString()); // "1,4,3"
// #END
expect(uint16.toString()).toEqual("1,4,3");
uint16 = new Uint16Array([1, 2, 3]).fill(4, 1, 1);
console.log(uint16.toString()); // "1,2,3"
// #END
expect(uint16.toString()).toEqual("1,2,3");
uint16 = new Uint16Array([1, 2, 3]).fill(4, -3, -2);
expect(uint16.toString()).toEqual("4,2,3");
console.log(uint16.toString()); // "4,2,3"
// #END
expect(uint16.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Uint16Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint16 = new Uint16Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint16Array) :
boolean => value >= 10);
expect(uint16.toString()).toEqual("12,44");
console.log(uint16.toString()); // "12,44"
// #END
expect(uint16.toString()).toEqual("12,44");
}
find() {
// #TEST Uint16Array.find
let uint16 = new Uint16Array([4, 5, 8, 12]);
let res = uint16.find((value : number, _ : number, _a : Uint16Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Uint16Array.findIndex
let uint16 = new Uint16Array([4, 6, 8, 12]);
let res = uint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100);
console.log(res); // -1
// #END
expect(res).toEqual(-1);
let uuint16 = new Uint16Array([4, 6, 7, 120]);
res = uuint16.findIndex((value : number, _ : number, _a : Uint16Array) : boolean => value > 100);
expect(res).toEqual(3);
console.log(res); // 3
// #END
expect(res).toEqual(3);
}
foreach() {
...
...
@@ -152,87 +167,114 @@ export class TUint16Array {
// #TEST Uint16Array.entries
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
let entry = entries.next().value;
console.log(entry[1]); // 10
// #END
expect(entry[1]).toEqual(10);
}
includes() {
// #TEST Uint16Array.includes
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.includes(2);
console.log(res); // true
// #END
expect(res).toEqual(true);
res = uint16.includes(4);
console.log(res); // false
// #END
expect(res).toEqual(false);
res = uint16.includes(3, 3);
expect(res).toEqual(false);
console.log(res); // false
// #END
expect(res).toEqual(false);
}
indexOf() {
// #TEST Uint16Array.indexOf
let uint16 = new Uint16Array([2, 5, 9]);
let res = uint16.indexOf(2);
console.log(res); // 0
// #END
expect(res).toEqual(0);
res = uint16.indexOf(7);
console.log(res); // -1
// #END
expect(res).toEqual(-1);
res = uint16.indexOf(9, 2);
console.log(res); // 2
// #END
expect(res).toEqual(2);
res = uint16.indexOf(2, -1);
console.log(res); // -1
// #END
expect(res).toEqual(-1);
res = uint16.indexOf(2, -3);
expect(res).toEqual(0);
console.log(res); // 0
// #END
expect(res).toEqual(0);
}
join() {
// #TEST Uint16Array.join
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.join();
console.log(res); // "1,2,3"
// #END
expect(res).toEqual("1,2,3");
res = uint16.join(" / ");
console.log(res); // "1 / 2 / 3"
// #END
expect(res).toEqual("1 / 2 / 3");
res = uint16.join("");
expect(res).toEqual("123");
console.log(res); // "123"
// #END
expect(res).toEqual("123");
}
keys() {
// #TEST Uint16Array.keys
let arr = new Uint16Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
let value = keys.next().value
console.log(value); // 0
// #END
expect(value).toEqual(0);
}
map() {
// #TEST Uint16Array.map
let numbers = new Uint16Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint16Array) : number => value * 2);
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
// #END
}
reduce() {
// #TEST Uint16Array.reduce
let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue);
console.log(res); // 6
// #END
expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reduceRight() {
...
...
@@ -240,48 +282,63 @@ export class TUint16Array {
let total = new Uint16Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue);
console.log(res); // 6
// #END
expect(res).toEqual(6);
total = new Uint16Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint16Array) : number =>
accumulator + currentValue, 8);
expect(res).toEqual(14);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reverse() {
// #TEST Uint16Array.reverse
let uint16 = new Uint16Array([1, 2, 3]);
uint16.reverse();
expect(uint16.toString()).toEqual("3,2,1");
console.log(uint16.toString()); // "3,2,1"
// #END
expect(uint16.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Uint16Array.slice
let uint16 = new Uint16Array([1, 2, 3]);
let res = uint16.slice(1);
console.log(res.toString()); // "2,3"
// #END
expect(res.toString()).toEqual("2,3");
res = uint16.slice(2);
console.log(res.toString()); // "3"
// #END
expect(res.toString()).toEqual("3");
res = uint16.slice(-2);
console.log(res.toString()); // "2,3"
// #END
expect(res.toString()).toEqual("2,3");
res = uint16.slice(0, 1);
expect(res.toString()).toEqual("1");
console.log(res.toString()); // "1"
// #END
expect(res.toString()).toEqual("1");
}
sort() {
// #TEST Uint16Array.sort
let numbers = new Uint16Array([40, 1, 5]);
numbers.sort();
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
}
subarray() {
...
...
@@ -289,35 +346,42 @@ export class TUint16Array {
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
uint16.set([1, 2, 3]);
console.log(uint16.toString()); // "1,2,3,0,0,0,0,0"
// #END
expect(uint16.toString()).toEqual("1,2,3,0,0,0,0,0");
let sub = uint16.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
}
values() {
// #TEST Uint16Array.values
let arr = new Uint16Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
let value = values.next().value
console.log(value); // 1
// #END
expect(value).toEqual(1);
}
arrayBufferSlice() {
// #TEST Uint16Array.arrayBufferSlice
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
uint16[4] = 42;
console.log(uint16.toString()); // "0,0,0,0,42,0,0,0"
// #END
expect(uint16.toString()).toEqual("0,0,0,0,42,0,0,0");
let res = buffer.slice(8);
let sliced = new Uint16Array(res);
expect(sliced[0]).toEqual(42);
console.log(sliced[0]); // 42
// #END
expect(sliced[0]).toEqual(42);
}
testSome() {
// #TEST Uint16Array.some
const uint16 = new Uint16Array([8, 20, 30, 40, 50]);
...
...
@@ -327,11 +391,11 @@ export class TUint16Array {
element < 10
)).toEqual(true);
expect(positives.some((element : number, index : number, array : Uint16Array) : boolean =>
element < 0
)).toEqual(false);
// #END
}
// #endif
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUint32Array.uts
浏览文件 @
0c883eb7
...
...
@@ -68,8 +68,9 @@ export class TUint32Array {
let uint32 = new Uint32Array(8);
var array = [1, 2, 3];
uint32.set(array, 1);
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
console.log(uint32.toString()); // "0,1,2,3,0,0,0,0"
// #END
expect(uint32.toString()).toEqual("0,1,2,3,0,0,0,0");
}
testCopyWith() {
...
...
@@ -77,65 +78,65 @@ export class TUint32Array {
console.log("testCopyWith 1");
let uint32 = new Uint32Array(8);
uint32.set([1, 2, 3], 1);
console.log("testCopyWith
1
");
console.log("testCopyWith
2
");
uint32.copyWithin(3, 0, 3);
console.log("testCopyWith
1
");
expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0");
console.log("testCopyWith
3
");
console.log(uint32.toString()); // "0,1,2,0,1,2,0,0"
// #END
expect(uint32.toString()).toEqual("0,1,2,0,1,2,0,0");
}
testEvery() {
// #TEST Uint32Array.every
// const isBelowThreshold = (currentValue: number, index: number, array: Uint32Array): boolean => currentValue < 40;
let result = new Uint32Array([12, 5, 8, 130, 44]).every((value : number, _ : number, _a : Uint32Array) : boolean => value < 40);
expect(result).toEqual(false);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
testFill() {
// #TEST Uint32Array.fill
let uint32 = new Uint32Array([1, 2, 3]).fill(4);
expect(uint32.toString()).toEqual("4,4,4");
console.log(uint32.toString()); // "4,4,4"
uint32 = new Uint32Array([1, 2, 3]).fill(4, 1);
expect(uint32.toString()).toEqual("1,4,4");
console.log(uint32.toString()); // "1,4,4"
uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 2);
expect(uint32.toString()).toEqual("1,4,3");
console.log(uint32.toString()); // "1,4,3"
uint32 = new Uint32Array([1, 2, 3]).fill(4, 1, 1);
expect(uint32.toString()).toEqual("1,2,3");
console.log(uint32.toString()); // "1,2,3"
uint32 = new Uint32Array([1, 2, 3]).fill(4, -3, -2);
expect(uint32.toString()).toEqual("4,2,3");
console.log(uint32.toString()); // "4,2,3"
// #END
expect(uint32.toString()).toEqual("4,2,3");
}
testFilter() {
// #TEST Uint32Array.filter
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let uint32 = new Uint32Array([12, 5, 8, 44]).filter((value : number, _ : number, _a : Uint32Array) : boolean => value >= 10);
expect(uint32.toString()).toEqual("12,44");
console.log(uint32.toString()); // "12,44"
// #END
expect(uint32.toString()).toEqual("12,44");
}
find() {
// #TEST Uint32Array.find
let uint32 = new Uint32Array([4, 5, 8, 12]);
let res = uint32.find((value : number, _ : number, _a : Uint32Array) : boolean => value > 5);
expect(res).toEqual(8);
console.log(res); // 8
// #END
expect(res).toEqual(8);
}
findIndex() {
// #TEST Uint32Array.findIndex
let uint32 = new Uint32Array([4, 6, 8, 12]);
let res = uint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
expect(res).toEqual(-1);
let uuint32 = new Uint32Array([4, 6, 7, 120]);
res = uuint32.findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
expect(res).toEqual(3);
console.log(res); // -1
res = new Uint32Array([4, 6, 7, 120]).findIndex((value : number, _ : number, _a : Uint32Array) : boolean => value > 100);
console.log(res); // 3
// #END
expect(res).toEqual(3);
}
foreach() {
...
...
@@ -145,189 +146,206 @@ export class TUint32Array {
});
// #END
}
iterator() {
// #TEST Uint32Array.entries
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let entries = arr.entries();
expect(entries.next().value[1]).toEqual(10);
let entry = entries.next().value;
console.log(entry[1]); // 10
// #END
expect(entry[1]).toEqual(10);
}
includes() {
// #TEST Uint32Array.includes
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.includes(2);
expect(res).toEqual(true);
console.log(res); // true
res = uint32.includes(4);
expect(res).toEqual(false);
console.log(res); // false
res = uint32.includes(3, 3);
expect(res).toEqual(false);
console.log(res); // false
// #END
expect(res).toEqual(false);
}
indexOf() {
// #TEST Uint32Array.indexOf
let uint32 = new Uint32Array([2, 5, 9]);
let res = uint32.indexOf(2);
expect(res).toEqual(0);
console.log(res); // 0
res = uint32.indexOf(7);
expect(res).toEqual(-1);
console.log(res); // -1
res = uint32.indexOf(9, 2);
expect(res).toEqual(2);
console.log(res); // 2
res = uint32.indexOf(2, -1);
expect(res).toEqual(-1);
console.log(res); // -1
res = uint32.indexOf(2, -3);
expect(res).toEqual(0);
console.log(res); // 0
// #END
expect(res).toEqual(0);
}
join() {
// #TEST Uint32Array.join
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.join();
expect(res).toEqual("1,2,3");
console.log(res); // "1,2,3"
res = uint32.join(" / ");
expect(res).toEqual("1 / 2 / 3");
console.log(res); // "1 / 2 / 3"
res = uint32.join("");
expect(res).toEqual("123");
console.log(res); // "123"
// #END
expect(res).toEqual("123");
}
keys() {
// #TEST Uint32Array.keys
let arr = new Uint32Array([10, 20, 30, 40, 50]);
let keys = arr.keys();
expect(keys.next().value).toEqual(0);
let value = keys.next().value
console.log(value); // 0
// #END
expect(value).toEqual(0);
}
map() {
// #TEST Uint32Array.map
let numbers = new Uint32Array([1, 4, 9]);
let doubles = numbers.map((value : number, _ : number, _a : Uint32Array) : number => value * 2);
expect(numbers.toString()).toEqual("1,4,9");
expect(doubles.toString()).toEqual("2,8,18");
console.log(numbers.toString()); // "1,4,9"
console.log(doubles.toString()); // "2,8,18"
// #END
expect(doubles.toString()).toEqual("2,8,18");
}
reduce() {
// #TEST Uint32Array.reduce
let total = new Uint32Array([0, 1, 2, 3]);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) :
number => accumulator + currentValue);
expect(res).toEqual(6);
let res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue);
console.log(res); // 6
total = new Uint32Array([0, 1, 2, 3]);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) :
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
res = total.reduce((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reduceRight() {
// #TEST Uint32Array.reduceRight
let total = new Uint32Array([0, 1, 2, 3]);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) :
number => accumulator + currentValue);
expect(res).toEqual(6);
let res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue);
console.log(res); // 6
total = new Uint32Array([0, 1, 2, 3]);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) :
number => accumulator + currentValue, 8);
expect(res).toEqual(14);
res = total.reduceRight((accumulator : number, currentValue : number, _ : number, _a : Uint32Array) : number => accumulator + currentValue, 8);
console.log(res); // 14
// #END
expect(res).toEqual(14);
}
reverse() {
// #TEST Uint32Array.reverse
let uint32 = new Uint32Array([1, 2, 3]);
uint32.reverse();
expect(uint32.toString()).toEqual("3,2,1");
console.log(uint32.toString()); // "3,2,1"
// #END
expect(uint32.toString()).toEqual("3,2,1");
}
slice() {
// #TEST Uint32Array.slice
let uint32 = new Uint32Array([1, 2, 3]);
let res = uint32.slice(1);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
res = uint32.slice(2);
expect(res.toString()).toEqual("3");
console.log(res.toString()); // "3"
res = uint32.slice(-2);
expect(res.toString()).toEqual("2,3");
console.log(res.toString()); // "2,3"
res = uint32.slice(0, 1);
expect(res.toString()).toEqual("1");
console.log(res.toString()); // "1"
// #END
expect(res.toString()).toEqual("1");
}
sort() {
// #TEST Uint32Array.sort
let numbers = new Uint32Array([40, 1, 5]);
numbers.sort();
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
numbers.sort((a, b) : number => a - b);
expect(numbers.toString()).toEqual("1,5,40");
console.log(numbers.toString()); // "1,5,40"
// #END
expect(numbers.toString()).toEqual("1,5,40");
}
subarray() {
// #TEST Uint32Array.subarray
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
uint32.set([1, 2, 3]);
expect(uint32.toString()).toEqual("1,2,3,0");
console.log(uint32.toString()); // "1,2,3,0"
let sub = uint32.subarray(0, 4);
expect(sub.toString()).toEqual("1,2,3,0");
console.log(sub.toString()); // "1,2,3,0"
// #END
expect(sub.toString()).toEqual("1,2,3,0");
}
values() {
// #TEST Uint32Array.values
let arr = new Uint32Array([1, 2, 3]);
let values = arr.values();
expect(values.next().value).toEqual(1);
let value = values.next().value;
console.log(value); // 1
// #END
expect(value).toEqual(1);
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
uint32[3] = 42;
expect(uint32.toString()).toEqual("0,0,0,42");
console.log(uint32.toString()); // "0,0,0,42"
let res = buffer.slice(8);
let sliced = new Uint32Array(res);
expect(sliced[1]).toEqual(42);
console.log(sliced[1]); // 42
// #END
expect(sliced[1]).toEqual(42);
}
testSome() {
// #TEST Uint32Array.some
const uint32 = new Uint32Array([8, 20, 30, 40, 50]);
const positives = new Uint32Array([10, 20, 30, 40, 50]);
expect(
uint32.some((element : number, index : number, array : Uint32Array) : boolean =>
let result =
uint32.some((element : number, index : number, array : Uint32Array) : boolean =>
element < 10
)
).toEqual(true)
;
);
console.log(result); // true
expect(
positives.some((element : number, index : number, array : Uint32Array) : boolean =>
result =
positives.some((element : number, index : number, array : Uint32Array) : boolean =>
element < 0
)).toEqual(false);
);
console.log(result); // false
// #END
expect(result).toEqual(false);
}
// #endif
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录