From 52cf136c56e0d7954bc92c5d65a1faea6c0c653d Mon Sep 17 00:00:00 2001 From: Nikolaus Huber <nikolaus.huber@uni-wuerzburg.de> Date: Tue, 18 Dec 2012 11:54:05 +0000 Subject: [PATCH] git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@9556 9e42b895-fcda-4063-8a3b-11be15eb1bbd --- .../util/WeightingFunctionHelperTest.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/util/WeightingFunctionHelperTest.java 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 new file mode 100644 index 00000000..751484f8 --- /dev/null +++ b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/util/WeightingFunctionHelperTest.java @@ -0,0 +1,87 @@ +package edu.kit.ipd.descartes.adaptation.util; + +import static org.junit.Assert.assertEquals; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.junit.Before; +import org.junit.Test; + +import edu.kit.ipd.descartes.adaptation.model.PerformanceDataRepositoryHandler; +import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory; +import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric; +import edu.kit.ipd.descartes.mm.adaptation.WeightingFunction; +import edu.kit.ipd.descartes.perfdatarepo.Impact; +import edu.kit.ipd.descartes.perfdatarepo.MetricType; +import edu.kit.ipd.descartes.perfdatarepo.PerfdatarepoFactory; +import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository; +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); + } + +} -- GitLab