Skip to content

Commit

Permalink
implemented main method working with test case received
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmob committed Jul 11, 2020
1 parent 8128386 commit f0eec87
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public List<ArrayList> sortJobsForScheduling(List<Job> jobsList, LocalDateTime i
validateTimeWindow(inicioJanelaDeExecucao, fimJanelaDeExecucao);

jobsList = sortListByDateAndFilter(jobsList, inicioJanelaDeExecucao, fimJanelaDeExecucao);
return null;

return createJobExecuteSequence(jobsList , inicioJanelaDeExecucao, fimJanelaDeExecucao);
}

LocalDateTime getValidDate(LocalDateTime receivedDate, LocalDateTime defaultDate) {
Expand Down Expand Up @@ -79,5 +80,34 @@ boolean conlusionInsideTimeWindow(Job job, LocalDateTime inicioJanelaDeExecucao,
return duration.toHours() > 0;
}

private List<ArrayList> createJobExecuteSequence(List<Job> jobsList, LocalDateTime inicioJanelaDeExecucao, LocalDateTime fimJanelaDeExecucao) {
ArrayList<ArrayList> expectedList = new ArrayList<>();
ArrayList<Long> longArray = new ArrayList<>();
long totalHoursForArray = 0;

for(Job job : jobsList){
if(jobFitsInsideArray(totalHoursForArray, job)){
longArray.add(job.getId());
totalHoursForArray += job.getTempoEstimado().toHours();
}else{
addArrayToExpectedList(expectedList, longArray);
longArray = new ArrayList<>();
longArray.add(job.getId());
}
}

addArrayToExpectedList(expectedList, longArray);

return expectedList;
}

private void addArrayToExpectedList(ArrayList<ArrayList> expectedList, ArrayList<Long> longArray) {
if (longArray.size() > 0) {
expectedList.add(longArray);
}
}

private boolean jobFitsInsideArray(long totalHoursForArray, Job job) {
return (totalHoursForArray + job.getTempoEstimado().toHours()) <= maxDurationHour.toHours();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,47 @@ void whenJobListWithConclusionOutSideTimeWindowThenFilter() throws Exception {

}

@Test
void givenTestCaseFromDocTest() throws TimeWindowException {
//given
jobsList = getJobsArrayMocked();

LocalDateTime sameTimeWindow = LocalDateTime.of(
2019,
Month.FEBRUARY,
10,
9,
0,
0);
//when
List<ArrayList> received = schedulingService.sortJobsForScheduling(jobsList, sameTimeWindow, null);

//then
assertEquals("[[1, 3], [2]]", received.toString());
}

@Test
void givenListWithNoValidJob() throws TimeWindowException {
//given
LocalDateTime jobDateTime = LocalDateTime.of(2019,
Month.NOVEMBER,
10,
12,
0,
0);

jobsList = new ArrayList<Job>(Arrays.asList(
new Job(4,"Importação de arquivos de fundos 2", jobDateTime, Duration.ofHours(27))
));

//when
List<ArrayList> received = schedulingService.sortJobsForScheduling(jobsList, null, null);

//then
assertEquals("[]", received.toString());
}


private List<Job> getJobsArrayMocked() {
jobsList = new ArrayList<Job>(Arrays.asList(
getJob1Mocked(),
Expand Down

0 comments on commit f0eec87

Please sign in to comment.