From b2970c8fc90b14ff7e80f4c11fcb24a02a17ac4a Mon Sep 17 00:00:00 2001 From: Jan-Niclas Struewer <j.n.struewer@gmail.com> Date: Fri, 9 Aug 2024 09:25:02 +0200 Subject: [PATCH] test: added test for nested weight calculation --- .../kpiCalculator/core/KpiCalculatorTest.kt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt b/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt index e80a516b..1d829a9f 100644 --- a/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt +++ b/kpi-calculator/core/src/test/kotlin/de/fraunhofer/iem/kpiCalculator/core/KpiCalculatorTest.kt @@ -193,4 +193,57 @@ class KpiCalculatorTest { fail() } } + + @Test + fun calculateAggregationKpisIncompleteMixedKindsNested() { + val rawValueKpis = listOf( + RawValueKpi(kind = KpiId.VULNERABILITY_SCORE, score = 80), + RawValueKpi(kind = KpiId.VULNERABILITY_SCORE, score = 90), + ) + + val root = KpiNode( + kpiId = KpiId.ROOT, strategyType = KpiStrategyId.AGGREGATION_STRATEGY, children = listOf( + KpiEdge( + target = KpiNode( + kpiId = KpiId.MAXIMAL_VULNERABILITY, + strategyType = KpiStrategyId.MAXIMUM_STRATEGY, + children = listOf( + KpiEdge( + target = KpiNode( + kpiId = KpiId.VULNERABILITY_SCORE, + strategyType = KpiStrategyId.RAW_VALUE_STRATEGY, + children = listOf() + ), + weight = 1.0 + ), + ) + ), + weight = 0.5 + ), + KpiEdge( + target = KpiNode( + kpiId = KpiId.SAST_USAGE, + strategyType = KpiStrategyId.RAW_VALUE_STRATEGY, + children = listOf() + ), + weight = 0.5 + ) + ) + ) + val hierarchy = KpiHierarchy.create(root) + + val res = KpiCalculator.calculateKpis(hierarchy, rawValueKpis) + val result = res.rootNode.kpiResult + + if (result is KpiCalculationResult.Incomplete) { + assertEquals(90, result.score) + val sastResult = res.rootNode.children.find { it.target.kpiId == KpiId.SAST_USAGE } ?: fail() + assertEquals(0.0, sastResult.actualWeight) + val vulnerabilityEdges = res.rootNode.children.filter { it.target.kpiId == KpiId.MAXIMAL_VULNERABILITY } + assertEquals(vulnerabilityEdges.first().actualWeight, 1.0) + assertEquals(vulnerabilityEdges.first().plannedWeight, 0.5) + } else { + fail() + } + } } -- GitLab