From ae57959e1cc701103fd025ec6bc33df9b64906b1 Mon Sep 17 00:00:00 2001 From: Sylvain Carisey Date: Mon, 4 Nov 2024 15:13:19 +0100 Subject: [PATCH] =?UTF-8?q?feat:assert=20approximatively=20equal,=20=C3=A0?= =?UTF-8?q?=20la=20JS=20number=20definition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lectra/kapoeira/glue/FeaturesStepDefinitions.scala | 2 +- src/test/resources/features/assertions.feature | 4 +++- src/test/scala/com/lectra/kapoeira/glue/AssertsTest.scala | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) 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" ) }