Skip to content

Commit

Permalink
Includes Parity changes, Null handling and Test cases for 'and' 'or' …
Browse files Browse the repository at this point in the history
…operator. (#17)

Co-authored-by: Tanmay Ranjan <[email protected]>
  • Loading branch information
Tan108 and Tan108 authored Feb 26, 2024
1 parent f6e8911 commit 0fce28f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fun FeaturevisorInstance.evaluateFlag(featureKey: FeatureKey, context: Context =
}

// treated as enabled because of matched traffic
if (bucketValue < matchedTraffic.percentage) {
if (bucketValue <= matchedTraffic.percentage) {
// @TODO: verify if range check should be inclusive or not
evaluation = Evaluation(
featureKey = feature.key,
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/com/featurevisor/sdk/Instance+Feature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fun FeaturevisorInstance.getFeatureByKey(featureKey: String): Feature? {
return datafileReader.getFeature(featureKey)
}

fun FeaturevisorInstance.getFeature(featureKey: String): Feature?{
return datafileReader.getFeature(featureKey)
}

internal fun FeaturevisorInstance.findForceFromFeature(
feature: Feature,
context: Context,
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/com/featurevisor/types/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ data class VariableOverride(

// one of the below must be present in YAML
val conditions: Condition? = null,
val segments: GroupSegment?,
val segments: GroupSegment?=null,
)

@Serializable
data class Variable(
val key: VariableKey,
val value: VariableValue,
val overrides: List<VariableOverride>?,
val overrides: List<VariableOverride>? = null,
)

@Serializable
Expand All @@ -68,9 +68,9 @@ data class Variation(
val value: VariationValue,

// 0 to 100 (available from parsed YAML, but not in datafile)
val weight: Double?,
val weight: Double? = null,

val variables: List<Variable>?,
val variables: List<Variable>? = null,
)

@Serializable
Expand All @@ -97,7 +97,7 @@ data class Force(

data class Slot(
// @TODO: allow false?
val feature: FeatureKey?,
val feature: FeatureKey? = null,

// 0 to 100
val percentage: Weight,
Expand Down Expand Up @@ -128,15 +128,15 @@ data class Rule(
val segments: GroupSegment,
val percentage: Weight,

val enabled: Boolean?,
val variation: VariationValue?,
val variables: VariableValues?,
val enabled: Boolean? = null,
val variation: VariationValue? = null,
val variables: VariableValues? = null,
)

data class Environment(
val expose: Boolean?,
val expose: Boolean? = null,
val rules: List<Rule>,
val force: List<Force>?,
val force: List<Force>? = null,
)

typealias Environments = Map<EnvironmentKey, Environment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ConditionSerializerTest {
"value": "1.2.3"
}, {
"attribute": "age",
"operator": "greaterThanOrEqual",
"operator": "greaterThanOrEquals",
"value": "18"
}]
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class ConditionSerializerTest {
"value": "1.2.3"
}, {
"attribute": "age",
"operator": "greaterThanOrEqual",
"operator": "greaterThanOrEquals",
"value": "18"
}]
}
Expand Down

0 comments on commit 0fce28f

Please sign in to comment.