Added Unit-test to see if a supervisor is deleted or not + added unit-test to check that a supervisor not can supervise herself + test that the supervisor with available slots gets chosen.
This commit is contained in:
parent
40c3aad331
commit
c3e0bfb3a0
@ -13,10 +13,7 @@ import se.su.dsv.scipro.data.dao.interfaces.LanguageDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.RoleDao;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||
import se.su.dsv.scipro.data.dataobjects.Language;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.data.dataobjects.User;
|
||||
import se.su.dsv.scipro.data.dataobjects.*;
|
||||
import se.su.dsv.scipro.match.Matcher.Result;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.*;
|
||||
import se.su.dsv.scipro.match.dataobject.*;
|
||||
@ -61,6 +58,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Autowired
|
||||
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||
|
||||
|
||||
private List<ProjectIdea> unmatchedProjectIdeas;
|
||||
private List<Availability> supervisorAvailability;
|
||||
private Weights weights;
|
||||
@ -111,6 +109,19 @@ public class TestGreedyMatchingAlgorithm {
|
||||
keywordTypeWord = keywordTypeDao.save(new KeywordType("Word"));
|
||||
}
|
||||
|
||||
private void addKeyWords(final Employee supervisor, final ProjectIdea projectIdea, final Keyword keyword) {
|
||||
supervisor.getKeywords().getAll().add(keyword);
|
||||
projectIdea.getKeywords().getAll().add(keyword);
|
||||
}
|
||||
|
||||
private Keyword createKeyword(final KeywordType keyWordType , final String keyWordName, final boolean deleted) {
|
||||
Keyword keyword = new Keyword();
|
||||
keyword.setType(keyWordType);
|
||||
keyword.setKeyword(keyWordName);
|
||||
keyword.setDeleted(deleted);
|
||||
return keywordDao.save(keyword);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
supervisorAvailability = new ArrayList<Availability>();
|
||||
@ -135,7 +146,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
masterProjectIdea = createProjectIdea(masterProjectClass, applicationPeriod);
|
||||
}
|
||||
|
||||
|
||||
/* because of the rollback annotations in the test, there is no need to clear keywords of a supervisor or a projectIdea, set in a previous test, */
|
||||
private void clearOldData() {
|
||||
masterSupervisor.getKeywords().getAll().clear();
|
||||
masterProjectIdea.getKeywords().getAll().clear();
|
||||
@ -144,7 +155,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a master supervisor should be able to handle master project ideas */
|
||||
/* a master supervisor can handle master project ideas */
|
||||
public void testMasterSupervisor() {
|
||||
runFirstTest(masterSupervisor, masterProjectClass, masterProjectIdea);
|
||||
}
|
||||
@ -152,7 +163,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a bachelor supervisor should be able to handle bachelor project Ideas */
|
||||
/* a bachelor supervisor can handle bachelor project Ideas */
|
||||
public void testBachelorSupervisor() {
|
||||
runFirstTest(bachelorSupervisor, bachelorProjectClass, bachelorProjectIdea);
|
||||
}
|
||||
@ -160,7 +171,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a masterSupervisor can also handle bachelorProjectIdeas */
|
||||
/* a masterSupervisor can handle bachelorProjectIdeas */
|
||||
public void testMasterSupervisor_v2() {
|
||||
runFirstTest(masterSupervisor, masterProjectClass, bachelorProjectIdea);
|
||||
}
|
||||
@ -179,11 +190,10 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* no matches should be found, because a bachelorSupervisor cannot handle masterProjectIdeas */
|
||||
/* a bachelorSupervisor cannot handle masterProjectIdeas */
|
||||
public void testNoMatches() {
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
|
||||
unmatchedProjectIdeas.add(masterProjectIdea);
|
||||
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
assertTrue(result.matches.size() == 0);
|
||||
assertTrue(result.unmatched.size() == 1);
|
||||
@ -194,15 +204,26 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Rollback
|
||||
/* a bachelor supervisor should NOT be able to handle a rejected (bachelor) projectIdea */
|
||||
public void testRejectedProjectIdea() {
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
|
||||
addRejectedMatch(bachelorSupervisor, bachelorProjectIdea);
|
||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||
runSecondTest(bachelorSupervisor, bachelorProjectClass, bachelorProjectIdea);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a master supervisor should NOT be able to handle a rejected (bachelor) projectIdea */
|
||||
public void testRejectedProjectIdea_v2() {
|
||||
runSecondTest(masterSupervisor, masterProjectClass, bachelorProjectIdea);
|
||||
}
|
||||
|
||||
private void runSecondTest(final Employee supervisor, final ProjectClass projectClass, final ProjectIdea projectIdea) {
|
||||
addRejectedMatch(supervisor, projectIdea); // adds a rejected match to the projectIdea
|
||||
supervisorAvailability.add(new Availability(supervisor, 0L, 1, projectClass));
|
||||
unmatchedProjectIdeas.add(projectIdea);
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
assertTrue(result.matches.size() == 0);
|
||||
assertTrue(result.unmatched.size() == 1);
|
||||
}
|
||||
|
||||
|
||||
private void addRejectedMatch(final Employee supervisor, final ProjectIdea projectIdea) {
|
||||
Match rejectedMatch = new Match();
|
||||
rejectedMatch.setStatus(Match.Status.REJECTED);
|
||||
@ -212,28 +233,16 @@ public class TestGreedyMatchingAlgorithm {
|
||||
rejectedMatch = matchDao.save(rejectedMatch);
|
||||
projectIdea.getMatchHistory().add(rejectedMatch);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a master supervisor should NOT be able to handle a rejected (bachelor) projectIdea */
|
||||
public void testRejectedProjectIdea_v2() {
|
||||
supervisorAvailability.add(new Availability(masterSupervisor, 0L, 1, masterProjectClass));
|
||||
addRejectedMatch(masterSupervisor, bachelorProjectIdea);
|
||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
assertTrue(result.matches.size() == 0);
|
||||
assertTrue(result.unmatched.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a bachelor supervisor should be able to handle a projectIdea which has been rejected by another (bachelor) supervisor */
|
||||
/* a bachelor supervisor can handle a projectIdea which has been rejected by another (bachelor) supervisor, even if the other supervisor has a higher score */
|
||||
public void testRejectByOtherSupervisor() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
|
||||
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "test unit", false)); // 3
|
||||
addRejectedMatch(bachelorSupervisor2, bachelorProjectIdea);
|
||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
@ -245,7 +254,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a preferred supervisor should be chosen prior to another supervisor */
|
||||
/* a preferred bachelor supervisor should be chosen prior to another bachelor supervisor */
|
||||
public void testPreferredSupervisor() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
|
||||
@ -277,19 +286,6 @@ public class TestGreedyMatchingAlgorithm {
|
||||
assertTrue(result.unmatched.size() == 0);
|
||||
}
|
||||
|
||||
private void addKeyWords(final Employee supervisor, final ProjectIdea projectIdea, final Keyword keyword) {
|
||||
supervisor.getKeywords().getAll().add(keyword);
|
||||
projectIdea.getKeywords().getAll().add(keyword);
|
||||
}
|
||||
|
||||
private Keyword createKeyword(final KeywordType keyWordType , final String keyWordName, final boolean deleted) {
|
||||
Keyword keyword = new Keyword();
|
||||
keyword.setType(keyWordType);
|
||||
keyword.setKeyword(keyWordName);
|
||||
keyword.setDeleted(deleted);
|
||||
return keywordDao.save(keyword);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
@ -314,7 +310,6 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* keywords of 6 points should supersede keywords of 3 points */
|
||||
/* because of the rollback annotation, there is no need to clear keywords of a supervisor or a projectIdea set in a previous test, */
|
||||
public void testHighestScore_v2() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
addKeyWords(bachelorSupervisor, bachelorProjectIdea, createKeyword(keywordTypeWord, "test unit", false)); // 3
|
||||
@ -334,8 +329,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* deleted keywords of 6 points should NOT supersede valid keywords of 3 points */
|
||||
/* because of the rollback annotation, there is no need to clear keywords of a supervisor or a projectIdea set in a previous test, */
|
||||
public void testHighestScoreWhenDeleted() {
|
||||
public void testHighestScore_v3() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
addKeyWords(bachelorSupervisor, bachelorProjectIdea, createKeyword(keywordTypeWord, "test unit", false)); // 3
|
||||
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "UML", true)); // 3
|
||||
@ -354,8 +348,7 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* the preferred LANGUAGE of the project idea should determine even when two supervisors NOT have the same score */
|
||||
/* because of the rollback annotation, there is no need to clear keywords of a supervisor or a projectIdea set in a previous test, */
|
||||
public void testPreferredLanguageShouldDetermine() {
|
||||
public void testPreferredLanguage() {
|
||||
Set<Language> languageSet = new HashSet<Language>();
|
||||
Language language_sv = languageDao.save(new Language("Swedish"));
|
||||
languageSet.add(language_sv);
|
||||
@ -363,7 +356,6 @@ public class TestGreedyMatchingAlgorithm {
|
||||
|
||||
bachelorSupervisor.getCapabilities().getLanguages().clear();
|
||||
bachelorSupervisor.getCapabilities().getLanguages().add(languageDao.save(new Language("English")));
|
||||
|
||||
bachelorProjectIdea.getLanguages().clear();
|
||||
bachelorProjectIdea.getLanguages().add(language_sv);
|
||||
bachelorProjectIdea.setPreferredSupervisor(bachelorSupervisor); // 15
|
||||
@ -385,19 +377,60 @@ public class TestGreedyMatchingAlgorithm {
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* the both supervisors should be fetched when they have the same score regarding keywords */
|
||||
/* because of the rollback annotation, there is no need to clear keywords of a supervisor or a projectIdea set in a previous test, */
|
||||
public void bothSupervisorsShouldBeFetchedWhenScoresAreEqual() {
|
||||
/* the supervisor with the most "slots" should be chosen when two supervisors have the same score and both are compatible (matches the criteria in
|
||||
* the method isPossibleSupervisor) */
|
||||
public void testSelectHighestAvailability() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
addKeyWords(bachelorSupervisor, bachelorProjectIdea, createKeyword(keywordTypeWord, "Design", false)); // 3
|
||||
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "UML", false)); // 3
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass)); // supervisor, numMatched, numCapable, project class
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor, 1L, 1, bachelorProjectClass)); // availability = numCapable - numMatched
|
||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
assertTrue(result.matches.size() > 0);
|
||||
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
|
||||
assertTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor2));
|
||||
assertTrue(result.unmatched.size() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a supervisor should not be chosen if he/she is "deleted" */
|
||||
public void testForDeletedSupervisor() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
bachelorSupervisor2.setDeleted(true);
|
||||
|
||||
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "UML", false)); // 3
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
|
||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
assertTrue(result.matches.size() > 0);
|
||||
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
|
||||
assertTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor));
|
||||
assertTrue(result.unmatched.size() == 0);
|
||||
}
|
||||
|
||||
//isTrue(result.matches.size() == 2); // WHY DOES THIS TEST BREAK?????
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
/* a supervisor cannot be supervisor to herself */
|
||||
public void testSupervisorCannotHandleHerself() {
|
||||
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg", languages);
|
||||
Role role = new Student();
|
||||
role.setUser(bachelorSupervisor2.getUser());
|
||||
role = roleDao.save(role);
|
||||
bachelorProjectIdea.getAuthors().add((Student) role);
|
||||
|
||||
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "UML", false)); // 3
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
|
||||
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
|
||||
unmatchedProjectIdeas.add(bachelorProjectIdea);
|
||||
|
||||
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
|
||||
assertTrue(result.matches.size() > 0);
|
||||
assertTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
|
||||
assertTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor));
|
||||
assertTrue(result.unmatched.size() == 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user