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

测试示例增加数字对比的方法

上级 133051c2
...@@ -35,8 +35,9 @@ export function testGlobal(): Result { ...@@ -35,8 +35,9 @@ export function testGlobal(): Result {
expect(parseInt("9223372036854775807")).toEqual(9.223372036854778e+18) expect(parseInt("9223372036854775807")).toEqual(9.223372036854778e+18)
expect(parseInt("9223372036854775807000")).toEqual(9.223372036854777e+21) expect(parseInt("9223372036854775807000")).toEqual(9.223372036854777e+21)
expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqual(9.223372036854776e+86) expect(parseInt("922337203685477580700099999999999999999999999999999999999999999999999999999999999999999")).toEqual(9.223372036854776e+86)
expect(parseInt("50") / 100).toEqual(0.5); expect(parseInt("50") / 100).toEqualNumber(0.5);
expect(parseInt("500") / 100).toEqual(5); expect(parseInt("500") / 100).toEqualNumber(5);
}) })
...@@ -47,7 +48,7 @@ export function testGlobal(): Result { ...@@ -47,7 +48,7 @@ export function testGlobal(): Result {
expect(parseFloat("314e-2")).toEqual(3.14); expect(parseFloat("314e-2")).toEqual(3.14);
expect(parseFloat("0.0314E+2")).toEqual(3.14); expect(parseFloat("0.0314E+2")).toEqual(3.14);
expect(parseFloat("3.14some non-digit characters")).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); expect(parseFloat("105") / 50).toEqual(2.1);
}) })
......
...@@ -15,6 +15,12 @@ export class Matchers<T> { ...@@ -15,6 +15,12 @@ export class Matchers<T> {
NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise() NSException(name = NSExceptionName.internalInconsistencyException, reason = format(expected, this.actual)).raise()
// #endif // #endif
} }
toEqualNumber(expected: T) {
if (expected == this.actual) {
return
}
}
} }
/** /**
* 数值对比器 * 数值对比器
......
...@@ -91,29 +91,29 @@ export function testOperators(): Result { ...@@ -91,29 +91,29 @@ export function testOperators(): Result {
function divide (a: number, b: number): number { function divide (a: number, b: number): number {
return a / b return a / b
} }
expect(divide(10, 5)).toEqual(2);
expect(divide(-10, -5)).toEqual(2); expect(divide(10, 5)).toEqualNumber(2);
expect(divide(10, -5)).toEqual(-2); expect(divide(-10, -5)).toEqualNumber(2);
expect(divide(-10, 5)).toEqual(-2); expect(divide(10, -5)).toEqualNumber(-2);
expect(divide(0.1, 0.3)).toEqual(0.33333333333333337); expect(divide(-10, 5)).toEqualNumber(-2);
expect(divide(0.3, 0.1)).toEqual(2.9999999999999996); 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); 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(3 / 2).toEqual(1.5);
expect(divide(10, 3)).toEqual(3.3333333333333335); expect(divide(10, 3)).toEqualNumber(3.3333333333333335);
expect(divide(3, 10)).toEqual(0.3); expect(divide(3, 10)).toEqualNumber(0.3);
expect(divide(1, 3)).toEqual(0.3333333333333333); expect(divide(1, 3)).toEqualNumber(0.3333333333333333);
expect(divide(1000000, 2000000)).toEqual(0.5); expect(divide(1000000, 2000000)).toEqualNumber(0.5);
// kotlin java.lang.ArithmeticException: divide by zero // kotlin java.lang.ArithmeticException: divide by zero
// swift 返回 inf // swift 返回 inf
// web 返回 Infinity // web 返回 Infinity
// todo 统一处理 // todo 统一处理
// expect(divide(1, 0)).toEqual(); // expect(divide(1, 0)).toEqual();
expect(divide(16788990011, 5)).toEqual(3357798002.2); expect(divide(16788990011, 5)).toEqualNumber(3357798002.2);
expect(divide(16788990015, 5)).toEqual(3357798003); expect(divide(16788990015, 5)).toEqualNumber(3357798003);
expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822); expectNumber(divide(16788990015, 10088990000)).toEqualDouble(1.6640902622561822);
}) })
test('/=', () => { test('/=', () => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册