diff --git a/uni_modules/uts-tests/utssdk/Global.uts b/uni_modules/uts-tests/utssdk/Global.uts index 5b7b28e7294f0da1274df539ef1095f5a6433abc..92e135e8a511283eb02a0606836c8994a72528e3 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 4bb39d1aa28ac9898604010761efbe1d4a2329b6..55597d7ca2cfb517f8fdd647a4926bcda33ee561 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 1e18a6a234441449a58311b9bbd46e0e3828a2ee..1b32623dae5bb644575d3f41798f682a4345ecaa 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('/=', () => {