Refactored duplicate code in test.

This commit is contained in:
Tom Vahlman 2012-02-11 19:24:09 +01:00
parent 4cd13c739c
commit 6e5fddd656

@ -112,17 +112,26 @@ public class TestGreedyMatchingAlgorithm {
weights.setPreferredSupervisorPoints(10);
}
private void setSupervisorAvailability(final Employee supervisor, final ProjectClass projectClass) {
Availability availability = new Availability(supervisor, 0L, 1, projectClass);
supervisorAvailability.add(availability);
}
private Result runAlgorithm(final ProjectIdea projectIdea) {
GreedyMatchingAlgorithm matchAlgorithm = new GreedyMatchingAlgorithm();
unmatchedProjectIdeas.add(projectIdea);
return matchAlgorithm.match(supervisorAvailability, unmatchedProjectIdeas, weights);
}
@Test
@Transactional
@Rollback
/* Make a match based on language, project class and if the supervisor has rejected the project idea previously or not */
public void testMatchMasterThesisAndMasterSupervisor() {
Availability availability = new Availability(masterSupervisor, 0L, 1, masterProjectClass);
supervisorAvailability.add(availability);
unmatchedProjectIdeas.add(masterProjectIdea);
GreedyMatchingAlgorithm matchAlgorithm = new GreedyMatchingAlgorithm();
Result result = matchAlgorithm.match(supervisorAvailability, unmatchedProjectIdeas, weights);
setSupervisorAvailability(masterSupervisor, masterProjectClass);
Result result = runAlgorithm(masterProjectIdea);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(masterProjectIdea));
Assert.isTrue(result.unmatched.size() == 0);
@ -132,12 +141,8 @@ public class TestGreedyMatchingAlgorithm {
@Transactional
@Rollback
public void testMatchBachelorThesisAndMasterSupervisor() {
Availability availability = new Availability(masterSupervisor, 0L, 1, masterProjectClass);
supervisorAvailability.add(availability);
unmatchedProjectIdeas.add(bachelorProjectIdea);
GreedyMatchingAlgorithm matchAlgorithm = new GreedyMatchingAlgorithm();
Result result = matchAlgorithm.match(supervisorAvailability, unmatchedProjectIdeas, weights);
setSupervisorAvailability(masterSupervisor, masterProjectClass);
Result result = runAlgorithm(bachelorProjectIdea);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
Assert.isTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
@ -148,12 +153,8 @@ public class TestGreedyMatchingAlgorithm {
@Transactional
@Rollback
public void testMatchBachelorThesisAndBachelorSupervisor() {
Availability availability = new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass);
supervisorAvailability.add(availability);
unmatchedProjectIdeas.add(bachelorProjectIdea);
GreedyMatchingAlgorithm matchAlgorithm = new GreedyMatchingAlgorithm();
Result result = matchAlgorithm.match(supervisorAvailability, unmatchedProjectIdeas, weights);
setSupervisorAvailability(bachelorSupervisor, bachelorProjectClass);
Result result = runAlgorithm(bachelorProjectIdea);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor));
@ -164,12 +165,8 @@ public class TestGreedyMatchingAlgorithm {
@Transactional
@Rollback
public void testMatchMasterThesisAndBachelorSupervisor() {
Availability availability = new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass);
supervisorAvailability.add(availability);
unmatchedProjectIdeas.add(masterProjectIdea);
GreedyMatchingAlgorithm matchAlgorithm = new GreedyMatchingAlgorithm();
Result result = matchAlgorithm.match(supervisorAvailability, unmatchedProjectIdeas, weights);
setSupervisorAvailability(bachelorSupervisor, bachelorProjectClass);
Result result = runAlgorithm(masterProjectIdea);
Assert.notEmpty(result.unmatched);
Assert.isTrue(result.matches.size() == 0);
}
@ -185,10 +182,8 @@ public class TestGreedyMatchingAlgorithm {
supervisorAvailability.add(availability1);
supervisorAvailability.add(availability2);
bachelorProjectIdea.setPreferredSupervisor(bachelorSupervisor2);
unmatchedProjectIdeas.add(bachelorProjectIdea);
GreedyMatchingAlgorithm matchAlgorithm = new GreedyMatchingAlgorithm();
Result result = matchAlgorithm.match(supervisorAvailability, unmatchedProjectIdeas, weights);
Result result = runAlgorithm(bachelorProjectIdea);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor2));
}