Skip to content

Commit

Permalink
Refactor to fix greaterThanOrEquals, lessThanOrEquals, semverGreaterT…
Browse files Browse the repository at this point in the history
…hanOrEquals, semverLessThanOrEquals issues for below operators (#16)
  • Loading branch information
Tan108 authored Feb 26, 2024
1 parent dd93adf commit f6e8911
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
20 changes: 10 additions & 10 deletions src/main/kotlin/com/featurevisor/sdk/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/featurevisor/types/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
16 changes: 8 additions & 8 deletions src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)

Expand All @@ -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)
)

Expand Down Expand Up @@ -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")
)

Expand Down Expand Up @@ -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")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit f6e8911

Please sign in to comment.