This repository has been archived by the owner on Dec 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c5fe8a
commit b7ad33d
Showing
7 changed files
with
130 additions
and
54 deletions.
There are no files selected for viewing
33 changes: 30 additions & 3 deletions
33
src/com/maxwittig/reportgenerator/builder/PlainTextReportBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/com/maxwittig/reportgenerator/tests/builder/PlainTextReportBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.maxwittig.reportgenerator.tests.builder | ||
|
||
import com.maxwittig.reportgenerator.builder.PlainTextReportBuilder | ||
import com.maxwittig.reportgenerator.builder.ReportType | ||
import org.junit.Test | ||
|
||
|
||
class PlainTextReportBuilderTest : ReportBuilderTest() | ||
{ | ||
@Test | ||
fun dailyReportTest() | ||
{ | ||
val tasks = getRandomTimekeeperTaskArrayList() | ||
val reportBuilder = PlainTextReportBuilder(tasks, ReportType.DAILY, todaysDate = getRandomDateInTheYear()) | ||
println(reportBuilder.getReport()) | ||
|
||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/com/maxwittig/reportgenerator/tests/builder/ReportBuilderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.maxwittig.reportgenerator.tests.builder | ||
|
||
import com.maxwittig.reportgenerator.models.TimekeeperTask | ||
import java.io.File | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
|
||
abstract class ReportBuilderTest | ||
{ | ||
private val wordList : List<String> = File("data/wordlist.txt").readText().split("\n") | ||
|
||
protected fun getRandomTimekeeperTaskArrayList() : ArrayList<TimekeeperTask> | ||
{ | ||
val completeTaskList = ArrayList<TimekeeperTask>() | ||
var i = 0 | ||
while (i < 10000) | ||
{ | ||
i++ | ||
val startDate = getRandomDateInTheYear() | ||
val duration = getRandomDuration() | ||
val endDate = Date(startDate.time + duration) | ||
val task = TimekeeperTask(getRandomWordFromList(), getRandomWordFromList(), startDate, endDate, duration) | ||
completeTaskList.add(task) | ||
} | ||
completeTaskList.sort { task1, task2 -> task1.startTime.compareTo(task2.startTime) } | ||
return completeTaskList | ||
} | ||
|
||
protected fun getRandomWordFromList() : String | ||
{ | ||
return wordList[Random().nextInt(wordList.size)] | ||
} | ||
|
||
protected fun getRandomDateInTheYear() : Date | ||
{ | ||
val year = "2017" | ||
val format = SimpleDateFormat("yyyy") | ||
val yearDate = format.parse(year) | ||
val yearStartSeconds = yearDate.time | ||
val yearLengthMilliSeconds = 31557600000 | ||
val randomDateInMilliseconds = (Random().nextDouble()*(yearLengthMilliSeconds)).toLong() | ||
return Date(yearStartSeconds+randomDateInMilliseconds) | ||
} | ||
|
||
protected fun getRandomDuration() : Long | ||
{ | ||
return (Random().nextDouble()*(86400)).toLong() | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/com/maxwittig/reportgenerator/tests/builder/ReportTypeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.maxwittig.reportgenerator.tests.builder | ||
|
||
import com.maxwittig.reportgenerator.builder.ReportType | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import java.time.LocalDate | ||
|
||
class ReportTypeTest | ||
{ | ||
@Test | ||
fun getCurrentReportTypeTest() | ||
{ | ||
val yearlyDate = LocalDate.of(2016, 12, 31) //end of the year | ||
val monthlyDate = LocalDate.of(2016, 11, 30) //end of the month | ||
val sundayDate = LocalDate.of(2016, 12, 25) //sunday | ||
val dailyDate = LocalDate.of(2016, 1, 5) //nothing special | ||
assertEquals(ReportType.getCurrentReportType(true, true, true, localDate = yearlyDate), ReportType.YEARLY) | ||
assertEquals(ReportType.getCurrentReportType(true, true, true, localDate = monthlyDate), ReportType.MONTHLY) | ||
assertEquals(ReportType.getCurrentReportType(true, true, true, localDate = sundayDate), ReportType.WEEKLY) | ||
assertEquals(ReportType.getCurrentReportType(true, true, true, localDate = dailyDate), ReportType.DAILY) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters