Added tests for matching supervisor to a project idea based on which keywords has been set.

This commit is contained in:
Tom Vahlman 2012-02-15 12:23:12 +01:00
parent 48299ca373
commit dfd29f4174

@ -69,6 +69,11 @@ public class TestGreedyMatchingAlgorithm {
private ProjectClass masterProjectClass;
private Set<Language> languages;
private KeywordType keywordTypeArea;
private KeywordType keywordTypeUnit; // does not exists
private KeywordType keywordTypeWord;
private Employee createSupervisor(final String firstName, final String lastName) {
Employee employee = new Employee();
User user = new User();
@ -96,8 +101,14 @@ public class TestGreedyMatchingAlgorithm {
private void createWeights() {
weights = new Weights();
weights.setKeywordPoints(3); // "Word"
weights.setResearchAreaPoints(100); // "Area" + "Unit" for unit
weights.setPreferredSupervisorPoints(5); // ??
weights.setResearchAreaPoints(10); // "Area" + "Unit"?? for unit
weights.setPreferredSupervisorPoints(15); // ??
}
private void setUpKeyWordTypes() {
keywordTypeArea = keywordTypeDao.save(new KeywordType("Area"));
keywordTypeUnit = keywordTypeDao.save(new KeywordType("Unit"));
keywordTypeWord = keywordTypeDao.save(new KeywordType("Word"));
}
private void addLanguage(final String name) {
@ -105,28 +116,12 @@ public class TestGreedyMatchingAlgorithm {
languages.add(language);
}
private ApplicationPeriod createApplicationPeriod() {
Calendar cal = Calendar.getInstance();cal.getTime();
final Date startDate = cal.getTime();
cal.add(Calendar.MONTH, 1);
final Date endDate = cal.getTime();
Set<ProjectClass> projectClassSet = new HashSet<ProjectClass>();
projectClassSet.add(bachelorProjectClass);
projectClassSet.add(masterProjectClass);
ApplicationPeriod appPeriod = new ApplicationPeriod();
appPeriod.setStartDate(startDate);
appPeriod.setEndDate(endDate);
appPeriod.setProjectClass(projectClassSet);
return applicationPeriodDao.save(appPeriod);
}
@Before
public void init() throws Exception {
supervisorAvailability = new ArrayList<Availability>();
unmatchedProjectIdeas = new ArrayList<ProjectIdea>();
createWeights();
//ProjectClass projectClass = projectClassDao.getProjectClass(ProjectClass.BACHELOR); // return NULL, the database is empty at the beginning of every test...
setUpKeyWordTypes();
languages = new HashSet<Language>();
addLanguage("Swedish");
addLanguage("English");
@ -235,11 +230,11 @@ public class TestGreedyMatchingAlgorithm {
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor));
}
// @Test
// @Transactional
// @Rollback
@Test
@Transactional
@Rollback
/* the preferred supervisor should be chosen prior to another supervisor, when the other test data is ok */
/*public void preferred_Supervisor() {
public void preferred_Supervisor() {
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg");
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
@ -249,14 +244,14 @@ public class TestGreedyMatchingAlgorithm {
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor2));
}*/
}
// @Test
// @Transactional
// @Rollback
@Test
@Transactional
@Rollback
/* a masterSupervisor should handle a master projectIdea even if the idea has a preferred bachelor supervisor */
/* public void preferredBachelorSupervisor_should_not_be_chosen_when_MasterSupervisorMasterProjectIdea() {
public void preferredBachelorSupervisor_should_not_be_chosen_when_MasterSupervisorMasterProjectIdea() {
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg");
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
supervisorAvailability.add(new Availability(masterSupervisor, 0L, 1, masterProjectClass));
@ -268,53 +263,57 @@ public class TestGreedyMatchingAlgorithm {
Assert.isTrue(result.matches.get(0).getSupervisor().equals(masterSupervisor));
Assert.isTrue(result.unmatched.size() == 0);
}
*/
// @Test
// @Transactional
// @Rollback
/* a keyword of 100 points should supersede a preferred supervisor of 5 points */
/* public void keywordShouldSupersedePreferredSupervisor() {
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg");
Keyword keyword = createKeyword("Area", "test area");
bachelorSupervisor2.getKeywords().getAll().add(keyword);
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
//bachelorProjectIdea.setPreferredSupervisor(bachelorSupervisor2);
bachelorProjectIdea.getKeywords().getAll().add(keyword);
unmatchedProjectIdeas.add(bachelorProjectIdea);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor));
}*/
private Keyword createKeyword(final String keyWordType, final String keyWordName) {
KeywordType researchArea = new KeywordType(keyWordType);
researchArea = keywordTypeDao.save(researchArea);
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) {
Keyword keyword = new Keyword();
keyword.setType(researchArea);
keyword.setType(keyWordType);
keyword.setKeyword(keyWordName);
return keywordDao.save(keyword);
}
/* @Test
@Test
@Transactional
@Rollback
*//* the supervisor with a keyword of 10 points should be chosen prior to the supervisor with a keyword of 5 points *//*
public void keywordSupervisorShouldSupersedePreferred() {
/* a keywords of 16 points should supersede a preferred supervisor of 15 points */
public void keywordsShouldSupersedePreferredSupervisor() {
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg");
Keyword keyword = createKeyword(KeywordTypeDao.TYPE.RESEARCH_AREA.toString());
bachelorSupervisor.getKeywords().getAll().add(keyword);
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeArea, "test area")); // 10
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "test unit")); // 3
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "Java")); // 3
// addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "UML")); // 3
// addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "Design")); // 3
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
bachelorProjectIdea.setPreferredSupervisor(bachelorSupervisor2);
bachelorProjectIdea.getKeywords().getAll().add(keyword);
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
bachelorProjectIdea.setPreferredSupervisor(bachelorSupervisor); // 15
unmatchedProjectIdeas.add(bachelorProjectIdea);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor2));
}
*/
@Test
@Transactional
@Rollback
/* a preferred supervisor of 15 points should supersede keywords of 13 points */
public void preferredSupervisorShouldSupersedeKeywords() {
Employee bachelorSupervisor2 = createSupervisor("David", "Hallberg");
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeArea, "test area")); // 10
addKeyWords(bachelorSupervisor2, bachelorProjectIdea, createKeyword(keywordTypeWord, "test unit")); // 3
supervisorAvailability.add(new Availability(bachelorSupervisor2, 0L, 1, bachelorProjectClass));
supervisorAvailability.add(new Availability(bachelorSupervisor, 0L, 1, bachelorProjectClass));
bachelorProjectIdea.setPreferredSupervisor(bachelorSupervisor); // 15
unmatchedProjectIdeas.add(bachelorProjectIdea);
Result result = new GreedyMatchingAlgorithm().match(supervisorAvailability, unmatchedProjectIdeas, weights);
Assert.notEmpty(result.matches);
Assert.isTrue(result.matches.get(0).getProjectIdea().equals(bachelorProjectIdea));
Assert.isTrue(result.matches.get(0).getSupervisor().equals(bachelorSupervisor));
}
}