#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
 | 
			
		||||
 | 
			
		||||
class FunctionalCustomTimer(studyTime: Int): FunctionalTimer(studyTime) {
 | 
			
		||||
class FunctionalCustomTimer(studyTime: Int) : FunctionalTimer(studyTime) {
 | 
			
		||||
 | 
			
		||||
    override fun tick() {
 | 
			
		||||
        if (time.time == 0) {
 | 
			
		||||
            view = "Done!"
 | 
			
		||||
            view = DONE
 | 
			
		||||
        } else {
 | 
			
		||||
            time.minOne()
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
class FunctionalEndlessTimer() : FunctionalTimer(0){
 | 
			
		||||
class FunctionalEndlessTimer() : FunctionalTimer(0) {
 | 
			
		||||
 | 
			
		||||
    override fun hasEnded(): Boolean {
 | 
			
		||||
        return false
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,25 +3,25 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		|||
class FunctionalPomodoroTimer(
 | 
			
		||||
    private var studyTime: Int,
 | 
			
		||||
    private var breakTime: Int, repeats: Int
 | 
			
		||||
): FunctionalTimer(studyTime) {
 | 
			
		||||
) : FunctionalTimer(studyTime) {
 | 
			
		||||
 | 
			
		||||
    private var breaksRemaining = repeats
 | 
			
		||||
    private var isInBreak = false
 | 
			
		||||
    var breaksRemaining = repeats
 | 
			
		||||
    var isInBreak = false
 | 
			
		||||
 | 
			
		||||
    override fun tick() {
 | 
			
		||||
        if (time.time == 0 && breaksRemaining == 0){
 | 
			
		||||
            view = "Done!"
 | 
			
		||||
        if (time.time == 0 && breaksRemaining == 0) {
 | 
			
		||||
            view = DONE
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (time.time == 0) {
 | 
			
		||||
            if (isInBreak) {
 | 
			
		||||
                breaksRemaining--
 | 
			
		||||
                view = "Focus! ($breaksRemaining breaks remaining)"
 | 
			
		||||
                view = FOCUS_REMAINING(breaksRemaining)
 | 
			
		||||
                time.time = studyTime
 | 
			
		||||
            } else {
 | 
			
		||||
                view = "Take a break!"
 | 
			
		||||
                time.time =breakTime
 | 
			
		||||
                view = BREAK
 | 
			
		||||
                time.time = breakTime
 | 
			
		||||
            }
 | 
			
		||||
            isInBreak = !isInBreak
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@ package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		|||
 | 
			
		||||
abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		||||
    val time: Time = Time(initialValue)
 | 
			
		||||
    var view: String = "Focus"
 | 
			
		||||
    var view: String = FOCUS
 | 
			
		||||
 | 
			
		||||
    fun getHoursMinutesSeconds(): HoursMinutesSeconds {
 | 
			
		||||
        return time.getAsHMS()
 | 
			
		||||
| 
						 | 
				
			
			@ -12,4 +12,11 @@ abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		|||
 | 
			
		||||
    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)" }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue