Skip to content

Commit

Permalink
Add codestyle, reformat files, configure test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
uniumuniu committed Oct 2, 2023
1 parent 60f0002 commit ebab671
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 104 deletions.
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.2.1/userguide/building_java_projects.html in the Gradle documentation.
*/

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.8.20"
Expand Down Expand Up @@ -66,4 +69,10 @@ java {
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
// Log useful information when running tests.
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(TestLogEvent.SKIPPED, TestLogEvent.PASSED, TestLogEvent.FAILED)
showStandardStreams = true
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/com/featurevisor/sdk/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ object Conditions {
Operator.notEquals -> return contextValue.value != conditionValue.value
Operator.contains -> return contextValue.value.contains(conditionValue.value)
Operator.notContains ->
return !contextValue.value.contains(conditionValue.value)
return !contextValue.value.contains(conditionValue.value)

Operator.startsWith ->
return contextValue.value.startsWith(conditionValue.value)
return contextValue.value.startsWith(conditionValue.value)

Operator.endsWith -> return contextValue.value.endsWith(conditionValue.value)
else -> return false
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/com/featurevisor/sdk/MurmurHash3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ public class MurmurHash3(private val seed: UInt = 1.toUInt()) {

private fun ByteArray.getLittleEndianUInt(index: Int): UInt {
return this.getUInt(index) or
(this.getUInt(index + 1) shl 8) or
(this.getUInt(index + 2) shl 16) or
(this.getUInt(index + 3) shl 24)
(this.getUInt(index + 1) shl 8) or
(this.getUInt(index + 2) shl 16) or
(this.getUInt(index + 3) shl 24)
}

private fun ByteArray.getLittleEndianLong(index: Int): ULong {
return this.getULong(index) or
(this.getULong(index + 1) shl 8) or
(this.getULong(index + 2) shl 16) or
(this.getULong(index + 3) shl 24) or
(this.getULong(index + 4) shl 32) or
(this.getULong(index + 5) shl 40) or
(this.getULong(index + 6) shl 48) or
(this.getULong(index + 7) shl 56)
(this.getULong(index + 1) shl 8) or
(this.getULong(index + 2) shl 16) or
(this.getULong(index + 3) shl 24) or
(this.getULong(index + 4) shl 32) or
(this.getULong(index + 5) shl 40) or
(this.getULong(index + 6) shl 48) or
(this.getULong(index + 7) shl 56)
}

private fun UInt.mix(r: Int, c1: UInt, c2: UInt): UInt {
Expand Down
68 changes: 35 additions & 33 deletions src/main/kotlin/com/featurevisor/types/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sealed class AttributeValue {
data class IntValue(val value: Int) : AttributeValue()
data class DoubleValue(val value: Double) : AttributeValue()
data class BooleanValue(val value: Boolean) : AttributeValue()

// @TODO: implement Date
object NullValue : AttributeValue()
}
Expand All @@ -17,7 +18,7 @@ data class Attribute(
val key: AttributeKey,
val type: String,
val archived: Boolean?,
val capture: Boolean?
val capture: Boolean?,
)

enum class Operator(val value: String) {
Expand Down Expand Up @@ -59,26 +60,27 @@ sealed class ConditionValue {
data class DoubleValue(val value: Double) : ConditionValue()
data class BooleanValue(val value: Boolean) : ConditionValue()
data class ArrayValue(val values: Array<String>) : ConditionValue()

// @TODO: implement Date
object NullValue : ConditionValue()
}

data class PlainCondition(
val attribute: AttributeKey,
val operator: Operator,
val value: ConditionValue
val value: ConditionValue,
)

data class AndCondition(
val and: Array<Condition>
val and: Array<Condition>,
)

data class OrCondition(
val or: Array<Condition>
val or: Array<Condition>,
)

data class NotCondition(
val not: Array<Condition>
val not: Array<Condition>,
)

sealed class Condition {
Expand All @@ -95,21 +97,21 @@ typealias SegmentKey = String
data class Segment(
val archived: Boolean?,
val key: SegmentKey,
val conditions: Condition
val conditions: Condition,
)

typealias PlainGroupSegment = SegmentKey

data class AndGroupSegment(
val and: Array<GroupSegment>
val and: Array<GroupSegment>,
)

data class OrGroupSegment(
val or: Array<GroupSegment>
val or: Array<GroupSegment>,
)

data class NotGroupSegment(
val not: Array<GroupSegment>
val not: Array<GroupSegment>,
)

sealed class GroupSegment {
Expand Down Expand Up @@ -152,13 +154,13 @@ data class VariableOverride(

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

data class Variable(
val key: VariableKey,
val value: VariableValue,
val overrides: Array<VariableOverride>?
val overrides: Array<VariableOverride>?,
)

data class Variation(
Expand All @@ -170,13 +172,13 @@ data class Variation(
// 0 to 100 (available from parsed YAML, but not in datafile)
val weight: Double?,

val variables: Array<Variable>?
val variables: Array<Variable>?,
)

data class VariableSchema(
val key: VariableKey,
val type: VariableType,
val defaultValue: VariableValue
val defaultValue: VariableValue,
)

typealias FeatureKey = String
Expand All @@ -190,21 +192,21 @@ data class Force(

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

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

// 0 to 100
val percentage: Weight
val percentage: Weight,
)

data class Group(
val key: String,
val description: String,
val slots: Array<Slot>
val slots: Array<Slot>,
)

typealias BucketKey = String
Expand All @@ -220,12 +222,12 @@ typealias Percentage = Int

data class Range(
val start: Percentage,
val end: Percentage
val end: Percentage,
)

data class Allocation(
val variation: VariationValue,
val range: Range
val range: Range,
)

data class Traffic(
Expand All @@ -237,15 +239,15 @@ data class Traffic(
val variation: VariationValue?,
val variables: VariableValues?,

val allocation: Array<Allocation>
val allocation: Array<Allocation>,
)

typealias PlainBucketBy = String

typealias AndBucketBy = Array<BucketBy>

data class OrBucketBy(
val or: Array<String>
val or: Array<String>,
)

sealed class BucketBy {
Expand All @@ -256,7 +258,7 @@ sealed class BucketBy {

data class RequiredWithVariation(
val key: FeatureKey,
val variation: VariationValue
val variation: VariationValue,
)

sealed class Required {
Expand All @@ -275,21 +277,21 @@ data class Feature(
val force: Array<Force>?,

// if in a Group (mutex), these are available slot ranges
val ranges: Array<Range>?
val ranges: Array<Range>?,
)

data class DatafileContent(
val schemaVersion: String,
val revision: String,
val attributes: Array<Attribute>,
val segments: Array<Segment>,
val features: Array<Feature>
val features: Array<Feature>,
)

data class OverrideFeature(
val enabled: Boolean,
val variation: VariationValue?,
val variables: VariableValues?
val variables: VariableValues?,
)

typealias StickyFeatures = Map<FeatureKey, OverrideFeature>
Expand All @@ -313,13 +315,13 @@ data class Rule(

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

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

typealias Environments = Map<EnvironmentKey, Environment>
Expand All @@ -340,7 +342,7 @@ data class ParsedFeature(
val variablesSchema: Array<VariableSchema>?,
val variations: Array<Variation>?,

val environments: Environments
val environments: Environments,
)

/**
Expand All @@ -353,23 +355,23 @@ data class FeatureAssertion(
val context: Context,
val expectedToBeEnabled: Boolean,
val expectedVariation: VariationValue?,
val expectedVariables: VariableValues?
val expectedVariables: VariableValues?,
)

data class TestFeature(
val key: FeatureKey,
val assertions: Array<FeatureAssertion>
val assertions: Array<FeatureAssertion>,
)

data class SegmentAssertion(
val description: String?,
val context: Context,
val expectedToMatch: Boolean
val expectedToMatch: Boolean,
)

data class TestSegment(
val key: SegmentKey,
val assertions: Array<SegmentAssertion>
val assertions: Array<SegmentAssertion>,
)

data class Test(
Expand All @@ -381,9 +383,9 @@ data class Test(
val features: Array<TestFeature>?,

// needed for segment testing
val segments: Array<TestSegment>?
val segments: Array<TestSegment>?,
)

data class Spec(
val tests: Array<Test>
val tests: Array<Test>,
)
16 changes: 8 additions & 8 deletions src/test/kotlin/com/featurevisor/sdk/BucketTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class BucketTest {
fun getBucketedNumberReturnsExpectedValues() {

val expectedResults =
mapOf(
"foo" to 20602,
"bar" to 89144,
"123.foo" to 3151,
"123.bar" to 9710,
"123.456.foo" to 14432,
"123.456.bar" to 1982
)
mapOf(
"foo" to 20602,
"bar" to 89144,
"123.foo" to 3151,
"123.bar" to 9710,
"123.456.foo" to 14432,
"123.456.bar" to 1982
)

for ((key, value) in expectedResults) {
val result = Bucket.getBucketedNumber(key)
Expand Down
Loading

0 comments on commit ebab671

Please sign in to comment.