Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
48557981
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看板
提交
48557981
编写于
9月 04, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[array]去除手动生成的代码(修改测试失败)
上级
0aa2d9da
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
86 addition
and
24 deletion
+86
-24
uni_modules/uts-tests/utssdk/Array.uts
uni_modules/uts-tests/utssdk/Array.uts
+86
-24
未找到文件。
uni_modules/uts-tests/utssdk/Array.uts
浏览文件 @
48557981
...
...
@@ -115,18 +115,12 @@ export function testArray() : Result {
const arr = ['a', 'b', 'c', 'd', 'e'];
let ret1 = arr.copyWithin(0, 3, 4)
console.log(ret1)//["d", "b", "c", "d", "e"]
let ret2 = arr.copyWithin(1, 3)
console.log(ret2)//["d", "d", "e", "d", "e"]
const arr2 = [1, 2, 3, 4, 5];
let ret3 = arr2.copyWithin(-2)
console.log(ret3) //[1, 2, 3, 1, 2]
let ret4 = arr2.copyWithin(-2, -3, -1)
console.log(ret4) //[1, 2, 3, 3, 1]
// #END
expect(ret1).toEqual(["d", "b", "c", "d", "e"]);
expect(ret2).toEqual(["d", "d", "e", "d", "e"]);
expect(ret3).toEqual([1, 2, 3, 1, 2]);
expect(ret4).toEqual([1, 2, 3, 3, 1]);
expect(arr.copyWithin(1, 3)).toEqual(["d", "d", "e", "d", "e"]);
const arr2 = [1, 2, 3, 4, 5];
expect(arr2.copyWithin(-2)).toEqual([1, 2, 3, 1, 2]);
expect(arr2.copyWithin(-2, -3, -1)).toEqual([1, 2, 3, 3, 1]);
})
test("every", () => {
// #TEST Array.every,Array.every_1,Array.every_2,Array.every_3
...
...
@@ -152,21 +146,16 @@ export function testArray() : Result {
expect(array2.every(isBelowThreshold)).toEqual(false);
})
test("fill", () => {
// #TEST Array.fill
const array1 : number[] = [1, 2, 3, 4];
console.log(array1.fill(0, 2, 4)); //[1, 2, 0, 0]
console.log(array1.fill(5, 1)); //[1, 5, 5, 5]
console.log(array1.fill(6)); //[6, 6, 6, 6]
const array2 : number[] = [1, 2, 3];
console.log(array2.fill(4))//[4, 4, 4]
const array3 : number[] = [0, 0]
console.log(array3.fill(1, null))//[1, 1]
console.log(array3.fill(1, 0, 1.5))//([1, 1]);
let ret1 = array1.fill(0, 2, 4)
console.log(ret1); //[1, 2, 0, 0]
// #END
expect(
array1.fill(0, 2, 4)
).toEqual([1, 2, 0, 0]);
expect(
ret1
).toEqual([1, 2, 0, 0]);
expect(array1.fill(5, 1)).toEqual([1, 5, 5, 5]);
expect(array1.fill(6)).toEqual([6, 6, 6, 6]);
const array2 : number[] = [1, 2, 3]
expect(array2.fill(4)).toEqual([4, 4, 4]);
const array3 : number[] = [0, 0]
expect(array3.fill(1, null)).toEqual([1, 1]);
expect(array3.fill(1, 0, 1.5)).toEqual([1, 1]);
})
...
...
@@ -556,14 +545,14 @@ export function testArray() : Result {
test("unshift", () => {
// #TEST Array.unshift
const array1 = [1, 2, 3];
console.log(
array1.unshift(4, 5)
);
let ret1 =array1.unshift(4, 5)
console.log(
ret1
);
// 5
console.log(array1);
// [4, 5, 1, 2, 3]
// #END
expect(
array1.unshift(4, 5)
).toEqual(5);
expect(
ret1
).toEqual(5);
expect(array1).toEqual([4, 5, 1, 2, 3]);
})
test("toString", () => {
...
...
@@ -672,11 +661,84 @@ export function testArray() : Result {
// #END
})
//示例
test("sample
_create
", () => {
test("sample", () => {
// #TEST Array.sampleCreate
const fruits = ['Apple', 'Banana']
console.log(fruits.length)
// #END
// #TEST Array.sampleVisit
const first = fruits[0]
console.log(first) // Apple
const last = fruits[fruits.length - 1]
console.log(last) // Banana
// #END
// #TEST Array.sampleForEach
fruits.forEach(function (item, index, array) {
console.log(item, index)
})
// Apple 0
// Banana 1
// #END
// #TEST Array.sampleAdd
let newLength = fruits.push('Orange')
// ["Apple", "Banana", "Orange"]
console.log(newLength)//3
// #END
// #TEST Array.samplePop
const lastE = fruits.pop() // remove Orange (from the end)
// ["Apple", "Banana"]
console.log(lastE)
// #END
// #TEST Array.sampleShift
const firstE = fruits.shift() // remove Apple from the front
console.log(firstE) // ["Banana"]
// #END
// #TEST Array.sampleUnshift
newLength = fruits.unshift('Strawberry') // add to the front
console.log(newLength) // 2
// ["Strawberry", "Banana"]
// #END
// #TEST Array.sampleIndexOf
fruits.push('Mango')
// ["Strawberry", "Banana", "Mango"]
let pos = fruits.indexOf('Banana')
// 1
// #END
// #TEST Array.sampleSplice
const removedItem = fruits.splice(pos, 1) // this is how to remove an item
console.log(removedItem) // ["Banana"]
// #END
// #TEST Array.sampleSpliceMul
const vegetables = ['Cabbage', 'Turnip', 'Radish', 'Carrot']
console.log(vegetables)
// ["Cabbage", "Turnip", "Radish", "Carrot"]
pos = 1
const n = 2
const removedItems = vegetables.splice(pos, n)
// this is how to remove items, n defines the number of items to be removed,
// starting at the index position specified by pos and progressing toward the end of array.
console.log(vegetables)
// ["Cabbage", "Carrot"] (the original array is changed)
console.log(removedItems)
// ["Turnip", "Radish"]
// #END
// #TEST Array.sampleSpliceCopy
const shallowCopy = fruits.slice() // this is how to make a copy
console.log(shallowCopy) // ["Strawberry", "Mango"]
// #END
})
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录