java - 实数的步进文件法
问题描述
特征:添加小数特征
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
如何匹配所有正负实数?
解决方案
感谢 NeplatnyUdaj
以下作品
/**
* @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 的更长版本。所以如果浮动有效,为什么不加倍
推荐阅读
- android - Google Places API 建立取货点
- javascript - 如何将 next.js 应用部署到 Cpanel?
- tradingview-api - 有谁知道为什么它说变量 ,,`len` 已声明”,我该如何修复它... 交易视图
- javascript - 如何获取要保存在 Firestore 中的复选框的值?
- java - java 8中BiConsumer接口的使用
- javascript - 如果其他对象的属性为假,那么数组中对象的一个属性如何为真?
- android - Jetpack Compose 和 Compose Navigation 如何处理 Android 活动?
- python - 在列表中查找大于 10 的数字的算法不会返回正确答案
- javascript - 如何找到给定ID的路径?
- java - 使用 Java 读取 parquet 文件,但它在本地机器上工作,在 docker 容器中不工作