diff --git a/src/main/scala/com/lectra/kapoeira/glue/FeaturesStepDefinitions.scala b/src/main/scala/com/lectra/kapoeira/glue/FeaturesStepDefinitions.scala index ec22074..3a019be 100644 --- a/src/main/scala/com/lectra/kapoeira/glue/FeaturesStepDefinitions.scala +++ b/src/main/scala/com/lectra/kapoeira/glue/FeaturesStepDefinitions.scala @@ -226,7 +226,7 @@ class FeaturesStepDefinitions ) } - And("^assert\\s+(\\S+)\\s+(\\$\\S*)\\s*==\\s+(\\d+\\.\\d+)\\s+\\+\\-\\s+(\\d+\\.\\d+)\\s*$") { + And("""^assert\s+(\S+)\s+(\$\S*)\s*==\s+([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*)(?:[eE][+-]?\d+)?)\s+\+\-\s+([+-]?(?=\.\d|\d)(?:\d+)?(?:\.?\d*)(?:[eE][+-]?\d+)?)\s*$""") { (alias: String, jsonExpression: String, expectedJsonNumber: String,approximationJsonNumber:String) => val interpolatedExpectedJson = backgroundContext.substituteVariablesIn(expectedJsonNumber) diff --git a/src/test/resources/features/assertions.feature b/src/test/resources/features/assertions.feature index b4c59bc..870fc3b 100644 --- a/src/test/resources/features/assertions.feature +++ b/src/test/resources/features/assertions.feature @@ -25,6 +25,8 @@ Feature: assertions And assert value2.2 $ == [3,4] And assert value2.3 $ == "value2.3" And assert value2.4 $.foo == 12.0038209653823934567890123456789 - And assert value2.4 $.foo == 12.0038 +- 0.1 + And assert value2.4 $.foo == 12.0 +- 0.1 + And assert value2.4 $.foo == 12.1 +- 0.1 + And assert value2.4 $.foo == 12.0038 +- 1E4 And assert aliasHeaders2.1 $ == {"foo":"bar","baz":"42"} And assert aliasHeaders2.1 $.foo == "bar" diff --git a/src/test/scala/com/lectra/kapoeira/glue/AssertsTest.scala b/src/test/scala/com/lectra/kapoeira/glue/AssertsTest.scala index 4d89bdd..a9be2f9 100644 --- a/src/test/scala/com/lectra/kapoeira/glue/AssertsTest.scala +++ b/src/test/scala/com/lectra/kapoeira/glue/AssertsTest.scala @@ -47,7 +47,10 @@ class AssertsTest extends AnyFlatSpec with Matchers with MockFactory { val expectedConsumedRecords = List(keyValueRecord) assertionContext.launchConsumption(expectedConsumedRecords) - Asserts.approxEqual(assertionContext, valueAlias, "$.foo", "12.0038","0.1" ) + Asserts.approxEqual(assertionContext, valueAlias, "$.foo", "12.0038","0.0001" ) + Asserts.approxEqual(assertionContext, valueAlias, "$.foo", "12.0038","1E4" ) + Asserts.approxEqual(assertionContext, valueAlias, "$.foo", "12.0","0.1" ) + Asserts.approxEqual(assertionContext, valueAlias, "$.foo", "12.1","0.1" ) }