Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
626f78af
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1625
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看板
提交
626f78af
编写于
7月 01, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[array-buffer]添加测试用例
上级
b0c0f736
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
3479 addition
and
3 deletion
+3479
-3
uni_modules/uts-tests/utssdk/ArrayBuffer.uts
uni_modules/uts-tests/utssdk/ArrayBuffer.uts
+725
-0
uni_modules/uts-tests/utssdk/TDataView.js
uni_modules/uts-tests/utssdk/TDataView.js
+329
-0
uni_modules/uts-tests/utssdk/TFloat32Array.js
uni_modules/uts-tests/utssdk/TFloat32Array.js
+284
-0
uni_modules/uts-tests/utssdk/TFloat64Array.js
uni_modules/uts-tests/utssdk/TFloat64Array.js
+279
-0
uni_modules/uts-tests/utssdk/TInt16Array.js
uni_modules/uts-tests/utssdk/TInt16Array.js
+253
-0
uni_modules/uts-tests/utssdk/TInt32Array.js
uni_modules/uts-tests/utssdk/TInt32Array.js
+269
-0
uni_modules/uts-tests/utssdk/TInt8Array.js
uni_modules/uts-tests/utssdk/TInt8Array.js
+263
-0
uni_modules/uts-tests/utssdk/TUInt8Array.js
uni_modules/uts-tests/utssdk/TUInt8Array.js
+256
-0
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.js
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.js
+262
-0
uni_modules/uts-tests/utssdk/TUint16Array.js
uni_modules/uts-tests/utssdk/TUint16Array.js
+276
-0
uni_modules/uts-tests/utssdk/TUint32Array.js
uni_modules/uts-tests/utssdk/TUint32Array.js
+276
-0
uni_modules/uts-tests/utssdk/index.uts
uni_modules/uts-tests/utssdk/index.uts
+7
-3
未找到文件。
uni_modules/uts-tests/utssdk/ArrayBuffer.uts
0 → 100644
浏览文件 @
626f78af
import { describe, test, expect, Result } from './tests.uts'
import { TDataView } from './TDataView.js'
import { TFloat32Array } from './TFloat32Array.js'
import { TFloat64Array } from './TFloat64Array.js'
import { TInt8Array } from './TInt8Array.js'
import { TInt16Array } from './TInt16Array.js'
import { TInt32Array } from './TInt32Array.js'
import { TUint8Array } from './TUint8Array.js'
import { TUint8ClampedArray } from './TUint8ClampedArray.js'
import { TUint16Array } from './TUint16Array.js'
import { TUint32Array } from './TUint32Array.js'
const tDataView = new TDataView();
const float32 = new TFloat32Array();
const float64 = new TFloat64Array()
const int8 = new TInt8Array()
const int32 = new TInt32Array()
const uint8 = new TUint8Array()
const uint8Clamped = new TUint8ClampedArray()
const uint16 = new TUint16Array()
const uint32 = new TUint32Array()
const int16 = new TInt16Array()
export function testArrayBuffer() : Result {
return describe("ArrayBuffer", () => {
//dataview start
test('dataview_constructor', () => {
tDataView.setConstructor()
})
test('dataview_setInt8', () => {
tDataView.setInt8()
})
test('dataview_setFloat32', () => {
tDataView.setFloat32()
})
test('dataview_setFloat64', () => {
tDataView.setFloat64()
})
test('dataview_setInt16', () => {
tDataView.setInt16()
})
test('dataview_setInt32', () => {
tDataView.setInt32()
})
test('dataview_setUint16', () => {
tDataView.setUint16()
})
test('dataview_setUint32', () => {
tDataView.setUint32()
})
test('dataview_setUint8', () => {
tDataView.setUint8()
})
test('doTestDataViewBigEndian', () => {
tDataView.doTestDataViewBigEndian()
})
test('doTestDataViewLittleEndian', () => {
tDataView.doTestDataViewLittleEndian()
})
test('doTestTypedArrayBigEndian', () => {
tDataView.doTestTypedArrayBigEndian()
})
test('doTestTypedArrayLittleEndian', () => {
tDataView.doTestTypedArrayLittleEndian()
})
test('doTestDataViewFloats', () => {
tDataView.doTestDataViewFloats()
})
//dataview end
//float32array start
test('float32_testConstructor', () => {
float32.testConstructor()
})
test('float32_testSet', () => {
float32.testSet()
})
test('float32_testCopyWith', () => {
float32.testCopyWith()
})
test('float32_testEvery', () => {
float32.testEvery()
})
test('float32_testFill', () => {
float32.testFill()
})
test('float32_testFilter', () => {
float32.testFilter()
})
test('float32_find', () => {
float32.find()
})
test('float32_findIndex', () => {
float32.findIndex()
})
test('float32_foreach', () => {
float32.foreach()
})
test('float32_iterator', () => {
float32.iterator()
})
test('float32_includes', () => {
float32.includes()
})
test('float32_indexOf', () => {
float32.indexOf()
})
test('float32_join', () => {
float32.join()
})
test('float32_keys', () => {
float32.keys()
})
test('float32_map', () => {
float32.map()
})
test('float32_reduce', () => {
float32.reduce()
})
test('float32_reduceRight', () => {
float32.reduceRight()
})
test('float32_reverse', () => {
float32.reverse()
})
test('float32_slice', () => {
float32.slice()
})
test('float32_sort', () => {
float32.sort()
})
test('float32_subarray', () => {
float32.subarray()
})
test('float32_values', () => {
float32.values()
})
test('float32_arrayBufferSlice', () => {
float32.arrayBufferSlice()
})
//float32array end
//float64array start
test('float64_testConstructor', () => {
float64.testConstructor()
})
test('float64_testSet', () => {
float64.testSet()
})
test('float64_testCopyWith', () => {
float64.testCopyWith()
})
test('float64_testEvery', () => {
float64.testEvery()
})
test('float64_testFill', () => {
float64.testFill()
})
test('float64_testFilter', () => {
float64.testFilter()
})
test('float64_find', () => {
float64.find()
})
test('float64_findIndex', () => {
float64.findIndex()
})
test('float64_foreach', () => {
float64.foreach()
})
test('float64_iterator', () => {
float64.iterator()
})
test('float64_includes', () => {
float64.includes()
})
test('float64_indexOf', () => {
float64.indexOf()
})
test('float64_join', () => {
float64.join()
})
test('float64_keys', () => {
float64.keys()
})
test('float64_map', () => {
float64.map()
})
test('float64_reduce', () => {
float64.reduce()
})
test('float64_reduceRight', () => {
float64.reduceRight()
})
test('float64_reverse', () => {
float64.reverse()
})
test('float64_slice', () => {
float64.slice()
})
test('float64_sort', () => {
float64.sort()
})
test('float64_subarray', () => {
float64.subarray()
})
test('float64_values', () => {
float64.values()
})
test('float64_arrayBufferSlice', () => {
float64.arrayBufferSlice()
})
//float64 end
//int8 start
test('int8_testConstructor', () => {
int8.testConstructor()
})
test('int8_testSet', () => {
int8.testSet()
})
test('int8_testCopyWith', () => {
int8.testCopyWith()
})
test('int8_testEvery', () => {
int8.testEvery()
})
test('int8_testFill', () => {
int8.testFill()
})
test('int8_testFilter', () => {
int8.testFilter()
})
test('int8_find', () => {
int8.find()
})
test('int8_findIndex', () => {
int8.findIndex()
})
test('int8_foreach', () => {
int8.foreach()
})
test('int8_iterator', () => {
int8.iterator()
})
test('int8_includes', () => {
int8.includes()
})
test('int8_indexOf', () => {
int8.indexOf()
})
test('int8_join', () => {
int8.join()
})
test('int8_keys', () => {
int8.keys()
})
test('int8_map', () => {
int8.map()
})
test('int8_reduce', () => {
int8.reduce()
})
test('int8_reduceRight', () => {
int8.reduceRight()
})
test('int8_reverse', () => {
int8.reverse()
})
test('int8_slice', () => {
int8.slice()
})
test('int8_sort', () => {
int8.sort()
})
test('int8_subarray', () => {
int8.subarray()
})
test('int8_values', () => {
int8.values()
})
test('int8_arrayBufferSlice', () => {
int8.arrayBufferSlice()
})
// //int8 end
// //int16 start
test('int16_testConstructor', () => {
int16.testConstructor()
})
test('int16_testSet', () => {
int16.testSet()
})
test('int16_testCopyWith', () => {
int16.testCopyWith()
})
test('int16_testEvery', () => {
int16.testEvery()
})
test('int16_testFill', () => {
int16.testFill()
})
test('int16_testFilter', () => {
int16.testFilter()
})
test('int16_find', () => {
int16.find()
})
test('int16_findIndex', () => {
int16.findIndex()
})
test('int16_foreach', () => {
int16.foreach()
})
test('int16_iterator', () => {
int16.iterator()
})
test('int16_includes', () => {
int16.includes()
})
test('int16_indexOf', () => {
int16.indexOf()
})
test('int16_join', () => {
int16.join()
})
test('int16_keys', () => {
int16.keys()
})
test('int16_map', () => {
int16.map()
})
test('int16_reduce', () => {
int16.reduce()
})
test('int16_reduceRight', () => {
int16.reduceRight()
})
test('int16_reverse', () => {
int16.reverse()
})
test('int16_slice', () => {
int16.slice()
})
test('int16_sort', () => {
int16.sort()
})
test('int16_subarray', () => {
int16.subarray()
})
test('int16_values', () => {
int16.values()
})
test('int16_arrayBufferSlice', () => {
int16.arrayBufferSlice()
})
//int16 end
//int32 start
test('int32_testConstructor', () => {
int32.testConstructor()
})
test('int32_testSet', () => {
int32.testSet()
})
test('int32_testCopyWith', () => {
int32.testCopyWith()
})
test('int32_testEvery', () => {
int32.testEvery()
})
test('int32_testFill', () => {
int32.testFill()
})
test('int32_testFilter', () => {
int32.testFilter()
})
test('int32_find', () => {
int32.find()
})
test('int32_findIndex', () => {
int32.findIndex()
})
test('int32_foreach', () => {
int32.foreach()
})
test('int32_iterator', () => {
int32.iterator()
})
test('int32_includes', () => {
int32.includes()
})
test('int32_indexOf', () => {
int32.indexOf()
})
test('int32_join', () => {
int32.join()
})
test('int32_keys', () => {
int32.keys()
})
test('int32_map', () => {
int32.map()
})
test('int32_reduce', () => {
int32.reduce()
})
test('int32_reduceRight', () => {
int32.reduceRight()
})
test('int32_reverse', () => {
int32.reverse()
})
test('int32_slice', () => {
int32.slice()
})
test('int32_sort', () => {
int32.sort()
})
test('int32_subarray', () => {
int32.subarray()
})
test('int32_values', () => {
int32.values()
})
test('int32_arrayBufferSlice', () => {
int32.arrayBufferSlice()
})
//int32 end
//uint8 start
test('uint8_testConstructor', () => {
uint8.testConstructor()
})
test('uint8_testSet', () => {
uint8.testSet()
})
test('uint8_testCopyWith', () => {
uint8.testCopyWith()
})
test('uint8_testEvery', () => {
uint8.testEvery()
})
test('uint8_testFill', () => {
uint8.testFill()
})
test('uint8_testFilter', () => {
uint8.testFilter()
})
test('uint8_find', () => {
uint8.find()
})
test('uint8_findIndex', () => {
uint8.findIndex()
})
test('uint8_foreach', () => {
uint8.foreach()
})
test('uint8_iterator', () => {
uint8.iterator()
})
test('uint8_includes', () => {
uint8.includes()
})
test('uint8_indexOf', () => {
uint8.indexOf()
})
test('uint8_join', () => {
uint8.join()
})
test('uint8_keys', () => {
uint8.keys()
})
test('uint8_map', () => {
uint8.map()
})
test('uint8_reduce', () => {
uint8.reduce()
})
test('uint8_reduceRight', () => {
uint8.reduceRight()
})
test('uint8_reverse', () => {
uint8.reverse()
})
test('uint8_slice', () => {
uint8.slice()
})
test('uint8_sort', () => {
uint8.sort()
})
test('uint8_subarray', () => {
uint8.subarray()
})
test('uint8_values', () => {
uint8.values()
})
test('uint8_arrayBufferSlice', () => {
uint8.arrayBufferSlice()
})
//uint8 end
//uint8Clamped start
test('uint8Clamped_testConstructor', () => {
uint8Clamped.testConstructor()
})
test('uint8Clamped_testSet', () => {
uint8Clamped.testSet()
})
test('uint8Clamped_testCopyWith', () => {
uint8Clamped.testCopyWith()
})
test('uint8Clamped_testEvery', () => {
uint8Clamped.testEvery()
})
test('uint8Clamped_testFill', () => {
uint8Clamped.testFill()
})
test('uint8Clamped_testFilter', () => {
uint8Clamped.testFilter()
})
test('uint8Clamped_find', () => {
uint8Clamped.find()
})
test('uint8Clamped_findIndex', () => {
uint8Clamped.findIndex()
})
test('uint8Clamped_foreach', () => {
uint8Clamped.foreach()
})
test('uint8Clamped_iterator', () => {
uint8Clamped.iterator()
})
test('uint8Clamped_includes', () => {
uint8Clamped.includes()
})
test('uint8Clamped_indexOf', () => {
uint8Clamped.indexOf()
})
test('uint8Clamped_join', () => {
uint8Clamped.join()
})
test('uint8Clamped_keys', () => {
uint8Clamped.keys()
})
test('uint8Clamped_map', () => {
uint8Clamped.map()
})
test('uint8Clamped_reduce', () => {
uint8Clamped.reduce()
})
test('uint8Clamped_reduceRight', () => {
uint8Clamped.reduceRight()
})
test('uint8Clamped_reverse', () => {
uint8Clamped.reverse()
})
test('uint8Clamped_slice', () => {
uint8Clamped.slice()
})
test('uint8Clamped_sort', () => {
uint8Clamped.sort()
})
test('uint8Clamped_subarray', () => {
uint8Clamped.subarray()
})
test('uint8Clamped_values', () => {
uint8Clamped.values()
})
test('uint8Clamped_arrayBufferSlice', () => {
uint8Clamped.arrayBufferSlice()
})
//uint8Clamped end
//uint16 start
test('uint16_testConstructor', () => {
uint16.testConstructor()
})
test('uint16_testSet', () => {
uint16.testSet()
})
test('uint16_testCopyWith', () => {
uint16.testCopyWith()
})
test('uint16_testEvery', () => {
uint16.testEvery()
})
test('uint16_testFill', () => {
uint16.testFill()
})
test('uint16_testFilter', () => {
uint16.testFilter()
})
test('uint16_find', () => {
uint16.find()
})
test('uint16_findIndex', () => {
uint16.findIndex()
})
test('uint16_foreach', () => {
uint16.foreach()
})
test('uint16_iterator', () => {
uint16.iterator()
})
test('uint16_includes', () => {
uint16.includes()
})
test('uint16_indexOf', () => {
uint16.indexOf()
})
test('uint16_join', () => {
uint16.join()
})
test('uint16_keys', () => {
uint16.keys()
})
test('uint16_map', () => {
uint16.map()
})
test('uint16_reduce', () => {
uint16.reduce()
})
test('uint16_reduceRight', () => {
uint16.reduceRight()
})
test('uint16_reverse', () => {
uint16.reverse()
})
test('uint16_slice', () => {
uint16.slice()
})
test('uint16_sort', () => {
uint16.sort()
})
test('uint16_subarray', () => {
uint16.subarray()
})
test('uint16_values', () => {
uint16.values()
})
test('uint16_arrayBufferSlice', () => {
uint16.arrayBufferSlice()
})
//uint16 end
//uint32 start
test('uint32_testConstructor', () => {
uint32.testConstructor()
})
test('uint32_testSet', () => {
uint32.testSet()
})
test('uint32_testCopyWith', () => {
uint32.testCopyWith()
})
test('uint32_testEvery', () => {
uint32.testEvery()
})
test('uint32_testFill', () => {
uint32.testFill()
})
test('uint32_testFilter', () => {
uint32.testFilter()
})
test('uint32_find', () => {
uint32.find()
})
test('uint32_findIndex', () => {
uint32.findIndex()
})
test('uint32_foreach', () => {
uint32.foreach()
})
test('uint32_iterator', () => {
uint32.iterator()
})
test('uint32_includes', () => {
uint32.includes()
})
test('uint32_indexOf', () => {
uint32.indexOf()
})
test('uint32_join', () => {
uint32.join()
})
test('uint32_keys', () => {
uint32.keys()
})
test('uint32_map', () => {
uint32.map()
})
test('uint32_reduce', () => {
uint32.reduce()
})
test('uint32_reduceRight', () => {
uint32.reduceRight()
})
test('uint32_reverse', () => {
uint32.reverse()
})
test('uint32_slice', () => {
uint32.slice()
})
test('uint32_sort', () => {
uint32.sort()
})
test('uint32_subarray', () => {
uint32.subarray()
})
test('uint32_values', () => {
uint32.values()
})
test('uint32_arrayBufferSlice', () => {
uint32.arrayBufferSlice()
})
//uint32 end
})
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TDataView.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TDataView
{
test
()
{
// this.setDv();
// this.setInt8();
// this.setFloat32();
// this.setFloat64();
// this.setInt16();
// this.setInt32();
// this.setUint16();
// this.setUint32();
// this.setUint8();
// this.testMix();
}
setConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
dataview
=
new
DataView
(
buffer
);
dataview
.
setInt8
(
1
,
12
);
dataview
.
setFloat32
(
1
,
34
);
expect
(
dataview
.
getInt8
(
1
)).
toEqual
(
66
);
expect
(
this
.
numberEquals
(
34
,
dataview
.
getFloat32
(
1
))).
toEqual
(
true
);
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
,
1
,
4
);
view
.
setInt16
(
1
,
42
);
// 42
expect
(
view
.
getInt16
(
1
)).
toEqual
(
42
);
}
setInt8
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setInt8
(
1
,
127
);
// Max signed 8-bit integer
expect
(
view
.
getInt8
(
1
)).
toEqual
(
127
);
}
setFloat32
()
{
console
.
log
(
'
setFloat32
'
,
'
start
'
)
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setFloat32
(
1
,
Math
.
PI
.
toFloat
());
expect
(
this
.
numberEquals
(
3.1415927
,
view
.
getFloat32
(
1
).
toFloat
())).
toEqual
(
true
);
}
setFloat64
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setFloat64
(
1
,
Math
.
PI
);
expect
(
this
.
numberEquals
(
3.141592653589793
,
view
.
getFloat64
(
1
))).
toEqual
(
true
);
}
setInt16
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setInt16
(
1
,
32767
);
// Max signed 16-bit integer
expect
(
view
.
getInt16
(
1
)).
toEqual
(
32767
);
}
setInt32
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setInt32
(
1
,
2147483647
);
// Max signed 32-bit integer
expect
(
this
.
numberEquals
(
2147483647
,
view
.
getInt32
(
1
))).
toEqual
(
true
);
}
setUint16
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setUint16
(
1
,
65535
);
// Max unsigned 16-bit integer
expect
(
this
.
numberEquals
(
65535
,
view
.
getUint16
(
1
))).
toEqual
(
true
);
}
setUint32
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setUint32
(
1
,
4294967295
);
// Max unsigned 32-bit integer
expect
(
this
.
numberEquals
(
4294967295
,
view
.
getUint32
(
1
))).
toEqual
(
true
);
}
setUint8
()
{
// Create an ArrayBuffer with a size in bytes
let
buffer
=
new
ArrayBuffer
(
16
);
let
view
=
new
DataView
(
buffer
);
view
.
setUint8
(
1
,
255
);
// Max unsigned 8-bit integer
expect
(
this
.
numberEquals
(
255
,
view
.
getUint8
(
1
))).
toEqual
(
true
);
}
numberEquals
(
a
:
Number
,
b
:
Number
):
Boolean
{
return
a
==
b
}
doTestDataViewBigEndian
()
{
this
.
doIterations
(
false
,
true
);
}
doTestDataViewLittleEndian
()
{
this
.
doIterations
(
true
,
true
);
}
doTestTypedArrayBigEndian
()
{
this
.
doIterations
(
false
,
false
);
}
doTestTypedArrayLittleEndian
()
{
this
.
doIterations
(
true
,
false
);
}
doTestDataViewFloats
()
{
this
.
doFloatIterations
(
true
);
}
doTestTypedArrayFloats
()
{
this
.
doFloatIterations
(
false
);
}
doIterations
(
littleEndian
:
boolean
,
dataView
:
boolean
)
{
var
buffer
=
this
.
makeBuffer
(
1000
,
littleEndian
);
var
iterations
=
10
;
if
(
dataView
)
{
for
(
var
i
=
0
;
i
<
iterations
;
i
++
)
this
.
doOneIterationDV
(
buffer
,
littleEndian
);
}
else
{
for
(
var
i
=
0
;
i
<
iterations
;
i
++
)
this
.
doOneIterationJS
(
buffer
,
littleEndian
);
}
}
makeBuffer
(
size
:
Int
,
littleEndian
:
boolean
):
ArrayBuffer
{
var
buffer
=
new
ArrayBuffer
(
size
*
14
);
var
view
=
new
DataView
(
buffer
);
for
(
var
i
=
0
;
i
<
size
;
++
i
)
{
view
.
setInt8
(
i
*
14
,
i
);
view
.
setUint8
(
i
*
14
+
1
,
i
);
view
.
setInt16
(
i
*
14
+
2
,
i
*
i
,
littleEndian
);
view
.
setUint16
(
i
*
14
+
4
,
i
*
i
,
littleEndian
);
view
.
setInt32
(
i
*
14
+
6
,
i
*
i
*
i
,
littleEndian
);
view
.
setUint32
(
i
*
14
+
10
,
i
*
i
*
i
,
littleEndian
);
}
return
buffer
;
}
doOneIterationDV
(
buffer
:
ArrayBuffer
,
littleEndian
:
boolean
)
{
var
xor
=
0
;
var
view
=
new
DataView
(
buffer
);
for
(
var
i
=
0
;
i
<
view
.
byteLength
;
i
+=
14
)
{
xor
^=
view
.
getInt8
(
i
);
xor
^=
view
.
getUint8
(
i
+
1
);
xor
^=
view
.
getInt16
(
i
+
2
,
littleEndian
);
xor
^=
view
.
getUint16
(
i
+
4
,
littleEndian
);
xor
^=
view
.
getInt32
(
i
+
6
,
littleEndian
);
xor
^=
view
.
getUint32
(
i
+
10
,
littleEndian
);
}
expect
(
xor
).
toEqual
(
0
);
}
doOneIterationJS
(
buffer
:
ArrayBuffer
,
littleEndian
:
boolean
)
{
var
xor
=
0
;
if
(
littleEndian
)
{
var
reader
=
new
LittleEndian
(
buffer
);
for
(
var
i
=
0
;
i
<
buffer
.
byteLength
;
i
+=
14
)
{
xor
^=
reader
.
getInt8
(
i
);
xor
^=
reader
.
getUint8
(
i
+
1
);
xor
^=
reader
.
getInt16
(
i
+
2
);
xor
^=
reader
.
getUint16
(
i
+
4
);
xor
^=
reader
.
getInt32
(
i
+
6
);
xor
^=
reader
.
getUint32
(
i
+
10
);
}
expect
(
xor
).
toEqual
(
0
);
}
else
{
var
reader
=
new
BigEndian
(
buffer
);
for
(
var
i
=
0
;
i
<
buffer
.
byteLength
;
i
+=
14
)
{
xor
^=
reader
.
getInt8
(
i
);
xor
^=
reader
.
getUint8
(
i
+
1
);
xor
^=
reader
.
getInt16
(
i
+
2
);
xor
^=
reader
.
getUint16
(
i
+
4
);
xor
^=
reader
.
getInt32
(
i
+
6
);
xor
^=
reader
.
getUint32
(
i
+
10
);
}
}
}
doFloatIterations
(
dataView
:
boolean
)
{
var
buffer
=
makeFloatBuffer
(
1000
);
var
iterations
=
10
;
if
(
dataView
)
{
for
(
var
i
=
0
;
i
<
iterations
;
i
++
)
this
.
doOneFloatIterationDV
(
buffer
);
}
else
{
for
(
var
i
=
0
;
i
<
iterations
;
i
++
)
this
.
doOneFloatIterationJS
(
buffer
);
}
}
makeFloatBuffer
(
size
:
Int
):
ArrayBuffer
{
var
buffer
=
new
ArrayBuffer
(
size
*
16
);
var
view
=
new
DataView
(
buffer
);
for
(
var
i
=
0
;
i
<
size
;
i
++
)
{
view
.
setFloat64
(
i
*
16
,
Math
.
log10
(
i
+
1
));
view
.
setFloat32
(
i
*
16
+
8
,
Math
.
sqrt
(
i
));
view
.
setFloat32
(
i
*
16
+
12
,
Math
.
cos
(
i
));
}
return
buffer
;
}
doOneFloatIterationDV
(
buffer
:
ArrayBuffer
)
{
var
sum
=
0
;
var
view
=
new
DataView
(
buffer
);
for
(
var
i
=
0
;
i
<
view
.
byteLength
;
i
+=
16
)
{
sum
+=
view
.
getFloat64
(
i
);
sum
+=
view
.
getFloat32
(
i
+
8
);
sum
+=
view
.
getFloat32
(
i
+
12
);
}
expect
(
sum
).
toEqual
(
23634.413356150446
);
}
doOneFloatIterationJS
(
buffer
:
ArrayBuffer
)
{
var
sum
=
0
;
var
float32array
=
new
Float32Array
(
buffer
);
var
float64array
=
new
Float64Array
(
buffer
);
for
(
var
i
=
0
;
i
<
buffer
.
byteLength
;
i
+=
16
)
{
sum
+=
float64array
[
i
/
8
];
sum
+=
float32array
[
i
/
4
+
2
];
sum
+=
float32array
[
i
/
4
+
3
];
}
}
}
class
BigEndian
{
private
uint8View_
:
Uint8Array
;
private
int8View_
:
Int8Array
;
constructor
(
buffer
:
ArrayBuffer
,
)
{
const
offset
=
0
;
this
.
uint8View_
=
new
Uint8Array
(
buffer
,
offset
);
this
.
int8View_
=
new
Int8Array
(
buffer
,
offset
);
}
getInt8
(
byteOffset
:
number
):
number
{
return
this
.
int8View_
[
byteOffset
];
}
getUint8
(
byteOffset
:
number
):
number
{
return
this
.
uint8View_
[
byteOffset
];
}
getInt16
(
byteOffset
:
number
):
number
{
return
this
.
uint8View_
[
byteOffset
+
1
]
|
(
this
.
int8View_
[
byteOffset
]
<<
8
);
}
getUint16
(
byteOffset
:
number
):
number
{
return
this
.
uint8View_
[
byteOffset
+
1
]
|
(
this
.
uint8View_
[
byteOffset
]
<<
8
);
}
getInt32
(
byteOffset
:
number
):
number
{
return
(
this
.
uint8View_
[
byteOffset
+
3
]
|
(
this
.
uint8View_
[
byteOffset
+
2
]
<<
8
)
|
(
this
.
uint8View_
[
byteOffset
+
1
]
<<
16
)
|
(
this
.
int8View_
[
byteOffset
]
<<
24
)
);
}
getUint32
(
byteOffset
:
number
):
number
{
return
(
this
.
uint8View_
[
byteOffset
+
3
]
+
(
this
.
uint8View_
[
byteOffset
+
2
]
<<
8
)
+
(
this
.
uint8View_
[
byteOffset
+
1
]
<<
16
)
+
this
.
uint8View_
[
byteOffset
]
*
(
1
<<
24
)
);
}
}
class
LittleEndian
{
private
uint8View_
:
Uint8Array
;
private
int8View_
:
Int8Array
;
constructor
(
buffer
:
ArrayBuffer
)
{
const
offset
=
0
;
this
.
uint8View_
=
new
Uint8Array
(
buffer
,
offset
);
this
.
int8View_
=
new
Int8Array
(
buffer
,
offset
);
}
getInt8
(
byteOffset
:
number
):
number
{
return
this
.
int8View_
[
byteOffset
];
}
getUint8
(
byteOffset
:
number
):
number
{
return
this
.
uint8View_
[
byteOffset
];
}
getInt16
(
byteOffset
:
number
):
number
{
return
this
.
uint8View_
[
byteOffset
]
|
(
this
.
int8View_
[
byteOffset
+
1
]
<<
8
);
}
getUint16
(
byteOffset
:
number
):
number
{
return
this
.
uint8View_
[
byteOffset
]
|
(
this
.
uint8View_
[
byteOffset
+
1
]
<<
8
);
}
getInt32
(
byteOffset
:
number
):
number
{
return
(
this
.
uint8View_
[
byteOffset
]
|
(
this
.
uint8View_
[
byteOffset
+
1
]
<<
8
)
|
(
this
.
uint8View_
[
byteOffset
+
2
]
<<
16
)
|
(
this
.
int8View_
[
byteOffset
+
3
]
<<
24
)
);
}
getUint32
(
byteOffset
:
number
):
number
{
return
(
this
.
uint8View_
[
byteOffset
]
+
(
this
.
uint8View_
[
byteOffset
+
1
]
<<
8
)
+
(
this
.
uint8View_
[
byteOffset
+
2
]
<<
16
)
+
this
.
uint8View_
[
byteOffset
+
3
]
*
(
1
<<
24
)
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TFloat32Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TFloat32Array
{
test
()
{
this
.
testfloat32
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testfloat32
()
{
let
float32
=
new
Float32Array
(
2
);
float32
[
0
]
=
42
;
expect
(
float32
[
0
]).
toEqual
(
42
);
expect
(
float32
.
length
).
toEqual
(
2
);
expect
(
Float32Array
.
BYTES_PER_ELEMENT
).
toEqual
(
4
);
let
x
=
new
Float32Array
([
21
,
31
,
3
]);
expect
(
x
[
1
]).
toEqual
(
31
);
let
y
=
new
Float32Array
(
x
);
expect
(
y
[
0
]).
toEqual
(
21
);
let
buffer
=
new
ArrayBuffer
(
16
);
let
z
=
new
Float32Array
(
buffer
,
2
,
4
);
expect
(
z
.
byteOffset
).
toEqual
(
2
);
expect
(
z
.
length
).
toEqual
(
4
);
var
k
=
Float32Array
.
of
(
1
,
2
,
3
)
expect
(
k
.
toString
()).
toEqual
(
"
1,2,3
"
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Float32Array
(
buffer
);
float32
[
1
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,42,0,0
"
);
}
testSet
()
{
let
float32
=
new
Float32Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Float32Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
console
.
log
(
"
testCopyWith 1
"
)
float32
.
copyWithin
(
3
,
0
,
3
);
console
.
log
(
"
testCopyWith 1
"
)
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Float32Array): boolean => currentValue < 40;
let
result
=
new
Float32Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Float32Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Float32Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Float32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Float32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Float32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Float32Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Float32Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Float32Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Float32Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Float32Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Float32Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Float32Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Float32Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Float32Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Float32Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Float32Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Float32Array
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
20
);
}
includes
()
{
let
float32
=
new
Float32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2.0
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4.0
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3.0
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Float32Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Float32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
let
arr
=
new
Float32Array
([
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
);
}
map
()
{
let
numbers
=
new
Float32Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Float32Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Float32Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float32Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Float32Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float32Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Float32Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float32Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Float32Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float32Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Float32Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Float32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Float32Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Float32Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Float32Array
([
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
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Float32Array
(
buffer
);
float32
[
3
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,42
"
);
let
res
=
buffer
.
slice
(
8
);
let
sliced
=
new
Float32Array
(
res
);
expect
(
sliced
[
1
]).
toEqual
(
42
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TFloat64Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TFloat64Array
{
test
()
{
this
.
testfloat64
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testfloat64
()
{
let
float32
=
new
Float64Array
(
2
);
float32
[
0
]
=
42
;
expect
(
float32
[
0
]).
toEqual
(
42
);
expect
(
float32
.
length
).
toEqual
(
2
);
expect
(
Float64Array
.
BYTES_PER_ELEMENT
).
toEqual
(
8
);
let
x
=
new
Float64Array
([
21
,
31
,
3
]);
expect
(
x
[
1
]).
toEqual
(
31
);
let
y
=
new
Float64Array
(
x
);
expect
(
y
[
0
]).
toEqual
(
21
);
let
buffer
=
new
ArrayBuffer
(
16
);
let
z
=
new
Float64Array
(
buffer
,
2
,
4
);
expect
(
z
.
byteOffset
).
toEqual
(
2
);
expect
(
z
.
length
).
toEqual
(
4
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Float64Array
(
buffer
);
float32
[
1
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,42
"
);
}
testSet
()
{
let
float32
=
new
Float64Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
let
float32
=
new
Float64Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
float32
.
copyWithin
(
3
,
0
,
3
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Float64Array): boolean => currentValue < 40;
let
result
=
new
Float64Array
([
-
10
,
-
20
,
-
30
,
-
40
,
-
50
]).
every
((
value
:
number
,
index
:
number
,
array
:
Float64Array
):
boolean
=>
value
<
0
);
//
expect
(
result
).
toEqual
(
true
);
}
testFill
()
{
let
float32
=
new
Float64Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Float64Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Float64Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Float64Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Float64Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Float64Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Float64Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Float64Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Float64Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Float64Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Float64Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Float64Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Float64Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Float64Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Float64Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
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
);
}
includes
()
{
let
float32
=
new
Float64Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Float64Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Float64Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
//todo 有差异 js 是keys.next().value
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
);
}
map
()
{
let
numbers
=
new
Float64Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Float64Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Float64Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float64Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Float64Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float64Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Float64Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float64Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Float64Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Float64Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Float64Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Float64Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Float64Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
32
);
let
float32
=
new
Float64Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
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
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Float64Array
(
buffer
);
float32
[
1
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,42
"
);
let
res
=
buffer
.
slice
(
8
);
let
sliced
=
new
Float64Array
(
res
);
expect
(
sliced
[
0
]).
toEqual
(
42
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TInt16Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TInt16Array
{
test
()
{
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int16Array
(
buffer
);
float32
[
5
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,0,0,42,0,0
"
);
}
testSet
()
{
let
float32
=
new
Int16Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Int16Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
console
.
log
(
"
testCopyWith 1
"
)
float32
.
copyWithin
(
3
,
0
,
3
);
console
.
log
(
"
testCopyWith 1
"
)
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Int16Array): boolean => currentValue < 40;
let
result
=
new
Int16Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Int16Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Int16Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Int16Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Int16Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Int16Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Int16Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Int16Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Int16Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Int16Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Int16Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Int16Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Int16Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Int16Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Int16Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Int16Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Int16Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Int16Array
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
}
includes
()
{
let
float32
=
new
Int16Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Int16Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Int16Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
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
);
}
map
()
{
let
numbers
=
new
Int16Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Int16Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Int16Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int16Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Int16Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int16Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Int16Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int16Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Int16Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int16Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Int16Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Int16Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Int16Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int16Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0,0,0,0,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Int16Array
([
1
,
2
,
3
]);
let
values
=
arr
.
values
();
expect
(
values
.
next
().
value
).
toEqual
(
1
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int16Array
(
buffer
);
float32
[
4
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,0,42,0,0,0
"
);
let
res
=
buffer
.
slice
(
8
,
12
);
let
sliced
=
new
Int16Array
(
res
);
expect
(
sliced
[
0
]).
toEqual
(
42
);
}
}
uni_modules/uts-tests/utssdk/TInt32Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TInt32Array
{
test
()
{
this
.
testfloat32
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testfloat32
()
{
let
float32
=
new
Int32Array
(
2
);
float32
[
0
]
=
42
;
expect
(
float32
[
0
]).
toEqual
(
42
);
expect
(
float32
.
length
).
toEqual
(
2
);
expect
(
Int32Array
.
BYTES_PER_ELEMENT
).
toEqual
(
4
);
let
x
=
new
Int32Array
([
21
,
31
,
3
]);
expect
(
x
[
1
]).
toEqual
(
31
);
let
y
=
new
Int32Array
(
x
);
expect
(
y
[
0
]).
toEqual
(
21
);
let
buffer
=
new
ArrayBuffer
(
16
);
let
z
=
new
Int32Array
(
buffer
,
2
,
4
);
expect
(
z
.
byteOffset
).
toEqual
(
2
);
expect
(
z
.
length
).
toEqual
(
4
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int32Array
(
buffer
);
float32
[
1
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,42,0,0
"
);
}
testSet
()
{
let
float32
=
new
Int32Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Int32Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
console
.
log
(
"
testCopyWith 1
"
)
float32
.
copyWithin
(
3
,
0
,
3
);
console
.
log
(
"
testCopyWith 1
"
)
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Int32Array): boolean => currentValue < 40;
let
result
=
new
Int32Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Int32Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Int32Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Int32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Int32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Int32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Int32Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Int32Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Int32Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Int32Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Int32Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Int32Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Int32Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Int32Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Int32Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Int32Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Int32Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Int32Array
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
}
includes
()
{
let
float32
=
new
Int32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Int32Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Int32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
let
arr
=
new
Int32Array
([
10
,
20
,
30
,
40
,
50
]);
let
keys
=
arr
.
keys
();
expect
(
keys
.
next
().
value
).
toEqual
(
0
);
}
map
()
{
let
numbers
=
new
Int32Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Int32Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Int32Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int32Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6
);
total
=
new
Int32Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int32Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14
);
}
reduceRight
()
{
let
total
=
new
Int32Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int32Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6
);
total
=
new
Int32Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int32Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14
);
}
reverse
()
{
let
float32
=
new
Int32Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Int32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Int32Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int32Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Int32Array
([
1
,
2
,
3
]);
let
values
=
arr
.
values
();
expect
(
values
.
next
().
value
).
toEqual
(
1
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int32Array
(
buffer
);
float32
[
3
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,42
"
);
let
res
=
buffer
.
slice
(
8
);
let
sliced
=
new
Int32Array
(
res
);
expect
(
sliced
[
1
]).
toEqual
(
42
);
}
}
uni_modules/uts-tests/utssdk/TInt8Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TInt8Array
{
test
()
{
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
int8View
=
new
Int8Array
(
buffer
);
int8View
[
5
]
=
42
;
expect
(
int8View
.
toString
()).
toEqual
(
"
0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0
"
);
}
testSet
()
{
let
float32
=
new
Int8Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Int8Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
console
.
log
(
"
testCopyWith 1
"
)
float32
.
copyWithin
(
3
,
0
,
3
);
console
.
log
(
"
testCopyWith 1
"
)
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Int8Array): boolean => currentValue < 40;
let
result
=
new
Int8Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Int8Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Int8Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Int8Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Int8Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Int8Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Int8Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Int8Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Int8Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Int8Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Int8Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Int8Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Int8Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Int8Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Int8Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Int8Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Int8Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
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
);
}
includes
()
{
let
float32
=
new
Int8Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Int8Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Int8Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
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
);
}
map
()
{
let
numbers
=
new
Int8Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Int8Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Int8Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int8Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Int8Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int8Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Int8Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int8Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Int8Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Int8Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Int8Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Int8Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Int8Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
8
);
let
float32
=
new
Int8Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0,0,0,0,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
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
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Int8Array
(
buffer
);
float32
[
4
]
=
42
;
expect
(
float32
.
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
sliced
=
new
Int8Array
(
res
);
expect
(
sliced
[
0
]).
toEqual
(
42
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUInt8Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TUint8Array
{
test
()
{
this
.
testMAX
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testMAX
()
{
let
float32
=
new
Uint8Array
(
16
);
float32
[
0
]
=
255
;
expect
(
float32
[
0
]).
toEqual
(
255
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint8Array
(
buffer
);
float32
[
5
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0
"
);
}
testSet
()
{
let
float32
=
new
Uint8Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Uint8Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
float32
.
copyWithin
(
3
,
0
,
3
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8Array): boolean => currentValue < 40;
let
result
=
new
Uint8Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Uint8Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Uint8Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Uint8Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Uint8Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Uint8Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Uint8Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Uint8Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Uint8Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Uint8Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Uint8Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Uint8Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint8Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Uint8Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint8Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Uint8Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Uint8Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Uint8Array
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
}
includes
()
{
let
float32
=
new
Uint8Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2.0
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4.0
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3.0
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Uint8Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Uint8Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
let
arr
=
new
Uint8Array
([
10
,
20
,
30
,
40
,
50
]);
let
keys
=
arr
.
keys
();
expect
(
keys
.
next
().
value
).
toEqual
(
0
);
}
map
()
{
let
numbers
=
new
Uint8Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Uint8Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Uint8Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Uint8Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Uint8Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Uint8Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Uint8Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Uint8Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Uint8Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint8Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Uint8Array
([
1
,
2
,
3
]);
let
values
=
arr
.
values
();
expect
(
values
.
next
().
value
).
toEqual
(
1
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint8Array
(
buffer
);
float32
[
4
]
=
42
;
expect
(
float32
.
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
sliced
=
new
Uint8Array
(
res
);
expect
(
sliced
[
0
]).
toEqual
(
42
);
}
}
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TUint8ClampedArray
{
test
()
{
this
.
testMAX
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testMAX
()
{
let
float32
=
new
Uint8ClampedArray
(
16
);
float32
[
0
]
=
255
;
expect
(
float32
[
0
]).
toEqual
(
255
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint8ClampedArray
(
buffer
);
float32
[
5
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,0,0,42,0,0,0,0,0,0,0,0,0,0
"
);
}
testSet
()
{
let
float32
=
new
Uint8ClampedArray
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Uint8ClampedArray
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
float32
.
copyWithin
(
3
,
0
,
3
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Uint8ClampedArray): boolean => currentValue < 40;
let
result
=
new
Uint8ClampedArray
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Uint8ClampedArray
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Uint8ClampedArray
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Uint8ClampedArray
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Uint8ClampedArray
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Uint8ClampedArray
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Uint8ClampedArray
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint8ClampedArray
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Uint8ClampedArray
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint8ClampedArray
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Uint8ClampedArray
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Uint8ClampedArray
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Uint8ClampedArray
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
}
includes
()
{
let
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2.0
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4.0
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3.0
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Uint8ClampedArray
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
let
arr
=
new
Uint8ClampedArray
([
10
,
20
,
30
,
40
,
50
]);
let
keys
=
arr
.
keys
();
expect
(
keys
.
next
().
value
).
toEqual
(
0
);
}
map
()
{
let
numbers
=
new
Uint8ClampedArray
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Uint8ClampedArray
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Uint8ClampedArray
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8ClampedArray
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Uint8ClampedArray
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8ClampedArray
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Uint8ClampedArray
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8ClampedArray
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Uint8ClampedArray
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint8ClampedArray
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Uint8ClampedArray
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Uint8ClampedArray
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint8ClampedArray
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Uint8ClampedArray
([
1
,
2
,
3
]);
let
values
=
arr
.
values
();
expect
(
values
.
next
().
value
).
toEqual
(
1
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint8ClampedArray
(
buffer
);
float32
[
4
]
=
42
;
expect
(
float32
.
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
sliced
=
new
Uint8ClampedArray
(
res
);
expect
(
sliced
[
0
]).
toEqual
(
42
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUint16Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TUint16Array
{
test
()
{
this
.
testfloat32
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testfloat32
()
{
let
float32
=
new
Uint16Array
(
2
);
float32
[
0
]
=
42
;
expect
(
float32
[
0
]).
toEqual
(
42
);
expect
(
float32
.
length
).
toEqual
(
2
);
expect
(
Uint16Array
.
BYTES_PER_ELEMENT
).
toEqual
(
4
);
let
x
=
new
Uint16Array
([
21
,
31
,
3
]);
expect
(
x
[
1
]).
toEqual
(
31
);
let
y
=
new
Uint16Array
(
x
);
expect
(
y
[
0
]).
toEqual
(
21
);
let
buffer
=
new
ArrayBuffer
(
16
);
let
z
=
new
Uint16Array
(
buffer
,
2
,
4
);
expect
(
z
.
byteOffset
).
toEqual
(
2
);
expect
(
z
.
length
).
toEqual
(
4
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint16Array
(
buffer
);
float32
[
1
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,42,0,0,0,0,0,0
"
);
}
testSet
()
{
let
float32
=
new
Uint16Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Uint16Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
console
.
log
(
"
testCopyWith 1
"
)
float32
.
copyWithin
(
3
,
0
,
3
);
console
.
log
(
"
testCopyWith 1
"
)
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Uint16Array): boolean => currentValue < 40;
let
result
=
new
Uint16Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Uint16Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Uint16Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Uint16Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Uint16Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Uint16Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Uint16Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Uint16Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Uint16Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Uint16Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Uint16Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Uint16Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint16Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Uint16Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint16Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Uint16Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Uint16Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Uint16Array
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
}
includes
()
{
let
float32
=
new
Uint16Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2.0
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4.0
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3.0
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Uint16Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Uint16Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
let
arr
=
new
Uint16Array
([
10
,
20
,
30
,
40
,
50
]);
let
keys
=
arr
.
keys
();
expect
(
keys
.
next
().
value
).
toEqual
(
0
);
}
map
()
{
let
numbers
=
new
Uint16Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Uint16Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Uint16Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint16Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Uint16Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint16Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reduceRight
()
{
let
total
=
new
Uint16Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint16Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6.0
);
total
=
new
Uint16Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint16Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14.0
);
}
reverse
()
{
let
float32
=
new
Uint16Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Uint16Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Uint16Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint16Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0,0,0,0,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Uint16Array
([
1
,
2
,
3
]);
let
values
=
arr
.
values
();
expect
(
values
.
next
().
value
).
toEqual
(
1
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint16Array
(
buffer
);
float32
[
3
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,42,0,0,0,0
"
);
let
res
=
buffer
.
slice
(
8
);
let
sliced
=
new
Uint16Array
(
res
);
expect
(
sliced
[
0
]).
toEqual
(
42
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/TUint32Array.js
0 → 100644
浏览文件 @
626f78af
import
{
describe
,
test
,
expect
,
Result
}
from
'
./tests.uts
'
export
class
TUint32Array
{
test
()
{
this
.
testfloat32
();
this
.
testConstructor
();
this
.
testSet
();
this
.
testCopyWith
();
this
.
testEvery
();
this
.
testFill
();
this
.
testFilter
();
this
.
find
();
this
.
findIndex
();
this
.
foreach
();
this
.
iterator
();
this
.
includes
();
this
.
indexOf
();
this
.
join
();
this
.
keys
();
this
.
map
();
this
.
reduce
();
this
.
reduceRight
();
this
.
reverse
();
this
.
slice
();
this
.
sort
();
this
.
subarray
();
this
.
values
();
this
.
arrayBufferSlice
();
}
testfloat32
()
{
let
float32
=
new
Uint32Array
(
2
);
float32
[
0
]
=
42
;
expect
(
float32
[
0
]).
toEqual
(
42
);
expect
(
float32
.
length
).
toEqual
(
2
);
expect
(
Uint32Array
.
BYTES_PER_ELEMENT
).
toEqual
(
4
);
let
x
=
new
Uint32Array
([
21
,
31
,
3
]);
expect
(
x
[
1
]).
toEqual
(
31
);
let
y
=
new
Uint32Array
(
x
);
expect
(
y
[
0
]).
toEqual
(
21
);
let
buffer
=
new
ArrayBuffer
(
16
);
let
z
=
new
Uint32Array
(
buffer
,
2
,
4
);
expect
(
z
.
byteOffset
).
toEqual
(
2
);
expect
(
z
.
length
).
toEqual
(
4
);
}
testConstructor
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint32Array
(
buffer
);
float32
[
1
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,42,0,0
"
);
}
testSet
()
{
let
float32
=
new
Uint32Array
(
8
);
var
array
=
[
1
,
2
,
3
]
float32
.
set
(
array
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,3,0,0,0,0
"
);
}
testCopyWith
()
{
console
.
log
(
"
testCopyWith 1
"
)
let
float32
=
new
Uint32Array
(
8
);
float32
.
set
([
1
,
2
,
3
],
1
);
console
.
log
(
"
testCopyWith 1
"
)
float32
.
copyWithin
(
3
,
0
,
3
);
console
.
log
(
"
testCopyWith 1
"
)
expect
(
float32
.
toString
()).
toEqual
(
"
0,1,2,0,1,2,0,0
"
);
}
testEvery
()
{
// const isBelowThreshold = (currentValue: number, index: number, array:Uint32Array): boolean => currentValue < 40;
let
result
=
new
Uint32Array
([
12
,
5
,
8
,
130
,
44
]).
every
((
value
:
number
,
index
:
number
,
array
:
Uint32Array
):
boolean
=>
value
<
40
);
//
expect
(
result
).
toEqual
(
false
);
}
testFill
()
{
let
float32
=
new
Uint32Array
([
1
,
2
,
3
]).
fill
(
4
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,4,4
"
);
float32
=
new
Uint32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,4
"
);
float32
=
new
Uint32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,4,3
"
);
float32
=
new
Uint32Array
([
1
,
2
,
3
]).
fill
(
4
,
1
,
1
);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3
"
);
float32
=
new
Uint32Array
([
1
,
2
,
3
]).
fill
(
4
,
-
3
,
-
2
);
expect
(
float32
.
toString
()).
toEqual
(
"
4,2,3
"
);
}
testFilter
()
{
// const isBelowThreshold = (currentValue: number, index: number, _): boolean => currentValue >= 10;
let
float32
=
new
Uint32Array
([
12
,
5
,
8
,
44
]).
filter
((
value
:
number
,
index
:
number
,
array
:
Uint32Array
):
boolean
=>
value
>=
10
);
expect
(
float32
.
toString
()).
toEqual
(
"
12,44
"
);
}
find
()
{
let
float32
=
new
Uint32Array
([
4
,
5
,
8
,
12
]);
let
res
=
float32
.
find
((
value
:
number
,
index
:
number
,
obj
:
Uint32Array
):
boolean
=>
value
>
5
);
expect
(
res
).
toEqual
(
8
);
}
findIndex
()
{
let
float32
=
new
Uint32Array
([
4
,
6
,
8
,
12
]);
let
res
=
float32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint32Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
-
1
);
let
ufloat32
=
new
Uint32Array
([
4
,
6
,
7
,
120
]);
res
=
ufloat32
.
findIndex
((
value
:
number
,
index
:
number
,
obj
:
Uint32Array
):
boolean
=>
value
>
100
);
expect
(
res
).
toEqual
(
3
);
}
foreach
()
{
new
Uint32Array
([
0
,
1
,
2
,
3
]).
forEach
((
value
:
number
,
index
:
number
,
array
:
Uint32Array
)
=>
{
console
.
log
(
`a[
${
index
}
] =
${
value
}
`
);
});
}
iterator
()
{
let
arr
=
new
Uint32Array
([
10
,
20
,
30
,
40
,
50
]);
let
entries
=
arr
.
entries
();
expect
(
entries
.
next
().
value
[
1
]).
toEqual
(
10
);
}
includes
()
{
let
float32
=
new
Uint32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
includes
(
2
);
expect
(
res
).
toEqual
(
true
);
res
=
float32
.
includes
(
4
);
expect
(
res
).
toEqual
(
false
);
res
=
float32
.
includes
(
3
,
3
);
expect
(
res
).
toEqual
(
false
);
}
indexOf
()
{
let
float32
=
new
Uint32Array
([
2
,
5
,
9
]);
let
res
=
float32
.
indexOf
(
2
);
expect
(
res
).
toEqual
(
0
);
res
=
float32
.
indexOf
(
7
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
9
,
2
);
expect
(
res
).
toEqual
(
2
);
res
=
float32
.
indexOf
(
2
,
-
1
);
expect
(
res
).
toEqual
(
-
1
);
res
=
float32
.
indexOf
(
2
,
-
3
);
expect
(
res
).
toEqual
(
0
);
}
join
()
{
let
float32
=
new
Uint32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
join
();
expect
(
res
).
toEqual
(
"
1,2,3
"
);
res
=
float32
.
join
(
"
/
"
);
expect
(
res
).
toEqual
(
"
1 / 2 / 3
"
);
res
=
float32
.
join
(
""
);
expect
(
res
).
toEqual
(
"
123
"
);
}
keys
()
{
let
arr
=
new
Uint32Array
([
10
,
20
,
30
,
40
,
50
]);
let
keys
=
arr
.
keys
();
expect
(
keys
.
next
().
value
).
toEqual
(
0
);
}
map
()
{
let
numbers
=
new
Uint32Array
([
1
,
4
,
9
]);
let
doubles
=
numbers
.
map
((
value
:
number
,
index
:
number
,
array
:
Uint32Array
):
number
=>
value
*
2
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,4,9
"
);
expect
(
doubles
.
toString
()).
toEqual
(
"
2,8,18
"
);
}
reduce
()
{
let
total
=
new
Uint32Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint32Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6
);
total
=
new
Uint32Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduce
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint32Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14
);
}
reduceRight
()
{
let
total
=
new
Uint32Array
([
0
,
1
,
2
,
3
]);
let
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint32Array
):
number
=>
accumulator
+
currentValue
);
expect
(
res
).
toEqual
(
6
);
total
=
new
Uint32Array
([
0
,
1
,
2
,
3
]);
res
=
total
.
reduceRight
((
accumulator
:
number
,
currentValue
:
number
,
currentIndex
:
number
,
array
:
Uint32Array
):
number
=>
accumulator
+
currentValue
,
8
);
expect
(
res
).
toEqual
(
14
);
}
reverse
()
{
let
float32
=
new
Uint32Array
([
1
,
2
,
3
]);
float32
.
reverse
();
expect
(
float32
.
toString
()).
toEqual
(
"
3,2,1
"
);
}
slice
()
{
let
float32
=
new
Uint32Array
([
1
,
2
,
3
]);
let
res
=
float32
.
slice
(
1
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
2
);
expect
(
res
.
toString
()).
toEqual
(
"
3
"
);
res
=
float32
.
slice
(
-
2
);
expect
(
res
.
toString
()).
toEqual
(
"
2,3
"
);
res
=
float32
.
slice
(
0
,
1
);
expect
(
res
.
toString
()).
toEqual
(
"
1
"
);
}
sort
()
{
let
numbers
=
new
Uint32Array
([
40
,
1
,
5
]);
numbers
.
sort
();
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
numbers
.
sort
((
a
,
b
):
Number
=>
a
-
b
);
expect
(
numbers
.
toString
()).
toEqual
(
"
1,5,40
"
);
}
subarray
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint32Array
(
buffer
);
float32
.
set
([
1
,
2
,
3
]);
expect
(
float32
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
let
sub
=
float32
.
subarray
(
0
,
4
);
expect
(
sub
.
toString
()).
toEqual
(
"
1,2,3,0
"
);
}
values
()
{
let
arr
=
new
Uint32Array
([
1
,
2
,
3
]);
let
values
=
arr
.
values
();
expect
(
values
.
next
().
value
).
toEqual
(
1
);
}
arrayBufferSlice
()
{
let
buffer
=
new
ArrayBuffer
(
16
);
let
float32
=
new
Uint32Array
(
buffer
);
float32
[
3
]
=
42
;
expect
(
float32
.
toString
()).
toEqual
(
"
0,0,0,42
"
);
let
res
=
buffer
.
slice
(
8
);
let
sliced
=
new
Uint32Array
(
res
);
expect
(
sliced
[
1
]).
toEqual
(
42
);
}
}
\ No newline at end of file
uni_modules/uts-tests/utssdk/index.uts
浏览文件 @
626f78af
...
...
@@ -16,7 +16,9 @@ import { testRegExp } from './RegExp.uts'
import { testForLoop } from './ForLoop.uts'
import { testGlobal } from './Global.uts'
import { testType } from './Type.uts'
export { Result } from './tests.uts'
export { Result } from './tests.uts'
import { testArrayBuffer } from './ArrayBuffer.uts'
// Promise、Proxy、Reflect、Weakmap、WeakSet 不支持
export function runTests() : UTSJSONObject {
...
...
@@ -37,7 +39,8 @@ export function runTests() : UTSJSONObject {
const TypeRes = testType();
const JSONLargeRes = testJSONLarge();
const consoleRes = testConsole();
const UTSJSONObjectRes = testUTSJSONObject();
const UTSJSONObjectRes = testUTSJSONObject();
const ArrayBufferRes = testArrayBuffer();
return {
Array: ArrayRes,
Date: DateRes,
...
...
@@ -56,6 +59,7 @@ export function runTests() : UTSJSONObject {
Global: GlobalRes,
Type: TypeRes,
console:consoleRes,
UTSJSONObject:UTSJSONObjectRes
UTSJSONObject:UTSJSONObjectRes,
ArrayBuffer:ArrayBufferRes
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录