Skip to content
Snippets Groups Projects
Commit 97335000 authored by Nikolaus Huber's avatar Nikolaus Huber
Browse files

refactorings in weightingfunction package

git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@11917 9e42b895-fcda-4063-8a3b-11be15eb1bbd
parent eeb628ac
No related branches found
No related tags found
No related merge requests found
package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import java.util.Random; import java.util.Random;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunctionCalculator;
import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.RandomWeightCalculator;
import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory; import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory;
import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic;
public class RandomWeightCalculatorTest { public class RandomWeightsWeightingFunctionTest {
IWeightingFunctionCalculator randomCalculator = new RandomWeightCalculator(); IWeightingFunction randomCalculator = new RandomWeightsWeightingFunction();
WeightedTactic wt = null; WeightedTactic wt = null;
@Before @Before
...@@ -33,13 +30,4 @@ public class RandomWeightCalculatorTest { ...@@ -33,13 +30,4 @@ public class RandomWeightCalculatorTest {
assertEquals(r.nextDouble(), randomCalculator.calculateWeight(wt),1.0); assertEquals(r.nextDouble(), randomCalculator.calculateWeight(wt),1.0);
assertEquals(0.0, wt.getDefaultWeight(), 0.0); assertEquals(0.0, wt.getDefaultWeight(), 0.0);
} }
@Test
public void testCalculateAndSetWeight() {
randomCalculator.updateWeight(wt);
assertNotSame(1.0, wt.getCurrentWeight());
assertEquals(0.0, wt.getDefaultWeight(), 0.0);
}
} }
...@@ -13,8 +13,8 @@ import org.junit.Test; ...@@ -13,8 +13,8 @@ import org.junit.Test;
import edu.kit.ipd.descartes.adaptation.AbstractTest; import edu.kit.ipd.descartes.adaptation.AbstractTest;
import edu.kit.ipd.descartes.adaptation.AdaptationControl; import edu.kit.ipd.descartes.adaptation.AdaptationControl;
import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunctionCalculator; import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunction;
import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSumCalculator; import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSum;
import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryModelLoader; import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryModelLoader;
import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory; import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory;
import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric; import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric;
...@@ -27,12 +27,12 @@ import edu.kit.ipd.descartes.perfdatarepo.PerfdatarepoFactory; ...@@ -27,12 +27,12 @@ import edu.kit.ipd.descartes.perfdatarepo.PerfdatarepoFactory;
import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository; import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository;
import edu.kit.ipd.descartes.perfdatarepo.Result; import edu.kit.ipd.descartes.perfdatarepo.Result;
public class WeightedSumCalculatorTest extends AbstractTest { public class WeightedSumWeightingFunctionTest extends AbstractTest {
private static final String PROP_TEST_PERF_DATA_REPO_XMI_FILE_PATH_NAME = "perfdatarepo.test"; private static final String PROP_TEST_PERF_DATA_REPO_XMI_FILE_PATH_NAME = "perfdatarepo.test";
private static final double NEW_WEIGHT = 99.8; private static final double NEW_WEIGHT = 99.8;
IWeightingFunctionCalculator weightedSum; IWeightingFunction weightedSum;
WeightedTactic wt = null; WeightedTactic wt = null;
WeightingFunction fun = null; WeightingFunction fun = null;
AdaptationControl control = null; AdaptationControl control = null;
...@@ -67,7 +67,7 @@ public class WeightedSumCalculatorTest extends AbstractTest { ...@@ -67,7 +67,7 @@ public class WeightedSumCalculatorTest extends AbstractTest {
fun.getWeightedMetrics().add(wmRespTime); fun.getWeightedMetrics().add(wmRespTime);
fun.getWeightedMetrics().add(wmUtil); fun.getWeightedMetrics().add(wmUtil);
weightedSum = new WeightedSumCalculator(fun); weightedSum = new WeightedSum(fun);
wt = AdaptationFactory.eINSTANCE.createWeightedTactic(); wt = AdaptationFactory.eINSTANCE.createWeightedTactic();
...@@ -114,13 +114,6 @@ public class WeightedSumCalculatorTest extends AbstractTest { ...@@ -114,13 +114,6 @@ public class WeightedSumCalculatorTest extends AbstractTest {
assertEquals(wt.getDefaultWeight(), 0.0, 0); assertEquals(wt.getDefaultWeight(), 0.0, 0);
} }
@Test
public void testCalculateAndSetWeight() {
weightedSum.updateWeight(wt);
assertEquals(NEW_WEIGHT, wt.getCurrentWeight(), 0.0);
assertEquals(wt.getDefaultWeight(), 0.0, 0);
}
@Test @Test
public void testImpact() { public void testImpact() {
Impact impact = loadImpactFromModel(); Impact impact = loadImpactFromModel();
...@@ -130,7 +123,7 @@ public class WeightedSumCalculatorTest extends AbstractTest { ...@@ -130,7 +123,7 @@ public class WeightedSumCalculatorTest extends AbstractTest {
WeightedTactic wt = AdaptationFactory.eINSTANCE.createWeightedTactic(); WeightedTactic wt = AdaptationFactory.eINSTANCE.createWeightedTactic();
wt.setLastImpact(impact); wt.setLastImpact(impact);
WeightedSumCalculator wSumCalc = new WeightedSumCalculator(testFunction); WeightedSum wSumCalc = new WeightedSum(testFunction);
for (MetricType metricType : metricTypes) { for (MetricType metricType : metricTypes) {
WeightedMetric wm = AdaptationFactory.eINSTANCE.createWeightedMetric(); WeightedMetric wm = AdaptationFactory.eINSTANCE.createWeightedMetric();
wm.setMetricType(metricType); wm.setMetricType(metricType);
......
...@@ -12,7 +12,7 @@ import org.eclipse.emf.common.util.URI; ...@@ -12,7 +12,7 @@ import org.eclipse.emf.common.util.URI;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightingFunctionHelper; import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSumWeightingFunctionHelper;
import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerfDataRepoConverter; import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerfDataRepoConverter;
import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryModelLoader; import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryModelLoader;
import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory; import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory;
...@@ -73,11 +73,11 @@ public class WeightingFunctionHelperTest { ...@@ -73,11 +73,11 @@ public class WeightingFunctionHelperTest {
public void testGetWeightForMetricType() { public void testGetWeightForMetricType() {
double weight = 0.0; double weight = 0.0;
MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME); MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME);
weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); weight = WeightedSumWeightingFunctionHelper.getWeightForMetricType(function, metricType);
assertEquals(Double.NaN, weight, 0.0); assertEquals(Double.NaN, weight, 0.0);
metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType); weight = WeightedSumWeightingFunctionHelper.getWeightForMetricType(function, metricType);
assertEquals(UTIL_WEIGHT, weight, 0.0); assertEquals(UTIL_WEIGHT, weight, 0.0);
} }
...@@ -87,12 +87,12 @@ public class WeightingFunctionHelperTest { ...@@ -87,12 +87,12 @@ public class WeightingFunctionHelperTest {
MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION); MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult(); Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult();
testValue = WeightingFunctionHelper.getValueForMetricType(metricType, emptyResult); testValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(metricType, emptyResult);
assertEquals(Double.NaN, testValue, 0); assertEquals(Double.NaN, testValue, 0);
Impact impact = perfDataRepo.getImpactHistory().get(0); Impact impact = perfDataRepo.getImpactHistory().get(0);
Result before = impact.getBefore(); Result before = impact.getBefore();
testValue = WeightingFunctionHelper.getValueForMetricType(metricType, before); testValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(metricType, before);
assertEquals(0.4, testValue, 0); assertEquals(0.4, testValue, 0);
} }
...@@ -140,7 +140,7 @@ public class WeightingFunctionHelperTest { ...@@ -140,7 +140,7 @@ public class WeightingFunctionHelperTest {
MetricValue v2 = i.next(); MetricValue v2 = i.next();
assertEquals(v1.getMetricType(), v2.getMetricType()); assertEquals(v1.getMetricType(), v2.getMetricType());
MetricValue v3 = i.next(); MetricValue v3 = i.next();
assertTrue(WeightingFunctionHelper.sameMetricType(v2, v3.getMetricType())); assertTrue(WeightedSumWeightingFunctionHelper.sameMetricType(v2, v3.getMetricType()));
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment