From 55b35073c7adafed0722a6f4642cb7640bd6ba90 Mon Sep 17 00:00:00 2001 From: reyniersbram <55666730+reyniersbram@users.noreply.github.com> Date: Mon, 17 Apr 2023 17:50:09 +0200 Subject: [PATCH] #57 FunctionalCustomTimer unit test --- .../timer_functional/FunctionalTimer.kt | 2 +- .../studeez/FunctionalCustomTimerUnitTest.kt | 38 +++++++++++++++++++ .../sel/studeez/FunctionalTimerUnitTest.kt | 25 ++++++++++++ .../java/be/ugent/sel/studeez/TimeUnitTest.kt | 4 +- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 app/src/test/java/be/ugent/sel/studeez/FunctionalCustomTimerUnitTest.kt create mode 100644 app/src/test/java/be/ugent/sel/studeez/FunctionalTimerUnitTest.kt diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt index 5d06207..dd01924 100644 --- a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt @@ -1,7 +1,7 @@ package be.ugent.sel.studeez.data.local.models.timer_functional abstract class FunctionalTimer(initialValue: Int) { - protected val time: Time = Time(initialValue) + val time: Time = Time(initialValue) var view: String = "Focus" fun getHoursMinutesSeconds(): HoursMinutesSeconds { diff --git a/app/src/test/java/be/ugent/sel/studeez/FunctionalCustomTimerUnitTest.kt b/app/src/test/java/be/ugent/sel/studeez/FunctionalCustomTimerUnitTest.kt new file mode 100644 index 0000000..9a875cd --- /dev/null +++ b/app/src/test/java/be/ugent/sel/studeez/FunctionalCustomTimerUnitTest.kt @@ -0,0 +1,38 @@ +package be.ugent.sel.studeez + +import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer +import org.junit.Assert + +class FunctionalCustomTimerUnitTest: FunctionalTimerUnitTest() { + override fun setup() { + timer = FunctionalCustomTimer(time) + } + + override fun testOneTick() { + timer.tick() + Assert.assertEquals( + time - 1, + timer.time.time, + ) + } + + override fun multipleTicks() { + val n = 10 + for (i in 1 .. n) { + timer.tick() + } + Assert.assertEquals( + time - n, + timer.time.time, + ) + } + + override fun testEnded() { + timer = FunctionalCustomTimer(0) + timer.tick() + Assert.assertEquals( + "Done!", + timer.view + ) + } +} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/sel/studeez/FunctionalTimerUnitTest.kt b/app/src/test/java/be/ugent/sel/studeez/FunctionalTimerUnitTest.kt new file mode 100644 index 0000000..996dae5 --- /dev/null +++ b/app/src/test/java/be/ugent/sel/studeez/FunctionalTimerUnitTest.kt @@ -0,0 +1,25 @@ +package be.ugent.sel.studeez + +import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer +import org.junit.Before +import org.junit.Test + +abstract class FunctionalTimerUnitTest { + protected lateinit var timer: FunctionalTimer + private val hours = 4 + private val minutes = 20 + private val seconds = 39 + protected val time = seconds + minutes * 60 + hours * 60 * 60 + + @Before + abstract fun setup() + + @Test + abstract fun testOneTick() + + @Test + abstract fun multipleTicks() + + @Test + abstract fun testEnded() +} \ No newline at end of file diff --git a/app/src/test/java/be/ugent/sel/studeez/TimeUnitTest.kt b/app/src/test/java/be/ugent/sel/studeez/TimeUnitTest.kt index 567ef18..f15c821 100644 --- a/app/src/test/java/be/ugent/sel/studeez/TimeUnitTest.kt +++ b/app/src/test/java/be/ugent/sel/studeez/TimeUnitTest.kt @@ -58,7 +58,7 @@ class TimeUnitTest { @Test fun minMultiple() { val n = 10 - for (i in 1..n) { + for (i in 1 .. n) { time.minOne() } Assert.assertEquals( @@ -70,7 +70,7 @@ class TimeUnitTest { @Test fun plusMultiple() { val n = 10 - for (i in 1..n) { + for (i in 1 .. n) { time.plusOne() } Assert.assertEquals(