From 9733500041556b601eb890a3774e239e19155949 Mon Sep 17 00:00:00 2001
From: Nikolaus Huber <nikolaus.huber@uni-wuerzburg.de>
Date: Tue, 4 Jun 2013 14:06:41 +0000
Subject: [PATCH] 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
---
 ...> RandomWeightsWeightingFunctionTest.java} | 16 ++--------------
 ... => WeightedSumWeightingFunctionTest.java} | 19 ++++++-------------
 .../WeightingFunctionHelperTest.java          | 12 ++++++------
 3 files changed, 14 insertions(+), 33 deletions(-)
 rename edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/{RandomWeightCalculatorTest.java => RandomWeightsWeightingFunctionTest.java} (59%)
 rename edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/{WeightedSumCalculatorTest.java => WeightedSumWeightingFunctionTest.java} (91%)

diff --git a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightCalculatorTest.java b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightsWeightingFunctionTest.java
similarity index 59%
rename from edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightCalculatorTest.java
rename to edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightsWeightingFunctionTest.java
index a623a2c8..55666bc7 100644
--- a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightCalculatorTest.java
+++ b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/RandomWeightsWeightingFunctionTest.java
@@ -1,21 +1,18 @@
 package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
 
 import java.util.Random;
 
 import org.junit.Before;
 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.WeightedTactic;
 
-public class RandomWeightCalculatorTest {
+public class RandomWeightsWeightingFunctionTest {
 	
-	IWeightingFunctionCalculator randomCalculator = new RandomWeightCalculator();
+	IWeightingFunction randomCalculator = new RandomWeightsWeightingFunction();
 	WeightedTactic wt = null;
 
 	@Before
@@ -33,13 +30,4 @@ public class RandomWeightCalculatorTest {
 		assertEquals(r.nextDouble(), randomCalculator.calculateWeight(wt),1.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);
-	}
-
 }
diff --git a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculatorTest.java b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumWeightingFunctionTest.java
similarity index 91%
rename from edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculatorTest.java
rename to edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumWeightingFunctionTest.java
index 8e1cb880..f1ba253a 100644
--- a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculatorTest.java
+++ b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumWeightingFunctionTest.java
@@ -13,8 +13,8 @@ import org.junit.Test;
 
 import edu.kit.ipd.descartes.adaptation.AbstractTest;
 import edu.kit.ipd.descartes.adaptation.AdaptationControl;
-import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunctionCalculator;
-import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSumCalculator;
+import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.IWeightingFunction;
+import edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction.WeightedSum;
 import edu.kit.ipd.descartes.adaptation.model.perfdatarepo.PerformanceDataRepositoryModelLoader;
 import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory;
 import edu.kit.ipd.descartes.mm.adaptation.WeightedMetric;
@@ -27,12 +27,12 @@ import edu.kit.ipd.descartes.perfdatarepo.PerfdatarepoFactory;
 import edu.kit.ipd.descartes.perfdatarepo.PerformanceDataRepository;
 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 double NEW_WEIGHT = 99.8;
 	
-	IWeightingFunctionCalculator weightedSum;
+	IWeightingFunction weightedSum;
 	WeightedTactic wt = null;
 	WeightingFunction fun = null;
 	AdaptationControl control = null;
@@ -67,7 +67,7 @@ public class WeightedSumCalculatorTest extends AbstractTest {
 		fun.getWeightedMetrics().add(wmRespTime);
 		fun.getWeightedMetrics().add(wmUtil);
 		
-		weightedSum = new WeightedSumCalculator(fun);
+		weightedSum = new WeightedSum(fun);
 		
 		wt = AdaptationFactory.eINSTANCE.createWeightedTactic();
 		
@@ -114,13 +114,6 @@ public class WeightedSumCalculatorTest extends AbstractTest {
 		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
 	public void testImpact() {
 	    Impact impact = loadImpactFromModel();
@@ -130,7 +123,7 @@ public class WeightedSumCalculatorTest extends AbstractTest {
 	    WeightedTactic wt = AdaptationFactory.eINSTANCE.createWeightedTactic();
 
 	    wt.setLastImpact(impact);
-	    WeightedSumCalculator wSumCalc = new WeightedSumCalculator(testFunction);
+	    WeightedSum wSumCalc = new WeightedSum(testFunction);
 	    for (MetricType metricType : metricTypes) {
 	        WeightedMetric wm = AdaptationFactory.eINSTANCE.createWeightedMetric();
 	        wm.setMetricType(metricType);
diff --git a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightingFunctionHelperTest.java b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightingFunctionHelperTest.java
index 25cbf237..ae5434a4 100644
--- a/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightingFunctionHelperTest.java
+++ b/edu.kit.ipd.descartes.adaptation.test/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightingFunctionHelperTest.java
@@ -12,7 +12,7 @@ import org.eclipse.emf.common.util.URI;
 import org.junit.Before;
 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.PerformanceDataRepositoryModelLoader;
 import edu.kit.ipd.descartes.mm.adaptation.AdaptationFactory;
@@ -73,11 +73,11 @@ public class WeightingFunctionHelperTest {
     public void testGetWeightForMetricType() {
         double weight = 0.0;
         MetricType metricType = getTypeHelper(METRIC_TYPES.RESPONSE_TIME);
-        weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType);
+        weight = WeightedSumWeightingFunctionHelper.getWeightForMetricType(function, metricType);
         assertEquals(Double.NaN, weight, 0.0);
 
         metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
-        weight = WeightingFunctionHelper.getWeightForMetricType(function, metricType);
+        weight = WeightedSumWeightingFunctionHelper.getWeightForMetricType(function, metricType);
         assertEquals(UTIL_WEIGHT, weight, 0.0);
     }
 
@@ -87,12 +87,12 @@ public class WeightingFunctionHelperTest {
         MetricType metricType = getTypeHelper(METRIC_TYPES.UTILIZATION);
 
         Result emptyResult = PerfdatarepoFactory.eINSTANCE.createResult();
-        testValue = WeightingFunctionHelper.getValueForMetricType(metricType, emptyResult);
+        testValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(metricType, emptyResult);
         assertEquals(Double.NaN, testValue, 0);
 
         Impact impact = perfDataRepo.getImpactHistory().get(0);
         Result before = impact.getBefore();
-        testValue = WeightingFunctionHelper.getValueForMetricType(metricType, before);
+        testValue = WeightedSumWeightingFunctionHelper.getValueForMetricType(metricType, before);
         assertEquals(0.4, testValue, 0);
     }
     
@@ -140,7 +140,7 @@ public class WeightingFunctionHelperTest {
         MetricValue v2 = i.next();
         assertEquals(v1.getMetricType(), v2.getMetricType());
         MetricValue v3 = i.next();
-        assertTrue(WeightingFunctionHelper.sameMetricType(v2, v3.getMetricType()));
+        assertTrue(WeightedSumWeightingFunctionHelper.sameMetricType(v2, v3.getMetricType()));
     }
 
 }
-- 
GitLab