Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
eb5fba03
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
eb5fba03
编写于
7月 15, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "[array-buffer]添加slice测试"
This reverts commit
68ed013c
.
上级
4908c461
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
41 addition
and
71 deletion
+41
-71
uni_modules/uts-tests/utssdk/TDataView.uts
uni_modules/uts-tests/utssdk/TDataView.uts
+37
-52
uni_modules/uts-tests/utssdk/TFloat64Array.uts
uni_modules/uts-tests/utssdk/TFloat64Array.uts
+1
-3
uni_modules/uts-tests/utssdk/TInt16Array.uts
uni_modules/uts-tests/utssdk/TInt16Array.uts
+0
-2
uni_modules/uts-tests/utssdk/TInt32Array.uts
uni_modules/uts-tests/utssdk/TInt32Array.uts
+0
-2
uni_modules/uts-tests/utssdk/TInt8Array.uts
uni_modules/uts-tests/utssdk/TInt8Array.uts
+1
-3
uni_modules/uts-tests/utssdk/TUInt8Array.uts
uni_modules/uts-tests/utssdk/TUInt8Array.uts
+1
-3
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
+1
-2
uni_modules/uts-tests/utssdk/TUint16Array.uts
uni_modules/uts-tests/utssdk/TUint16Array.uts
+0
-2
uni_modules/uts-tests/utssdk/TUint32Array.uts
uni_modules/uts-tests/utssdk/TUint32Array.uts
+0
-2
未找到文件。
uni_modules/uts-tests/utssdk/TDataView.uts
浏览文件 @
eb5fba03
...
...
@@ -33,87 +33,72 @@ export class TDataView {
}
setInt8() {
// #TEST DataView.setInt8,DataView.getInt8
// 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);
// #END
}
}
setFloat32() {
// #TEST DataView.setFloat32,DataView.getFloat32
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, 3);
view.setFloat32(1,3);
console.log('setFloat32',view.getFloat32(1))
expect(this.numberEquals(3, view.getFloat32(1))).toEqual(true);
// #END
}
}
setFloat64() {
// #TEST DataView.setFloat64,DataView.getFloat64
// 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);
// #END
}
}
setInt16() {
// #TEST DataView.setInt16,DataView.getInt16
// 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);
// #END
}
}
setInt32() {
// #TEST DataView.setInt32,DataView.getInt32
// 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);
// #END
}
}
setUint16() {
// #TEST DataView.setUint16,DataView.getUint16
// 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);
// #END
}
setUint32() {
// #TEST DataView.setUint32,DataView.getUint32
// 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);
// #END
}
}
setUint8() {
// #TEST DataView.setUint8,DataView.getUint8
// 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);
// #END
}
numberEquals(a : number, b : number) : Boolean {
numberEquals(a: number, b: number): Boolean {
return a == b
}
...
...
@@ -142,7 +127,7 @@ export class TDataView {
this.doFloatIterations(false);
}
doIterations(littleEndian
: boolean, dataView
: boolean) {
doIterations(littleEndian
: boolean, dataView
: boolean) {
var buffer = this.makeBuffer(1000, littleEndian);
var iterations = 10;
if (dataView) {
...
...
@@ -154,7 +139,7 @@ export class TDataView {
}
}
makeBuffer(size
: number, littleEndian : boolean)
: ArrayBuffer {
makeBuffer(size
: number, littleEndian: boolean)
: ArrayBuffer {
var buffer = new ArrayBuffer(1000 * 14);
var view = new DataView(buffer);
for (var i = 0; i < 1000; ++i) {
...
...
@@ -168,7 +153,7 @@ export class TDataView {
return buffer;
}
doOneIterationDV(buffer
: ArrayBuffer, littleEndian
: boolean) {
doOneIterationDV(buffer
: ArrayBuffer, littleEndian
: boolean) {
var xor = 0;
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 14) {
...
...
@@ -182,7 +167,7 @@ export class TDataView {
expect(xor).toEqual(0);
}
doOneIterationJS(buffer
: ArrayBuffer, littleEndian
: boolean) {
doOneIterationJS(buffer
: ArrayBuffer, littleEndian
: boolean) {
var xor = 0;
if (littleEndian) {
var reader = new LittleEndian(buffer);
...
...
@@ -209,7 +194,7 @@ export class TDataView {
}
doFloatIterations(dataView
: boolean) {
doFloatIterations(dataView: boolean) {
var buffer = this.makeFloatBuffer();
var iterations = 10;
if (dataView) {
...
...
@@ -221,7 +206,7 @@ export class TDataView {
}
}
makeFloatBuffer()
: ArrayBuffer {
makeFloatBuffer(): ArrayBuffer {
var buffer = new ArrayBuffer(1000 * 16);
var view = new DataView(buffer);
for (var i = 0; i < 1000; i++) {
...
...
@@ -232,7 +217,7 @@ export class TDataView {
return buffer;
}
doOneFloatIterationDV(buffer
: ArrayBuffer) {
doOneFloatIterationDV(buffer: ArrayBuffer) {
var sum = 0;
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 16) {
...
...
@@ -240,10 +225,10 @@ export class TDataView {
sum += view.getFloat32(i + 8);
sum += view.getFloat32(i + 12);
}
expect(sum).toEqual(23634.413356150446);
expect(sum).toEqual(23634.413356150446);
}
doOneFloatIterationJS(buffer
: ArrayBuffer) {
doOneFloatIterationJS(buffer: ArrayBuffer) {
var sum = 0;
var float32array = new Float32Array(buffer);
var float64array = new Float64Array(buffer);
...
...
@@ -255,32 +240,32 @@ export class TDataView {
}
}
class BigEndian {
private uint8View_
: Uint8Array;
private int8View_
: Int8Array;
private uint8View_: Uint8Array;
private int8View_: Int8Array;
constructor(buffer
: ArrayBuffer,
) {
constructor(buffer
: ArrayBuffer,
) {
const offset = 0;
this.uint8View_ = new Uint8Array(buffer, offset);
this.int8View_ = new Int8Array(buffer, offset);
}
getInt8(byteOffset
: number)
: number {
getInt8(byteOffset
: number)
: number {
return this.int8View_[byteOffset];
}
getUint8(byteOffset
: number)
: number {
getUint8(byteOffset
: number)
: number {
return this.uint8View_[byteOffset];
}
getInt16(byteOffset
: number)
: number {
getInt16(byteOffset
: number)
: number {
return this.uint8View_[byteOffset + 1] | (this.int8View_[byteOffset] << 8);
}
getUint16(byteOffset
: number)
: number {
getUint16(byteOffset
: number)
: number {
return this.uint8View_[byteOffset + 1] | (this.uint8View_[byteOffset] << 8);
}
getInt32(byteOffset
: number)
: number {
getInt32(byteOffset
: number)
: number {
return (
this.uint8View_[byteOffset + 3] |
(this.uint8View_[byteOffset + 2] << 8) |
...
...
@@ -289,7 +274,7 @@ class BigEndian {
);
}
getUint32(byteOffset
: number)
: number {
getUint32(byteOffset
: number)
: number {
return (
this.uint8View_[byteOffset + 3] +
(this.uint8View_[byteOffset + 2] << 8) +
...
...
@@ -300,32 +285,32 @@ class BigEndian {
}
class LittleEndian {
private uint8View_
: Uint8Array;
private int8View_
: Int8Array;
private uint8View_: Uint8Array;
private int8View_: Int8Array;
constructor(buffer
: ArrayBuffer) {
constructor(buffer: ArrayBuffer) {
const offset = 0;
this.uint8View_ = new Uint8Array(buffer, offset);
this.int8View_ = new Int8Array(buffer, offset);
}
getInt8(byteOffset
: number)
: number {
getInt8(byteOffset
: number)
: number {
return this.int8View_[byteOffset];
}
getUint8(byteOffset
: number)
: number {
getUint8(byteOffset
: number)
: number {
return this.uint8View_[byteOffset];
}
getInt16(byteOffset
: number)
: number {
getInt16(byteOffset
: number)
: number {
return this.uint8View_[byteOffset] | (this.int8View_[byteOffset + 1] << 8);
}
getUint16(byteOffset
: number)
: number {
getUint16(byteOffset
: number)
: number {
return this.uint8View_[byteOffset] | (this.uint8View_[byteOffset + 1] << 8);
}
getInt32(byteOffset
: number)
: number {
getInt32(byteOffset
: number)
: number {
return (
this.uint8View_[byteOffset] |
(this.uint8View_[byteOffset + 1] << 8) |
...
...
@@ -334,7 +319,7 @@ class LittleEndian {
);
}
getUint32(byteOffset
: number)
: number {
getUint32(byteOffset
: number)
: number {
return (
this.uint8View_[byteOffset] +
(this.uint8View_[byteOffset + 1] << 8) +
...
...
uni_modules/uts-tests/utssdk/TFloat64Array.uts
浏览文件 @
eb5fba03
...
...
@@ -304,8 +304,7 @@ export class TFloat64Array {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
// #TEST Float64Array with ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let float64 = new Float64Array(buffer);
float64[1] = 42;
...
...
@@ -315,7 +314,6 @@ export class TFloat64Array {
let sliced = new Float64Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
...
...
uni_modules/uts-tests/utssdk/TInt16Array.uts
浏览文件 @
eb5fba03
...
...
@@ -279,7 +279,6 @@ export class TInt16Array {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice with Int16Array
let buffer = new ArrayBuffer(16);
let int16 = new Int16Array(buffer);
...
...
@@ -290,7 +289,6 @@ export class TInt16Array {
let sliced = new Int16Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
...
...
uni_modules/uts-tests/utssdk/TInt32Array.uts
浏览文件 @
eb5fba03
...
...
@@ -298,7 +298,6 @@ export class TInt32Array {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let int32 = new Int32Array(buffer);
...
...
@@ -309,7 +308,6 @@ export class TInt32Array {
let sliced = new Int32Array(res);
expect(sliced[1]).toEqual(42);
// #END
}
// #endif
...
...
uni_modules/uts-tests/utssdk/TInt8Array.uts
浏览文件 @
eb5fba03
...
...
@@ -294,8 +294,7 @@ export class TInt8Array {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
// #TEST ArrayBuffer.slice with Int8Array
let buffer = new ArrayBuffer(16);
let int8 = new Int8Array(buffer);
int8[4] = 42;
...
...
@@ -305,7 +304,6 @@ export class TInt8Array {
let sliced = new Int8Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
...
...
uni_modules/uts-tests/utssdk/TUInt8Array.uts
浏览文件 @
eb5fba03
...
...
@@ -293,8 +293,7 @@ export class TUint8Array {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
// #TEST ArrayBuffer.slice with Uint8Array
let buffer = new ArrayBuffer(16);
let uint8 = new Uint8Array(buffer);
uint8[4] = 42;
...
...
@@ -304,7 +303,6 @@ export class TUint8Array {
let sliced = new Uint8Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
...
...
uni_modules/uts-tests/utssdk/TUInt8ClampedArray.uts
浏览文件 @
eb5fba03
...
...
@@ -291,8 +291,7 @@ export class TUint8ClampedArray {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
// #TEST ArrayBuffer.slice with Uint8ClampedArray
let buffer = new ArrayBuffer(16);
let uint8Clamped = new Uint8ClampedArray(buffer);
uint8Clamped[4] = 42;
...
...
uni_modules/uts-tests/utssdk/TUint16Array.uts
浏览文件 @
eb5fba03
...
...
@@ -305,7 +305,6 @@ export class TUint16Array {
}
arrayBufferSlice() {
// #TEST Uint16Array.arrayBufferSlice
let buffer = new ArrayBuffer(16);
let uint16 = new Uint16Array(buffer);
...
...
@@ -316,7 +315,6 @@ export class TUint16Array {
let sliced = new Uint16Array(res);
expect(sliced[0]).toEqual(42);
// #END
}
// #endif
...
...
uni_modules/uts-tests/utssdk/TUint32Array.uts
浏览文件 @
eb5fba03
...
...
@@ -299,7 +299,6 @@ export class TUint32Array {
}
arrayBufferSlice() {
// #TEST ArrayBuffer.slice
let buffer = new ArrayBuffer(16);
let uint32 = new Uint32Array(buffer);
...
...
@@ -310,7 +309,6 @@ export class TUint32Array {
let sliced = new Uint32Array(res);
expect(sliced[1]).toEqual(42);
// #END
}
// #endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录