diff --git a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/util/WeightingFunctionHelperTest.java b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/util/WeightingFunctionHelperTest.java index 751484f850bfacf00fbce3e4bcbe59eafb680cd6..3bc75ef34ceb291174bbc0ca9d4e46ee57b69eea 100644 --- a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/util/WeightingFunctionHelperTest.java +++ b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/util/WeightingFunctionHelperTest.java @@ -19,69 +19,68 @@ import edu.kit.ipd.descartes.perfdatarepo.Result; public class WeightingFunctionHelperTest { - private static final String PERF_DATA_REPO_XMI_FILE = "../ExampleModels/Adaptation/PerformanceDataRepositoryDummy.xmi"; - private static final double UTIL_WEIGHT = 2.0d; - - PerformanceDataRepositoryHandler perfDataHandler = PerformanceDataRepositoryHandler.getInstance(); - PerformanceDataRepository perfDataRepo = null; - WeightingFunction function = null; - - private enum METRIC_TYPES { - UTILIZATION, - RESPONSE_TIME; - } - - private MetricType getTypeHelper(METRIC_TYPES mType) { - EList<MetricType> types = perfDataRepo.getMetricTypes(); - switch (mType) { - case UTILIZATION: - return types.get(0); - case RESPONSE_TIME: - return types.get(1); - default: - return null; - } - } - - @Before - public void setUp() throws Exception { - perfDataRepo = (PerformanceDataRepository) perfDataHandler.load(URI.createFileURI(PERF_DATA_REPO_XMI_FILE)); - MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); - - function = AdaptationFactory.eINSTANCE.createWeightingFunction(); - WeightedMetric wUtil = AdaptationFactory.eINSTANCE.createWeightedMetric(); - wUtil.setId("1"); - wUtil.setName("UtilizationMetricWeight"); - wUtil.setWeight(UTIL_WEIGHT); - wUtil.setMetricType(metricType); - function.getWeightedMetrics().add(wUtil); - } - - @Test - public void testGetWeightForMetricType() { - double weight = 0.0; - MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME); - weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); - assertEquals(Double.NaN, weight, 0.0); - - metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); - weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); - assertEquals(UTIL_WEIGHT, weight, 0.0); - } - - @Test - public void testGetValueForMetricType() { - double testValue = 0; - MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); - - Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult(); - testValue = WeightingFunctionHelper.getValueForMetricType(metricType, emptyResult); - assertEquals(Double.NaN, testValue, 0); - - Impact impact = perfDataRepo.getImpactHistory().get(0); - Result before = impact.getBefore(); - testValue = WeightingFunctionHelper.getValueForMetricType(metricType, before); - assertEquals(0.4, testValue, 0); - } + private static final String PERF_DATA_REPO_XMI_FILE = "../ExampleModels/Adaptation/PerformanceDataRepositoryDummy.xmi"; + private static final double UTIL_WEIGHT = 2.0d; + + private PerformanceDataRepositoryHandler perfDataHandler = PerformanceDataRepositoryHandler.getInstance(); + private PerformanceDataRepository perfDataRepo = null; + private WeightingFunction function = null; + + private enum METRIC_TYPES { + UTILIZATION, RESPONSE_TIME; + } + + private MetricType getTypeHelper(METRIC_TYPES mType) { + EList<MetricType> types = perfDataRepo.getMetricTypes(); + switch (mType) { + case UTILIZATION: + return types.get(0); + case RESPONSE_TIME: + return types.get(1); + default: + return null; + } + } + + @Before + public void setUp() throws Exception { + perfDataRepo = (PerformanceDataRepository) perfDataHandler.load(URI.createFileURI(PERF_DATA_REPO_XMI_FILE)); + MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); + + function = AdaptationFactory.eINSTANCE.createWeightingFunction(); + WeightedMetric wUtil = AdaptationFactory.eINSTANCE.createWeightedMetric(); + wUtil.setId("1"); + wUtil.setName("UtilizationMetricWeight"); + wUtil.setWeight(UTIL_WEIGHT); + wUtil.setMetricType(metricType); + function.getWeightedMetrics().add(wUtil); + } + + @Test + public void testGetWeightForMetricType() { + double weight = 0.0; + MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME); + weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); + assertEquals(Double.NaN, weight, 0.0); + + metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); + weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); + assertEquals(UTIL_WEIGHT, weight, 0.0); + } + + @Test + public void testGetValueForMetricType() { + double testValue = 0; + MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); + + Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult(); + testValue = WeightingFunctionHelper.getValueForMetricType(metricType, emptyResult); + assertEquals(Double.NaN, testValue, 0); + + Impact impact = perfDataRepo.getImpactHistory().get(0); + Result before = impact.getBefore(); + testValue = WeightingFunctionHelper.getValueForMetricType(metricType, before); + assertEquals(0.4, testValue, 0); + } } diff --git a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/weightingfunction/WeightedSumCalculatorTest.java b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/weightingfunction/WeightedSumCalculatorTest.java index 415aa698c3077eee5644f5fa5459f1509c12df24..37545cb3d44386fd50ff8094f7e243e4acb68bf1 100644 --- a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/weightingfunction/WeightedSumCalculatorTest.java +++ b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/weightingfunction/WeightedSumCalculatorTest.java @@ -51,17 +51,17 @@ public class WeightedSumCalculatorTest extends AbstractTest { MetricValue metric1ValueBefore = PerfdatarepoFactory.eINSTANCE.createMetricValue(); - metric1ValueBefore.setMetric(respTime); + metric1ValueBefore.setMetricType(respTime); metric1ValueBefore.setValue(100); MetricValue metric1ValueAfter = PerfdatarepoFactory.eINSTANCE.createMetricValue(); - metric1ValueAfter.setMetric(respTime); + metric1ValueAfter.setMetricType(respTime); metric1ValueAfter.setValue(50); MetricValue metric2ValueBefore = PerfdatarepoFactory.eINSTANCE.createMetricValue(); - metric2ValueBefore.setMetric(util); + metric2ValueBefore.setMetricType(util); metric2ValueBefore.setValue(0.6); MetricValue metric2ValueAfter = PerfdatarepoFactory.eINSTANCE.createMetricValue(); - metric2ValueAfter.setMetric(util); + metric2ValueAfter.setMetricType(util); metric2ValueAfter.setValue(0.8); Result before = PerfdatarepoFactory.eINSTANCE.createResult();