Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
01874ff1
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1598
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
01874ff1
编写于
9月 04, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[number]去除手动生成的代码(添加示例代码)
上级
0b467edf
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
95 addition
and
30 deletion
+95
-30
uni_modules/uts-tests/utssdk/Number.uts
uni_modules/uts-tests/utssdk/Number.uts
+95
-30
未找到文件。
uni_modules/uts-tests/utssdk/Number.uts
浏览文件 @
01874ff1
...
@@ -5,9 +5,16 @@ export function testNumber() : Result {
...
@@ -5,9 +5,16 @@ export function testNumber() : Result {
return describe("Number", () => {
return describe("Number", () => {
test('toFixed', () => {
test('toFixed', () => {
// #TEST Number.toFixed
function financial(x : Number) : String {
function financial(x : Number) : String {
return x.toFixed(2);
return x.toFixed(2);
}
}
console.log(financial(123.456));
// expected output: "123.46"
console.log(financial(0.004));
// expected output: "0.00"
// #END
expect(financial(123.456)).toEqual('123.46');
expect(financial(123.456)).toEqual('123.46');
expect(financial(0.004)).toEqual("0.00");
expect(financial(0.004)).toEqual("0.00");
expect(financial(0)).toEqual("0.00");
expect(financial(0)).toEqual("0.00");
...
@@ -74,7 +81,7 @@ export function testNumber() : Result {
...
@@ -74,7 +81,7 @@ export function testNumber() : Result {
test('number-from-json-parse', () => {
test('number-from-json-parse', () => {
type A = {
type A = {
a:
number
a :
number
}
}
let aj = JSON.parse<A>('{"a":1}');
let aj = JSON.parse<A>('{"a":1}');
expect(aj?.a == 1).toEqual(true);
expect(aj?.a == 1).toEqual(true);
...
@@ -82,13 +89,13 @@ export function testNumber() : Result {
...
@@ -82,13 +89,13 @@ export function testNumber() : Result {
expect(aj?.a == 1.0).toEqual(true);
expect(aj?.a == 1.0).toEqual(true);
expect(aj?.a == 1.0 as number).toEqual(true);
expect(aj?.a == 1.0 as number).toEqual(true);
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
expect(numberEquals(aj?.a,1)).toEqual(true);
expect(numberEquals(aj?.a,
1)).toEqual(true);
expect(numberEquals(aj?.a,1 as number)).toEqual(true);
expect(numberEquals(aj?.a,
1 as number)).toEqual(true);
expect(numberEquals(aj?.a,1.0)).toEqual(true);
expect(numberEquals(aj?.a,
1.0)).toEqual(true);
expect(numberEquals(aj?.a,1.0 as number)).toEqual(true);
expect(numberEquals(aj?.a,
1.0 as number)).toEqual(true);
let ki
:
Int = 1;
let ki
:
Int = 1;
let kd
:
Double = 1.0;
let kd
:
Double = 1.0;
let kf
:Float = (1.0).toFloat();
let kf
: Float = (1.0).toFloat();
expect(aj?.a == ki).toEqual(true);
expect(aj?.a == ki).toEqual(true);
expect(aj?.a == kd).toEqual(true);
expect(aj?.a == kd).toEqual(true);
expect(aj?.a == kf).toEqual(true);
expect(aj?.a == kf).toEqual(true);
...
@@ -183,12 +190,19 @@ export function testNumber() : Result {
...
@@ -183,12 +190,19 @@ export function testNumber() : Result {
})
})
test('toPrecision', () => {
test('toPrecision', () => {
// #TEST Number.toPrecision
console.log(123.456.toPrecision(4))//123.5
// #END
expect(123.456.toPrecision(4)).toEqual("123.5");
expect(123.456.toPrecision(4)).toEqual("123.5");
expect(0.004.toPrecision(4)).toEqual("0.004000");
expect(0.004.toPrecision(4)).toEqual("0.004000");
// expect(1.23e5.toPrecision(4)).toEqual("1.230e+5");
// expect(1.23e5.toPrecision(4)).toEqual("1.230e+5");
})
})
test('toString', () => {
test('toString', () => {
// #TEST Number.toString
console.log((10).toString())//10
// #END
expect((10).toString()).toEqual("10");
expect((10).toString()).toEqual("10");
expect((17).toString()).toEqual("17");
expect((17).toString()).toEqual("17");
expect((17.2).toString()).toEqual("17.2");
expect((17.2).toString()).toEqual("17.2");
...
@@ -201,12 +215,12 @@ export function testNumber() : Result {
...
@@ -201,12 +215,12 @@ export function testNumber() : Result {
expect((-0xff).toString(2)).toEqual("-11111111");
expect((-0xff).toString(2)).toEqual("-11111111");
const a = 1e38
const a = 1e38
expect(a.toString(16).substring(0,12)).toEqual("4b3b4ca85a86");
expect(a.toString(16).substring(0,
12)).toEqual("4b3b4ca85a86");
expect(a.toString(16).length).toEqual(32);
expect(a.toString(16).length).toEqual(32);
expect(a.toString(16).substring(23)).toEqual("000000000");
expect(a.toString(16).substring(23)).toEqual("000000000");
expect(a.toString(2).length).toEqual(127);
expect(a.toString(2).length).toEqual(127);
expect(a.toString(2).substring(0,32)).toEqual("10010110011101101001100101010000");
expect(a.toString(2).substring(0,
32)).toEqual("10010110011101101001100101010000");
expect(a.toString(2).substring(100)).toEqual("000000000000000000000000000");
expect(a.toString(2).substring(100)).toEqual("000000000000000000000000000");
const b = 1e22
const b = 1e22
const bStr12 = b.toString(12)
const bStr12 = b.toString(12)
...
@@ -215,7 +229,7 @@ export function testNumber() : Result {
...
@@ -215,7 +229,7 @@ export function testNumber() : Result {
* 浏览器端:27373a86ba1a195400000
* 浏览器端:27373a86ba1a195400000
*/
*/
expect(bStr12.length).toEqual(21);
expect(bStr12.length).toEqual(21);
expect(bStr12.substring(0,14)).toEqual("27373a86ba1a19");
expect(bStr12.substring(0,
14)).toEqual("27373a86ba1a19");
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
expect((new UTSNumber(2709954670497349.5)).toString()).toEqual("2709954670497349.5");
expect((new UTSNumber(2709954670497349.5)).toString()).toEqual("2709954670497349.5");
...
@@ -228,6 +242,9 @@ export function testNumber() : Result {
...
@@ -228,6 +242,9 @@ export function testNumber() : Result {
})
})
test('valueOf', () => {
test('valueOf', () => {
// #TEST Number.valueOf
console.log((10).valueOf()) //10
// #END
expect((10).valueOf()).toEqual(10);
expect((10).valueOf()).toEqual(10);
expect((-10.2).valueOf()).toEqual(-10.2);
expect((-10.2).valueOf()).toEqual(-10.2);
expect((0xf).valueOf()).toEqual(15);
expect((0xf).valueOf()).toEqual(15);
...
@@ -241,6 +258,54 @@ export function testNumber() : Result {
...
@@ -241,6 +258,54 @@ export function testNumber() : Result {
expect(num.toDouble()).toEqual(10.123);
expect(num.toDouble()).toEqual(10.123);
})
})
// #endif
// #endif
test('toInt', () => {
// #ifdef APP
// #TEST Number.toInt
let a = 12
console.log(a.toInt());
// expected output: 12
// Int最大值2147483647,溢出了
let b = 2147483648
// expected output: -2147483648
// #END
expect(a.toInt()).toEqual(12);
// #endif
})
test('toByte', () => {
// #ifdef APP
// #TEST Number.toByte
let a = 12
console.log(a.toByte());
// expected output: 12
// #END
expect(a.toInt()).toEqual(12);
// #endif
})
test('toLong', () => {
// #ifdef APP
// #TEST Number.toLong
let a = 12
console.log(a.toLong());
// expected output: 12
// #END
expect(a.toLong()).toEqual(12);
// #endif
})
test('from', () => {
// #ifdef APP
// #TEST Number.from
let a = 12
let b = Number.from(a)
console.log(b);
// expected output: 12
// #END
expect(b).toEqual(12);
// #endif
})
test('numberEquals', () => {
test('numberEquals', () => {
let a1 = 10.123
let a1 = 10.123
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录