功能:添加小数特征
Scenario: Add two positive decimal numbers
Given I am on the demo page
When I add the numbers 2.25 and 3.25
Then the result is 5.5
我认为when方法应该是这样的
@When("^I add the numbers (-?\\d+\\.?\\d*) and (-?\\d+\\.?\\d*)$")
public void i_add_the_numbers_and(double x, double y) throws Throwable {
demoPage.addNumbers(x, y);
}
@Then("^the result is (-?\\d+\\.?\\d*)$")
public void the_result_is(double sum) throws Throwable {
assertEquals(demoPage.getCalculatorResults(), sum);
}
}
问题是正则表达式的数字与实数不匹配。例如-1.2或5.4或-23.234
如何匹配所有正负实数?
谢谢InvalidData
以下作品
/**
* @param x
* @param y
* @throws Throwable
*/
@When("^I add the numbers (-?\\d+\\.?\\d*) and (-?\\d+\\.?\\d*)$")
public void i_add_the_numbers_and(float x, float y) throws Throwable {
demoPage.addNumbers(x, y);
}
/**
* @param sum
* @throws Throwable
*/
@Then("^the result is (-?\\d+\\.?\\d*)$")
public void the_result_is(float sum) throws Throwable {
assertEquals(demoPage.getCalculatorResults(), sum);
}
那么为什么使用float或BigDecimal导致该方法工作?我的理解是double是float的较长版本。所以,如果浮动工作,为什么不会加倍