Skip to content
Snippets Groups Projects
Commit 89d3e81e authored by Florian Lambers's avatar Florian Lambers
Browse files
parents 845f4309 89ff7bd1
No related branches found
No related tags found
No related merge requests found
......@@ -4,9 +4,14 @@ import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
......@@ -76,20 +81,71 @@ public class PrioritizationService {
HashMap<String, Integer> testPriorities = this.sumTestPriorities();
this.setTestPriorities(testPriorities);
this.setTestOrder(testPriorities);
}
/**
* Function to set the TestOrder for JUNIT5
* @param testPriorities
*/
private void setTestOrder(HashMap<String, Integer> testPriorities)
{
HashMap<String, Integer> sortedList = PrioritizationService.sortByValue(testPriorities);
int i = 1;
for (String key : sortedList.keySet()){
System.out.println("[TEST] " + key + " with priority " + sortedList.get(key) + " [JUNIT] Order: " + i);
i++;
// TODO: dem Test die Order hinzufügen
// test.setOrder(i);
}
}
/**
* Function to sort a HashMap by Value
* @param hm
* @return
*/
public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm)
{
List<Map.Entry<String, Integer> > list = new LinkedList<Map.Entry<String, Integer> >(hm.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() {
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2)
{
return (o2.getValue()).compareTo(o1.getValue());
}
});
HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>();
for (Map.Entry<String, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
/**
* @param testPriorities
* @throws IOException
*/
private void setTestPriorities(HashMap<String, Integer> testPriorities) throws IOException
{
testPriorities.forEach((k, v) -> {
Test test = this.newDSL.getTest(k);
test.setPriority(v);
System.out.println("[PRIORITY] Set priority " + v + " for Test " + k);
});
this.newDSL.serialize();
}
/**
* @return
*/
private HashMap<String, Integer> sumTestPriorities() {
List<Test> tests = this.newDSL.getTests();
List<Flow> flows = this.newDSL.getFlows();
......
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