[英]step file method for real numbers
Feature: Addition of decimal Feature 功能:添加小数特征
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
I think the when method should be something like 我认为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);
}
}
The problem is that the number regex is not matching real numbers. 问题是正则表达式的数字与实数不匹配。 example -1.2 or 5.4 or -23.234
例如-1.2或5.4或-23.234
How do I match all postive and negative real numbers? 我如何匹配所有正和负实数?
thanks NeplatnyUdaj 谢谢NeplatnyUdaj
the following works 以下作品
/**
* @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);
}
so why would using float or BigDecimal cause the method to work? 那么为什么使用float或BigDecimal导致该方法工作? My understanding is that double is a longer version of float.
我的理解是double是float的较长版本。 so if float works why won't double
所以,如果浮动工作,为什么不会加倍
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.