From affb5de98a2f7a7ba62dec5a4336ea179586b386 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Thu, 19 Oct 2023 16:25:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=A4=BA=E4=BE=8B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E5=AD=97=E5=AF=B9=E6=AF=94=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/Global.uts | 7 +++--- uni_modules/uts-tests/utssdk/Matchers.uts | 6 +++++ uni_modules/uts-tests/utssdk/Operators.uts | 28 +++++++++++----------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/uni_modules/uts-tests/utssdk/Global.uts b/uni_modules/uts-tests/utssdk/Global.uts index 5b7b28e..92e135e 100644 --- a/uni_modules/uts-tests/utssdk/Global.uts +++ b/uni_modules/uts-tests/utssdk/Global.uts @@ -35,8 +35,9 @@ export function testGlobal(): Result { expect(parseInt("9223372036854775807")).toEqual(9.223372036854778e+18) expect(parseInt("9223372036854775807000")).toEqual(9.223372036854777e+21) expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqual(9.223372036854776e+86) - expect(parseInt("50") / 100).toEqual(0.5); - expect(parseInt("500") / 100).toEqual(5); + expect(parseInt("50") / 100).toEqualNumber(0.5); + expect(parseInt("500") / 100).toEqualNumber(5); + }) @@ -47,7 +48,7 @@ export function testGlobal(): Result { expect(parseFloat("314e-2")).toEqual(3.14); expect(parseFloat("0.0314E+2")).toEqual(3.14); expect(parseFloat("3.14some non-digit characters")).toEqual(3.14); - expect(parseFloat("100") / 50).toEqual(2); + expect(parseFloat("100") / 50).toEqualNumber(2); expect(parseFloat("105") / 50).toEqual(2.1); }) diff --git a/uni_modules/uts-tests/utssdk/Matchers.uts b/uni_modules/uts-tests/utssdk/Matchers.uts index 4bb39d1..55597d7 100644 --- a/uni_modules/uts-tests/utssdk/Matchers.uts +++ b/uni_modules/uts-tests/utssdk/Matchers.uts @@ -15,6 +15,12 @@ export class Matchers { NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise() // #endif } + + toEqualNumber(expected: T) { + if (expected == this.actual) { + return + } + } } /** * 数值对比器 diff --git a/uni_modules/uts-tests/utssdk/Operators.uts b/uni_modules/uts-tests/utssdk/Operators.uts index 1e18a6a..1b32623 100644 --- a/uni_modules/uts-tests/utssdk/Operators.uts +++ b/uni_modules/uts-tests/utssdk/Operators.uts @@ -91,29 +91,29 @@ export function testOperators(): Result { function divide (a: number, b: number): number { return a / b } - expect(divide(10, 5)).toEqual(2); - expect(divide(-10, -5)).toEqual(2); - expect(divide(10, -5)).toEqual(-2); - expect(divide(-10, 5)).toEqual(-2); - expect(divide(0.1, 0.3)).toEqual(0.33333333333333337); - expect(divide(0.3, 0.1)).toEqual(2.9999999999999996); + + expect(divide(10, 5)).toEqualNumber(2); + expect(divide(-10, -5)).toEqualNumber(2); + expect(divide(10, -5)).toEqualNumber(-2); + expect(divide(-10, 5)).toEqualNumber(-2); + expect(divide(0.1, 0.3)).toEqualNumber(0.33333333333333337); + expect(divide(0.3, 0.1)).toEqualNumber(2.9999999999999996); expectNumber(divide(1.5, 0.5)).toEqualDouble(3); - expect(divide(3, 2)).toEqual(1.5); + expect(divide(3, 2)).toEqualNumber(1.5); // 暂不支持字面量 // expect(3 / 2).toEqual(1.5); - expect(divide(10, 3)).toEqual(3.3333333333333335); - expect(divide(3, 10)).toEqual(0.3); - expect(divide(1, 3)).toEqual(0.3333333333333333); - expect(divide(1000000, 2000000)).toEqual(0.5); + expect(divide(10, 3)).toEqualNumber(3.3333333333333335); + expect(divide(3, 10)).toEqualNumber(0.3); + expect(divide(1, 3)).toEqualNumber(0.3333333333333333); + expect(divide(1000000, 2000000)).toEqualNumber(0.5); // kotlin java.lang.ArithmeticException: divide by zero // swift 返回 inf // web 返回 Infinity // todo 统一处理 // expect(divide(1, 0)).toEqual(); - expect(divide(16788990011, 5)).toEqual(3357798002.2); - expect(divide(16788990015, 5)).toEqual(3357798003); + expect(divide(16788990011, 5)).toEqualNumber(3357798002.2); + expect(divide(16788990015, 5)).toEqualNumber(3357798003); expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822); - }) test('/=', () => { -- GitLab