提交 252d554d 编写于 作者: 杜庆泉's avatar 杜庆泉

增加部分示例

上级 f5d010e2
...@@ -444,6 +444,8 @@ export function logFloatTest() { ...@@ -444,6 +444,8 @@ export function logFloatTest() {
} }
export function logIntTest() { export function logIntTest() {
console.log(2023) console.log(2023)
console.log(2023.0)
console.log(2023.002)
} }
export function logObjectTest(){ export function logObjectTest(){
......
...@@ -176,6 +176,10 @@ export function testArray(): Result { ...@@ -176,6 +176,10 @@ export function testArray(): Result {
expect(index).toEqual(3); expect(index).toEqual(3);
index = array.lastIndexOf(2, 2); index = array.lastIndexOf(2, 2);
expect(index).toEqual(0); expect(index).toEqual(0);
}) })
test("map", () => { test("map", () => {
const array1: number[] = [1, 4, 9, 16]; const array1: number[] = [1, 4, 9, 16];
......
...@@ -2,6 +2,7 @@ import { describe, test, expect, Result } from './tests.uts' ...@@ -2,6 +2,7 @@ import { describe, test, expect, Result } from './tests.uts'
export function testNumber(): Result { export function testNumber(): Result {
return describe("Number", () => { return describe("Number", () => {
test('toFixed', () => { test('toFixed', () => {
function financial(x: Number): String { function financial(x: Number): String {
return x.toFixed(2); return x.toFixed(2);
...@@ -10,6 +11,16 @@ export function testNumber(): Result { ...@@ -10,6 +11,16 @@ export function testNumber(): Result {
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");
expect(financial(1)).toEqual("1.00"); expect(financial(1)).toEqual("1.00");
let num1: number = -1.1 / 0
let num2: number = -1.1 / 0.1
let num3: number = -1.1 / -0.1
console.warn(num1)
console.warn(num2)
console.warn(num3)
let obj = {"id":"3be2c600-894c-4231-aa56-82fd989cc961","result":{"result":[num1, num2, num3]}}
console.log(JSON.stringify(obj))
}) })
test('parseInt', () => { test('parseInt', () => {
...@@ -51,5 +62,12 @@ export function testNumber(): Result { ...@@ -51,5 +62,12 @@ export function testNumber(): Result {
expect((0xf).valueOf()).toEqual(15); expect((0xf).valueOf()).toEqual(15);
}) })
// 数据转换操作示例
test('toX', () => {
let num = 10.123
expect(num.toInt()).toEqual(10);
expect(num.toDouble()).toEqual(10.123);
})
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册