From f6e89116808e56d4b86bb364f8173de2ee7f400d Mon Sep 17 00:00:00 2001 From: Tanmay Ranjan <42682768+Tan108@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:02:21 +0530 Subject: [PATCH] Refactor to fix greaterThanOrEquals, lessThanOrEquals, semverGreaterThanOrEquals, semverLessThanOrEquals issues for below operators (#16) --- .../kotlin/com/featurevisor/sdk/Conditions.kt | 20 +++++++++---------- .../sdk/serializers/Serializers.kt | 8 ++++---- .../kotlin/com/featurevisor/types/Types.kt | 8 ++++---- .../com/featurevisor/sdk/ConditionsTest.kt | 16 +++++++-------- .../serializers/ConditionSerializerTest.kt | 4 ++-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/com/featurevisor/sdk/Conditions.kt b/src/main/kotlin/com/featurevisor/sdk/Conditions.kt index 895e60c..0898647 100644 --- a/src/main/kotlin/com/featurevisor/sdk/Conditions.kt +++ b/src/main/kotlin/com/featurevisor/sdk/Conditions.kt @@ -14,18 +14,18 @@ import com.featurevisor.types.Operator.CONTAINS import com.featurevisor.types.Operator.ENDS_WITH import com.featurevisor.types.Operator.EQUALS import com.featurevisor.types.Operator.GREATER_THAN -import com.featurevisor.types.Operator.GREATER_THAN_OR_EQUAL +import com.featurevisor.types.Operator.GREATER_THAN_OR_EQUALS import com.featurevisor.types.Operator.IN_ARRAY import com.featurevisor.types.Operator.LESS_THAN -import com.featurevisor.types.Operator.LESS_THAN_OR_EQUAL +import com.featurevisor.types.Operator.LESS_THAN_OR_EQUALS import com.featurevisor.types.Operator.NOT_CONTAINS import com.featurevisor.types.Operator.NOT_EQUALS import com.featurevisor.types.Operator.NOT_IN_ARRAY import com.featurevisor.types.Operator.SEMVER_EQUALS import com.featurevisor.types.Operator.SEMVER_GREATER_THAN -import com.featurevisor.types.Operator.SEMVER_GREATER_THAN_OR_EQUAL +import com.featurevisor.types.Operator.SEMVER_GREATER_THAN_OR_EQUALS import com.featurevisor.types.Operator.SEMVER_LESS_THAN -import com.featurevisor.types.Operator.SEMVER_LESS_THAN_OR_EQUAL +import com.featurevisor.types.Operator.SEMVER_LESS_THAN_OR_EQUALS import com.featurevisor.types.Operator.SEMVER_NOT_EQUALS import com.featurevisor.types.Operator.STARTS_WITH import net.swiftzer.semver.SemVer @@ -60,7 +60,7 @@ object Conditions { conditionValue.value ) == 1 - SEMVER_GREATER_THAN_OR_EQUAL -> compareVersions( + SEMVER_GREATER_THAN_OR_EQUALS -> compareVersions( attributeValue.value, conditionValue.value ) >= 0 @@ -70,7 +70,7 @@ object Conditions { conditionValue.value ) == -1 - SEMVER_LESS_THAN_OR_EQUAL -> compareVersions( + SEMVER_LESS_THAN_OR_EQUALS -> compareVersions( attributeValue.value, conditionValue.value ) <= 0 @@ -84,9 +84,9 @@ object Conditions { EQUALS -> attributeValue.value == conditionValue.value NOT_EQUALS -> attributeValue.value != conditionValue.value GREATER_THAN -> attributeValue.value > conditionValue.value - GREATER_THAN_OR_EQUAL -> attributeValue.value >= conditionValue.value + GREATER_THAN_OR_EQUALS -> attributeValue.value >= conditionValue.value LESS_THAN -> attributeValue.value < conditionValue.value - LESS_THAN_OR_EQUAL -> attributeValue.value <= conditionValue.value + LESS_THAN_OR_EQUALS -> attributeValue.value <= conditionValue.value else -> false } } @@ -96,9 +96,9 @@ object Conditions { EQUALS -> attributeValue.value == conditionValue.value NOT_EQUALS -> attributeValue.value != conditionValue.value GREATER_THAN -> attributeValue.value > conditionValue.value - GREATER_THAN_OR_EQUAL -> attributeValue.value >= conditionValue.value + GREATER_THAN_OR_EQUALS -> attributeValue.value >= conditionValue.value LESS_THAN -> attributeValue.value < conditionValue.value - LESS_THAN_OR_EQUAL -> attributeValue.value <= conditionValue.value + LESS_THAN_OR_EQUALS -> attributeValue.value <= conditionValue.value else -> false } } diff --git a/src/main/kotlin/com/featurevisor/sdk/serializers/Serializers.kt b/src/main/kotlin/com/featurevisor/sdk/serializers/Serializers.kt index 04736d3..7001f69 100644 --- a/src/main/kotlin/com/featurevisor/sdk/serializers/Serializers.kt +++ b/src/main/kotlin/com/featurevisor/sdk/serializers/Serializers.kt @@ -331,9 +331,9 @@ private fun mapOperator(value: String): Operator { // numeric "greaterThan" -> Operator.GREATER_THAN - "greaterThanOrEqual" -> Operator.GREATER_THAN_OR_EQUAL + "greaterThanOrEquals" -> Operator.GREATER_THAN_OR_EQUALS "lessThan" -> Operator.LESS_THAN - "lessThanOrEqual" -> Operator.LESS_THAN_OR_EQUAL + "lessThanOrEquals" -> Operator.LESS_THAN_OR_EQUALS // string "contains" -> Operator.CONTAINS @@ -345,9 +345,9 @@ private fun mapOperator(value: String): Operator { "semverEquals" -> Operator.SEMVER_EQUALS "semverNotEquals" -> Operator.SEMVER_NOT_EQUALS "semverGreaterThan" -> Operator.SEMVER_GREATER_THAN - "semverGreaterThanOrEquals" -> Operator.SEMVER_GREATER_THAN_OR_EQUAL + "semverGreaterThanOrEquals" -> Operator.SEMVER_GREATER_THAN_OR_EQUALS "semverLessThan" -> Operator.SEMVER_LESS_THAN - "semverLessThanOrEquals" -> Operator.SEMVER_LESS_THAN_OR_EQUAL + "semverLessThanOrEquals" -> Operator.SEMVER_LESS_THAN_OR_EQUALS // date comparisons "before" -> Operator.BEFORE diff --git a/src/main/kotlin/com/featurevisor/types/Types.kt b/src/main/kotlin/com/featurevisor/types/Types.kt index a482c54..e7e5ca1 100644 --- a/src/main/kotlin/com/featurevisor/types/Types.kt +++ b/src/main/kotlin/com/featurevisor/types/Types.kt @@ -274,9 +274,9 @@ enum class Operator(val value: String) { // numeric GREATER_THAN("greaterThan"), - GREATER_THAN_OR_EQUAL("greaterThanOrEqual"), + GREATER_THAN_OR_EQUALS("greaterThanOrEquals"), LESS_THAN("lessThan"), - LESS_THAN_OR_EQUAL("lessThanOrEqual"), + LESS_THAN_OR_EQUALS("lessThanOrEquals"), // string CONTAINS("contains"), @@ -288,9 +288,9 @@ enum class Operator(val value: String) { SEMVER_EQUALS("semverEquals"), SEMVER_NOT_EQUALS("semverNotEquals"), SEMVER_GREATER_THAN("semverGreaterThan"), - SEMVER_GREATER_THAN_OR_EQUAL("semverGreaterThanOrEqual"), + SEMVER_GREATER_THAN_OR_EQUALS("semverGreaterThanOrEquals"), SEMVER_LESS_THAN("semverLessThan"), - SEMVER_LESS_THAN_OR_EQUAL("semverLessThanOrEqual"), + SEMVER_LESS_THAN_OR_EQUALS("semverLessThanOrEquals"), // date comparisons BEFORE("before"), diff --git a/src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt b/src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt index af5bf0a..efba5c8 100644 --- a/src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt +++ b/src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt @@ -9,17 +9,17 @@ import com.featurevisor.types.Operator.CONTAINS import com.featurevisor.types.Operator.ENDS_WITH import com.featurevisor.types.Operator.EQUALS import com.featurevisor.types.Operator.GREATER_THAN -import com.featurevisor.types.Operator.GREATER_THAN_OR_EQUAL +import com.featurevisor.types.Operator.GREATER_THAN_OR_EQUALS import com.featurevisor.types.Operator.IN_ARRAY import com.featurevisor.types.Operator.LESS_THAN -import com.featurevisor.types.Operator.LESS_THAN_OR_EQUAL +import com.featurevisor.types.Operator.LESS_THAN_OR_EQUALS import com.featurevisor.types.Operator.NOT_EQUALS import com.featurevisor.types.Operator.NOT_IN_ARRAY import com.featurevisor.types.Operator.SEMVER_EQUALS import com.featurevisor.types.Operator.SEMVER_GREATER_THAN -import com.featurevisor.types.Operator.SEMVER_GREATER_THAN_OR_EQUAL +import com.featurevisor.types.Operator.SEMVER_GREATER_THAN_OR_EQUALS import com.featurevisor.types.Operator.SEMVER_LESS_THAN -import com.featurevisor.types.Operator.SEMVER_LESS_THAN_OR_EQUAL +import com.featurevisor.types.Operator.SEMVER_LESS_THAN_OR_EQUALS import com.featurevisor.types.Operator.SEMVER_NOT_EQUALS import com.featurevisor.types.Operator.STARTS_WITH import io.kotest.matchers.shouldBe @@ -112,7 +112,7 @@ class ConditionsTest { val condition = Condition.Plain( attributeKey = "age", - operator = GREATER_THAN_OR_EQUAL, + operator = GREATER_THAN_OR_EQUALS, value = ConditionValue.IntValue(18) ) @@ -137,7 +137,7 @@ class ConditionsTest { val condition = Condition.Plain( attributeKey = "age", - operator = LESS_THAN_OR_EQUAL, + operator = LESS_THAN_OR_EQUALS, value = ConditionValue.IntValue(18) ) @@ -299,7 +299,7 @@ class ConditionsTest { fun `SEMVER_GREATER_THAN_OR_EQUAL operator works for strings`() { val condition = Condition.Plain( attributeKey = "version", - operator = SEMVER_GREATER_THAN_OR_EQUAL, + operator = SEMVER_GREATER_THAN_OR_EQUALS, value = ConditionValue.StringValue("1.2.3") ) @@ -347,7 +347,7 @@ class ConditionsTest { fun `SEMVER_LESS_THAN_OR_EQUAL operator works for strings`() { val condition = Condition.Plain( attributeKey = "version", - operator = SEMVER_LESS_THAN_OR_EQUAL, + operator = SEMVER_LESS_THAN_OR_EQUALS, value = ConditionValue.StringValue("1.2.3") ) diff --git a/src/test/kotlin/com/featurevisor/sdk/serializers/ConditionSerializerTest.kt b/src/test/kotlin/com/featurevisor/sdk/serializers/ConditionSerializerTest.kt index 02fcc40..d1124d9 100644 --- a/src/test/kotlin/com/featurevisor/sdk/serializers/ConditionSerializerTest.kt +++ b/src/test/kotlin/com/featurevisor/sdk/serializers/ConditionSerializerTest.kt @@ -55,7 +55,7 @@ class ConditionSerializerTest { } (condition.and[1] as Condition.Plain).run { attributeKey shouldBe "age" - operator shouldBe Operator.GREATER_THAN_OR_EQUAL + operator shouldBe Operator.GREATER_THAN_OR_EQUALS value shouldBe ConditionValue.IntValue(18) } } @@ -86,7 +86,7 @@ class ConditionSerializerTest { } (condition.or[1] as Condition.Plain).run { attributeKey shouldBe "age" - operator shouldBe Operator.GREATER_THAN_OR_EQUAL + operator shouldBe Operator.GREATER_THAN_OR_EQUALS value shouldBe ConditionValue.IntValue(18) } }