#57 finish FunctionalTimer unit tests
This commit is contained in:
parent
e60a96429c
commit
2b68373230
8 changed files with 171 additions and 21 deletions
|
@ -1,10 +1,10 @@
|
||||||
package be.ugent.sel.studeez.data.local.models.timer_functional
|
package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
class FunctionalCustomTimer(studyTime: Int): FunctionalTimer(studyTime) {
|
class FunctionalCustomTimer(studyTime: Int) : FunctionalTimer(studyTime) {
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
if (time.time == 0) {
|
if (time.time == 0) {
|
||||||
view = "Done!"
|
view = DONE
|
||||||
} else {
|
} else {
|
||||||
time.minOne()
|
time.minOne()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package be.ugent.sel.studeez.data.local.models.timer_functional
|
package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
class FunctionalEndlessTimer() : FunctionalTimer(0){
|
class FunctionalEndlessTimer() : FunctionalTimer(0) {
|
||||||
|
|
||||||
override fun hasEnded(): Boolean {
|
override fun hasEnded(): Boolean {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -3,25 +3,25 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
class FunctionalPomodoroTimer(
|
class FunctionalPomodoroTimer(
|
||||||
private var studyTime: Int,
|
private var studyTime: Int,
|
||||||
private var breakTime: Int, repeats: Int
|
private var breakTime: Int, repeats: Int
|
||||||
): FunctionalTimer(studyTime) {
|
) : FunctionalTimer(studyTime) {
|
||||||
|
|
||||||
private var breaksRemaining = repeats
|
var breaksRemaining = repeats
|
||||||
private var isInBreak = false
|
var isInBreak = false
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
if (time.time == 0 && breaksRemaining == 0){
|
if (time.time == 0 && breaksRemaining == 0) {
|
||||||
view = "Done!"
|
view = DONE
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time.time == 0) {
|
if (time.time == 0) {
|
||||||
if (isInBreak) {
|
if (isInBreak) {
|
||||||
breaksRemaining--
|
breaksRemaining--
|
||||||
view = "Focus! ($breaksRemaining breaks remaining)"
|
view = FOCUS_REMAINING(breaksRemaining)
|
||||||
time.time = studyTime
|
time.time = studyTime
|
||||||
} else {
|
} else {
|
||||||
view = "Take a break!"
|
view = BREAK
|
||||||
time.time =breakTime
|
time.time = breakTime
|
||||||
}
|
}
|
||||||
isInBreak = !isInBreak
|
isInBreak = !isInBreak
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
|
||||||
|
|
||||||
abstract class FunctionalTimer(initialValue: Int) {
|
abstract class FunctionalTimer(initialValue: Int) {
|
||||||
val time: Time = Time(initialValue)
|
val time: Time = Time(initialValue)
|
||||||
var view: String = "Focus"
|
var view: String = FOCUS
|
||||||
|
|
||||||
fun getHoursMinutesSeconds(): HoursMinutesSeconds {
|
fun getHoursMinutesSeconds(): HoursMinutesSeconds {
|
||||||
return time.getAsHMS()
|
return time.getAsHMS()
|
||||||
|
@ -12,4 +12,11 @@ abstract class FunctionalTimer(initialValue: Int) {
|
||||||
|
|
||||||
abstract fun hasEnded(): Boolean
|
abstract fun hasEnded(): Boolean
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val FOCUS: String = "Focus"
|
||||||
|
const val DONE: String = "Done!"
|
||||||
|
const val BREAK: String = "Take a break!"
|
||||||
|
val FOCUS_REMAINING: (Int) -> String = { n -> "Focus! ($n breaks remaining)" }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,10 +1,11 @@
|
||||||
package be.ugent.sel.studeez
|
package be.ugent.sel.studeez
|
||||||
|
|
||||||
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
||||||
class FunctionalCustomTimerUnitTest: FunctionalTimerUnitTest() {
|
class FunctionalCustomTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
override fun setup() {
|
override fun setTimer() {
|
||||||
timer = FunctionalCustomTimer(time)
|
timer = FunctionalCustomTimer(time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ class FunctionalCustomTimerUnitTest: FunctionalTimerUnitTest() {
|
||||||
|
|
||||||
override fun multipleTicks() {
|
override fun multipleTicks() {
|
||||||
val n = 10
|
val n = 10
|
||||||
for (i in 1 .. n) {
|
for (i in 1..n) {
|
||||||
timer.tick()
|
timer.tick()
|
||||||
}
|
}
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
|
@ -31,7 +32,7 @@ class FunctionalCustomTimerUnitTest: FunctionalTimerUnitTest() {
|
||||||
timer = FunctionalCustomTimer(0)
|
timer = FunctionalCustomTimer(0)
|
||||||
timer.tick()
|
timer.tick()
|
||||||
Assert.assertEquals(
|
Assert.assertEquals(
|
||||||
"Done!",
|
FunctionalTimer.DONE,
|
||||||
timer.view
|
timer.view
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package be.ugent.sel.studeez
|
||||||
|
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
|
import org.junit.Assert
|
||||||
|
|
||||||
|
class FunctionalEndlessTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
|
override fun setTimer() {
|
||||||
|
timer = FunctionalEndlessTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun testOneTick() {
|
||||||
|
timer.tick()
|
||||||
|
Assert.assertEquals(
|
||||||
|
1,
|
||||||
|
timer.time.time
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun multipleTicks() {
|
||||||
|
val n = 10
|
||||||
|
for (i in 1..n) {
|
||||||
|
timer.tick()
|
||||||
|
}
|
||||||
|
Assert.assertEquals(
|
||||||
|
n,
|
||||||
|
timer.time.time
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun testEnded() {
|
||||||
|
val n = 1000
|
||||||
|
for (i in 1..n) {
|
||||||
|
timer.tick()
|
||||||
|
Assert.assertEquals(
|
||||||
|
FunctionalTimer.FOCUS,
|
||||||
|
timer.view
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,13 +6,21 @@ import org.junit.Test
|
||||||
|
|
||||||
abstract class FunctionalTimerUnitTest {
|
abstract class FunctionalTimerUnitTest {
|
||||||
protected lateinit var timer: FunctionalTimer
|
protected lateinit var timer: FunctionalTimer
|
||||||
private val hours = 4
|
protected open val hours = 4
|
||||||
private val minutes = 20
|
protected open val minutes = 20
|
||||||
private val seconds = 39
|
protected open val seconds = 39
|
||||||
protected val time = seconds + minutes * 60 + hours * 60 * 60
|
protected var time: Int = 0
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
abstract fun setup()
|
fun setup() {
|
||||||
|
time = seconds + minutes * 60 + hours * 60 * 60
|
||||||
|
setTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timer-property should be set to the right implementation in this method.
|
||||||
|
*/
|
||||||
|
abstract fun setTimer()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
abstract fun testOneTick()
|
abstract fun testOneTick()
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
package be.ugent.sel.studeez
|
||||||
|
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer
|
||||||
|
import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class FuntionalPomodoroTimerUnitTest : FunctionalTimerUnitTest() {
|
||||||
|
private val breakTime = 10
|
||||||
|
private val breaks = 2
|
||||||
|
override val hours = 0
|
||||||
|
override val minutes = 0
|
||||||
|
override val seconds = 10
|
||||||
|
private lateinit var pomodoroTimer: FunctionalPomodoroTimer
|
||||||
|
|
||||||
|
override fun setTimer() {
|
||||||
|
pomodoroTimer = FunctionalPomodoroTimer(time, breakTime, breaks)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun testOneTick() {
|
||||||
|
pomodoroTimer.tick()
|
||||||
|
Assert.assertEquals(
|
||||||
|
time - 1,
|
||||||
|
pomodoroTimer.time.time,
|
||||||
|
)
|
||||||
|
Assert.assertFalse(pomodoroTimer.isInBreak)
|
||||||
|
Assert.assertEquals(
|
||||||
|
breaks,
|
||||||
|
pomodoroTimer.breaksRemaining,
|
||||||
|
)
|
||||||
|
Assert.assertEquals(
|
||||||
|
FunctionalTimer.FOCUS,
|
||||||
|
pomodoroTimer.view,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun multipleTicks() {
|
||||||
|
val n = 10
|
||||||
|
for (i in 1..n) {
|
||||||
|
pomodoroTimer.tick()
|
||||||
|
}
|
||||||
|
Assert.assertEquals(
|
||||||
|
time - n,
|
||||||
|
pomodoroTimer.time.time
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun testEnded() {
|
||||||
|
pomodoroTimer = FunctionalPomodoroTimer(0, 0, 0)
|
||||||
|
pomodoroTimer.tick()
|
||||||
|
Assert.assertEquals(
|
||||||
|
FunctionalTimer.DONE,
|
||||||
|
pomodoroTimer.view,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun switchToBreak() {
|
||||||
|
for (i in 0..10) {
|
||||||
|
pomodoroTimer.tick()
|
||||||
|
}
|
||||||
|
Assert.assertTrue(pomodoroTimer.isInBreak)
|
||||||
|
Assert.assertEquals(
|
||||||
|
FunctionalTimer.BREAK,
|
||||||
|
pomodoroTimer.view
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun switchToStudying() {
|
||||||
|
for (i in 0..time) {
|
||||||
|
pomodoroTimer.tick()
|
||||||
|
}
|
||||||
|
Assert.assertTrue(pomodoroTimer.isInBreak)
|
||||||
|
Assert.assertEquals(
|
||||||
|
FunctionalTimer.BREAK,
|
||||||
|
pomodoroTimer.view
|
||||||
|
)
|
||||||
|
for (i in 0..breakTime) {
|
||||||
|
pomodoroTimer.tick()
|
||||||
|
}
|
||||||
|
Assert.assertFalse(pomodoroTimer.isInBreak)
|
||||||
|
val breaksRemaining = breaks - 1
|
||||||
|
Assert.assertEquals(
|
||||||
|
breaksRemaining,
|
||||||
|
pomodoroTimer.breaksRemaining
|
||||||
|
)
|
||||||
|
Assert.assertEquals(
|
||||||
|
FunctionalTimer.FOCUS_REMAINING(breaksRemaining),
|
||||||
|
pomodoroTimer.view
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue