Skip to content

Commit

Permalink
chore: fixed naming issues and explicitly return Empty() for max and …
Browse files Browse the repository at this point in the history
…min strategy
  • Loading branch information
janniclas committed Oct 30, 2024
1 parent 8e80e88 commit 68815d1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ internal object MaximumKPICalculationStrategy : BaseKpiCalculationStrategy() {

override fun internalCalculateKpi(edges: Collection<KpiHierarchyEdge>): KpiCalculationResult {

val max = if (edges.isEmpty()) 0 else edges.maxOf { it.to.score }
val max = edges.maxOfOrNull { it.to.score }

if (max == null) {
return KpiCalculationResult.Empty()
}

return KpiCalculationResult.Success(score = max)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ internal object MinimumKPICalculationStrategy : BaseKpiCalculationStrategy() {

override fun internalCalculateKpi(edges: Collection<KpiHierarchyEdge>): KpiCalculationResult {

val max = if (edges.isEmpty()) 0 else edges.minOf { it.to.score }
val min = edges.minOfOrNull { it.to.score }

return KpiCalculationResult.Success(score = max)
if (min == null) {
return KpiCalculationResult.Empty()
}

return KpiCalculationResult.Success(score = min)
}

/** There is no validity requirement for this strategy. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import de.fraunhofer.iem.spha.model.kpi.hierarchy.KpiNode
import kotlin.test.Test
import kotlin.test.assertEquals

class WeightedWeightedMaximumKPICalculationStrategyTest {
class WeightedMaximumKPICalculationStrategyTest {

@Test
fun calculateEmpty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import de.fraunhofer.iem.spha.model.kpi.hierarchy.KpiNode
import kotlin.test.Test
import kotlin.test.assertEquals

class WeightedWeightedMinimumKPICalculationStrategyTest {
class WeightedMinimumKPICalculationStrategyTest {

@Test
fun calculateEmpty() {
Expand Down

0 comments on commit 68815d1

Please sign in to comment.