Move test sources from jvmTest to commonTest for KMP migration
This commit is contained in:
parent
22d289d6cb
commit
232be1440e
@ -27,8 +27,8 @@ import org.isoron.platform.time.getToday
|
|||||||
import org.isoron.platform.time.getWeekdaySequence
|
import org.isoron.platform.time.getWeekdaySequence
|
||||||
import org.isoron.platform.time.resetToday
|
import org.isoron.platform.time.resetToday
|
||||||
import org.isoron.platform.time.setToday
|
import org.isoron.platform.time.setToday
|
||||||
import org.junit.Assert.assertArrayEquals
|
import kotlin.test.Test
|
||||||
import org.junit.Test
|
import kotlin.test.assertContentEquals
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@ -102,22 +102,22 @@ class DatesTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testCountWeekdayOccurrencesInMonth() {
|
fun testCountWeekdayOccurrencesInMonth() {
|
||||||
// February 2018 (28 days, starts on Thursday)
|
// February 2018 (28 days, starts on Thursday)
|
||||||
assertArrayEquals(
|
assertContentEquals(
|
||||||
arrayOf(4, 4, 4, 4, 4, 4, 4),
|
arrayOf(4, 4, 4, 4, 4, 4, 4),
|
||||||
countWeekdayOccurrencesInMonth(LocalDate(2018, 2, 1))
|
countWeekdayOccurrencesInMonth(LocalDate(2018, 2, 1))
|
||||||
)
|
)
|
||||||
// February 2020 (leap, 29 days, starts on Saturday)
|
// February 2020 (leap, 29 days, starts on Saturday)
|
||||||
assertArrayEquals(
|
assertContentEquals(
|
||||||
arrayOf(5, 4, 4, 4, 4, 4, 4),
|
arrayOf(5, 4, 4, 4, 4, 4, 4),
|
||||||
countWeekdayOccurrencesInMonth(LocalDate(2020, 2, 1))
|
countWeekdayOccurrencesInMonth(LocalDate(2020, 2, 1))
|
||||||
)
|
)
|
||||||
// April 2020 (30 days, starts on Wednesday)
|
// April 2020 (30 days, starts on Wednesday)
|
||||||
assertArrayEquals(
|
assertContentEquals(
|
||||||
arrayOf(4, 4, 4, 4, 5, 5, 4),
|
arrayOf(4, 4, 4, 4, 5, 5, 4),
|
||||||
countWeekdayOccurrencesInMonth(LocalDate(2020, 4, 1))
|
countWeekdayOccurrencesInMonth(LocalDate(2020, 4, 1))
|
||||||
)
|
)
|
||||||
// August 2020 (31 days, starts on Saturday)
|
// August 2020 (31 days, starts on Saturday)
|
||||||
assertArrayEquals(
|
assertContentEquals(
|
||||||
arrayOf(5, 5, 5, 4, 4, 4, 4),
|
arrayOf(5, 5, 5, 4, 4, 4, 4),
|
||||||
countWeekdayOccurrencesInMonth(LocalDate(2020, 8, 1))
|
countWeekdayOccurrencesInMonth(LocalDate(2020, 8, 1))
|
||||||
)
|
)
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2025 Álinson Santos Xavier <git@axavier.org>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.isoron.uhabits.core
|
||||||
|
|
||||||
|
import org.isoron.platform.io.TestDatabaseHelper
|
||||||
|
import org.isoron.platform.time.LocalDate
|
||||||
|
import org.isoron.platform.time.setToday
|
||||||
|
import org.isoron.uhabits.core.commands.CommandRunner
|
||||||
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
|
import org.isoron.uhabits.core.models.ModelFactory
|
||||||
|
import org.isoron.uhabits.core.models.memory.MemoryModelFactory
|
||||||
|
import org.isoron.uhabits.core.tasks.SingleThreadTaskRunner
|
||||||
|
import org.isoron.uhabits.core.test.HabitFixtures
|
||||||
|
import kotlin.test.BeforeTest
|
||||||
|
|
||||||
|
open class BaseUnitTest {
|
||||||
|
protected open lateinit var habitList: HabitList
|
||||||
|
protected lateinit var fixtures: HabitFixtures
|
||||||
|
protected lateinit var modelFactory: ModelFactory
|
||||||
|
protected lateinit var taskRunner: SingleThreadTaskRunner
|
||||||
|
protected open lateinit var commandRunner: CommandRunner
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
open fun setUp() {
|
||||||
|
setToday(LocalDate(2015, 1, 25))
|
||||||
|
val memoryModelFactory = MemoryModelFactory()
|
||||||
|
habitList = memoryModelFactory.buildHabitList()
|
||||||
|
fixtures = HabitFixtures(memoryModelFactory, habitList)
|
||||||
|
modelFactory = memoryModelFactory
|
||||||
|
taskRunner = SingleThreadTaskRunner()
|
||||||
|
commandRunner = CommandRunner(taskRunner)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun buildMemoryDatabase(): org.isoron.platform.io.Database {
|
||||||
|
return TestDatabaseHelper.createEmptyDatabase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -20,8 +20,8 @@ package org.isoron.uhabits.core.commands
|
|||||||
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@ -29,8 +29,7 @@ class ArchiveHabitsCommandTest : BaseUnitTest() {
|
|||||||
private lateinit var command: ArchiveHabitsCommand
|
private lateinit var command: ArchiveHabitsCommand
|
||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createShortHabit()
|
habit = fixtures.createShortHabit()
|
||||||
@ -18,24 +18,21 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.commands
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.PaletteColor
|
import org.isoron.uhabits.core.models.PaletteColor
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import java.util.LinkedList
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class ChangeHabitColorCommandTest : BaseUnitTest() {
|
class ChangeHabitColorCommandTest : BaseUnitTest() {
|
||||||
private lateinit var command: ChangeHabitColorCommand
|
private lateinit var command: ChangeHabitColorCommand
|
||||||
private lateinit var selected: LinkedList<Habit>
|
private lateinit var selected: MutableList<Habit>
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
selected = LinkedList()
|
selected = mutableListOf()
|
||||||
for (i in 0..2) {
|
for (i in 0..2) {
|
||||||
val habit = fixtures.createShortHabit()
|
val habit = fixtures.createShortHabit()
|
||||||
habit.color = PaletteColor(i + 1)
|
habit.color = PaletteColor(i + 1)
|
||||||
@ -54,13 +51,13 @@ class ChangeHabitColorCommandTest : BaseUnitTest() {
|
|||||||
|
|
||||||
private fun checkNewColors() {
|
private fun checkNewColors() {
|
||||||
for (habit in selected) {
|
for (habit in selected) {
|
||||||
assertThat(habit.color, equalTo(PaletteColor(0)))
|
assertEquals(PaletteColor(0), habit.color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkOriginalColors() {
|
private fun checkOriginalColors() {
|
||||||
var k = 0
|
var k = 0
|
||||||
for (habit in selected)
|
for (habit in selected)
|
||||||
assertThat(habit.color, equalTo(PaletteColor(++k)))
|
assertEquals(PaletteColor(++k), habit.color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,22 +18,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.commands
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.Reminder
|
import org.isoron.uhabits.core.models.Reminder
|
||||||
import org.isoron.uhabits.core.models.WeekdayList
|
import org.isoron.uhabits.core.models.WeekdayList
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class CreateHabitCommandTest : BaseUnitTest() {
|
class CreateHabitCommandTest : BaseUnitTest() {
|
||||||
private lateinit var command: CreateHabitCommand
|
private lateinit var command: CreateHabitCommand
|
||||||
private lateinit var model: Habit
|
private lateinit var model: Habit
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
model = fixtures.createEmptyHabit()
|
model = fixtures.createEmptyHabit()
|
||||||
@ -46,8 +44,8 @@ class CreateHabitCommandTest : BaseUnitTest() {
|
|||||||
fun testExecute() {
|
fun testExecute() {
|
||||||
assertTrue(habitList.isEmpty)
|
assertTrue(habitList.isEmpty)
|
||||||
command.run()
|
command.run()
|
||||||
assertThat(habitList.size(), equalTo(1))
|
assertEquals(1, habitList.size())
|
||||||
val habit = habitList.getByPosition(0)
|
val habit = habitList.getByPosition(0)
|
||||||
assertThat(habit.name, equalTo(model.name))
|
assertEquals(model.name, habit.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,8 +23,8 @@ import org.isoron.platform.time.getToday
|
|||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class CreateRepetitionCommandTest : BaseUnitTest() {
|
class CreateRepetitionCommandTest : BaseUnitTest() {
|
||||||
@ -32,8 +32,7 @@ class CreateRepetitionCommandTest : BaseUnitTest() {
|
|||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
private lateinit var today: LocalDate
|
private lateinit var today: LocalDate
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createShortHabit()
|
habit = fixtures.createShortHabit()
|
||||||
@ -18,23 +18,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.commands
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import java.util.*
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class DeleteHabitsCommandTest : BaseUnitTest() {
|
class DeleteHabitsCommandTest : BaseUnitTest() {
|
||||||
private lateinit var command: DeleteHabitsCommand
|
private lateinit var command: DeleteHabitsCommand
|
||||||
private lateinit var selected: LinkedList<Habit>
|
private lateinit var selected: MutableList<Habit>
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
selected = LinkedList()
|
selected = mutableListOf()
|
||||||
|
|
||||||
// Habits that should be deleted
|
// Habits that should be deleted
|
||||||
for (i in 0..2) {
|
for (i in 0..2) {
|
||||||
@ -52,9 +49,9 @@ class DeleteHabitsCommandTest : BaseUnitTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testExecute() {
|
fun testExecute() {
|
||||||
assertThat(habitList.size(), equalTo(4))
|
assertEquals(4, habitList.size())
|
||||||
command.run()
|
command.run()
|
||||||
assertThat(habitList.size(), equalTo(1))
|
assertEquals(1, habitList.size())
|
||||||
assertThat(habitList.getByPosition(0).name, equalTo("extra"))
|
assertEquals("extra", habitList.getByPosition(0).name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,15 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.commands
|
package org.isoron.uhabits.core.commands
|
||||||
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.hamcrest.Matchers.equalTo
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Frequency
|
import org.isoron.uhabits.core.models.Frequency
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class EditHabitCommandTest : BaseUnitTest() {
|
class EditHabitCommandTest : BaseUnitTest() {
|
||||||
private lateinit var command: EditHabitCommand
|
private lateinit var command: EditHabitCommand
|
||||||
@ -34,8 +33,7 @@ class EditHabitCommandTest : BaseUnitTest() {
|
|||||||
private lateinit var modified: Habit
|
private lateinit var modified: Habit
|
||||||
private lateinit var today: LocalDate
|
private lateinit var today: LocalDate
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createShortHabit()
|
habit = fixtures.createShortHabit()
|
||||||
@ -54,9 +52,9 @@ class EditHabitCommandTest : BaseUnitTest() {
|
|||||||
fun testExecute() {
|
fun testExecute() {
|
||||||
command = EditHabitCommand(habitList, habit.id!!, modified)
|
command = EditHabitCommand(habitList, habit.id!!, modified)
|
||||||
val originalScore = habit.scores[today].value
|
val originalScore = habit.scores[today].value
|
||||||
assertThat(habit.name, equalTo("original"))
|
assertEquals("original", habit.name)
|
||||||
command.run()
|
command.run()
|
||||||
assertThat(habit.name, equalTo("modified"))
|
assertEquals("modified", habit.name)
|
||||||
assertThat(habit.scores[today].value, equalTo(originalScore))
|
assertEquals(originalScore, habit.scores[today].value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,8 +20,8 @@ package org.isoron.uhabits.core.commands
|
|||||||
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@ -29,8 +29,7 @@ class UnarchiveHabitsCommandTest : BaseUnitTest() {
|
|||||||
private lateinit var command: UnarchiveHabitsCommand
|
private lateinit var command: UnarchiveHabitsCommand
|
||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createShortHabit()
|
habit = fixtures.createShortHabit()
|
||||||
@ -19,16 +19,15 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.hamcrest.core.IsEqual.equalTo
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.platform.time.TruncateField
|
import org.isoron.platform.time.TruncateField
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
import org.isoron.uhabits.core.models.Entry.Companion.NO
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||||
import org.junit.Test
|
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class EntryListTest {
|
class EntryListTest {
|
||||||
@ -146,27 +145,27 @@ class EntryListTest {
|
|||||||
truncateField = TruncateField.MONTH,
|
truncateField = TruncateField.MONTH,
|
||||||
isNumerical = true
|
isNumerical = true
|
||||||
)
|
)
|
||||||
assertThat(byMonth.size, equalTo(17))
|
assertEquals(17, byMonth.size)
|
||||||
assertThat(byMonth[0], equalTo(Entry(LocalDate(2014, 6, 1), 230)))
|
assertEquals(Entry(LocalDate(2014, 6, 1), 230), byMonth[0])
|
||||||
assertThat(byMonth[6], equalTo(Entry(LocalDate(2013, 12, 1), 1988)))
|
assertEquals(Entry(LocalDate(2013, 12, 1), 1988), byMonth[6])
|
||||||
assertThat(byMonth[12], equalTo(Entry(LocalDate(2013, 5, 1), 1271)))
|
assertEquals(Entry(LocalDate(2013, 5, 1), 1271), byMonth[12])
|
||||||
|
|
||||||
val byQuarter = entries.getKnown().groupedSum(
|
val byQuarter = entries.getKnown().groupedSum(
|
||||||
truncateField = TruncateField.QUARTER,
|
truncateField = TruncateField.QUARTER,
|
||||||
isNumerical = true
|
isNumerical = true
|
||||||
)
|
)
|
||||||
assertThat(byQuarter.size, equalTo(6))
|
assertEquals(6, byQuarter.size)
|
||||||
assertThat(byQuarter[0], equalTo(Entry(LocalDate(2014, 4, 1), 3263)))
|
assertEquals(Entry(LocalDate(2014, 4, 1), 3263), byQuarter[0])
|
||||||
assertThat(byQuarter[3], equalTo(Entry(LocalDate(2013, 7, 1), 3838)))
|
assertEquals(Entry(LocalDate(2013, 7, 1), 3838), byQuarter[3])
|
||||||
assertThat(byQuarter[5], equalTo(Entry(LocalDate(2013, 1, 1), 4975)))
|
assertEquals(Entry(LocalDate(2013, 1, 1), 4975), byQuarter[5])
|
||||||
|
|
||||||
val byYear = entries.getKnown().groupedSum(
|
val byYear = entries.getKnown().groupedSum(
|
||||||
truncateField = TruncateField.YEAR,
|
truncateField = TruncateField.YEAR,
|
||||||
isNumerical = true
|
isNumerical = true
|
||||||
)
|
)
|
||||||
assertThat(byYear.size, equalTo(2))
|
assertEquals(2, byYear.size)
|
||||||
assertThat(byYear[0], equalTo(Entry(LocalDate(2014, 1, 1), 8227)))
|
assertEquals(Entry(LocalDate(2014, 1, 1), 8227), byYear[0])
|
||||||
assertThat(byYear[1], equalTo(Entry(LocalDate(2013, 1, 1), 16172)))
|
assertEquals(Entry(LocalDate(2013, 1, 1), 16172), byYear[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -190,27 +189,27 @@ class EntryListTest {
|
|||||||
truncateField = TruncateField.MONTH,
|
truncateField = TruncateField.MONTH,
|
||||||
isNumerical = false
|
isNumerical = false
|
||||||
)
|
)
|
||||||
assertThat(byMonth.size, equalTo(17))
|
assertEquals(17, byMonth.size)
|
||||||
assertThat(byMonth[0], equalTo(Entry(LocalDate(2014, 6, 1), 1_000)))
|
assertEquals(Entry(LocalDate(2014, 6, 1), 1_000), byMonth[0])
|
||||||
assertThat(byMonth[6], equalTo(Entry(LocalDate(2013, 12, 1), 7_000)))
|
assertEquals(Entry(LocalDate(2013, 12, 1), 7_000), byMonth[6])
|
||||||
assertThat(byMonth[12], equalTo(Entry(LocalDate(2013, 5, 1), 6_000)))
|
assertEquals(Entry(LocalDate(2013, 5, 1), 6_000), byMonth[12])
|
||||||
|
|
||||||
val byQuarter = entries.getKnown().groupedSum(
|
val byQuarter = entries.getKnown().groupedSum(
|
||||||
truncateField = TruncateField.QUARTER,
|
truncateField = TruncateField.QUARTER,
|
||||||
isNumerical = false
|
isNumerical = false
|
||||||
)
|
)
|
||||||
assertThat(byQuarter.size, equalTo(6))
|
assertEquals(6, byQuarter.size)
|
||||||
assertThat(byQuarter[0], equalTo(Entry(LocalDate(2014, 4, 1), 15_000)))
|
assertEquals(Entry(LocalDate(2014, 4, 1), 15_000), byQuarter[0])
|
||||||
assertThat(byQuarter[3], equalTo(Entry(LocalDate(2013, 7, 1), 17_000)))
|
assertEquals(Entry(LocalDate(2013, 7, 1), 17_000), byQuarter[3])
|
||||||
assertThat(byQuarter[5], equalTo(Entry(LocalDate(2013, 1, 1), 20_000)))
|
assertEquals(Entry(LocalDate(2013, 1, 1), 20_000), byQuarter[5])
|
||||||
|
|
||||||
val byYear = entries.getKnown().groupedSum(
|
val byYear = entries.getKnown().groupedSum(
|
||||||
truncateField = TruncateField.YEAR,
|
truncateField = TruncateField.YEAR,
|
||||||
isNumerical = false
|
isNumerical = false
|
||||||
)
|
)
|
||||||
assertThat(byYear.size, equalTo(2))
|
assertEquals(2, byYear.size)
|
||||||
assertThat(byYear[0], equalTo(Entry(LocalDate(2014, 1, 1), 34_000)))
|
assertEquals(Entry(LocalDate(2014, 1, 1), 34_000), byYear[0])
|
||||||
assertThat(byYear[1], equalTo(Entry(LocalDate(2013, 1, 1), 66_000)))
|
assertEquals(Entry(LocalDate(2013, 1, 1), 66_000), byYear[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -242,7 +241,7 @@ class EntryListTest {
|
|||||||
Entry(day(11), NO)
|
Entry(day(11), NO)
|
||||||
)
|
)
|
||||||
val actual = EntryList.buildEntriesFromInterval(entries, intervals)
|
val actual = EntryList.buildEntriesFromInterval(entries, intervals)
|
||||||
assertThat(actual, equalTo(expected))
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -260,7 +259,7 @@ class EntryListTest {
|
|||||||
EntryList.Interval(day(29), day(27), day(23))
|
EntryList.Interval(day(29), day(27), day(23))
|
||||||
)
|
)
|
||||||
EntryList.snapIntervalsTogether(original)
|
EntryList.snapIntervalsTogether(original)
|
||||||
assertThat(original, equalTo(expected))
|
assertEquals(expected, original)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -274,7 +273,7 @@ class EntryListTest {
|
|||||||
EntryList.Interval(day(13), day(8), day(7))
|
EntryList.Interval(day(13), day(8), day(7))
|
||||||
)
|
)
|
||||||
EntryList.snapIntervalsTogether(original)
|
EntryList.snapIntervalsTogether(original)
|
||||||
assertThat(original, equalTo(expected))
|
assertEquals(expected, original)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -290,7 +289,7 @@ class EntryListTest {
|
|||||||
EntryList.Interval(day(23), day(23), day(17))
|
EntryList.Interval(day(23), day(23), day(17))
|
||||||
)
|
)
|
||||||
val actual = EntryList.buildIntervals(Frequency.WEEKLY, entries)
|
val actual = EntryList.buildIntervals(Frequency.WEEKLY, entries)
|
||||||
assertThat(actual, equalTo(expected))
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -306,7 +305,7 @@ class EntryListTest {
|
|||||||
EntryList.Interval(day(23), day(23), day(23))
|
EntryList.Interval(day(23), day(23), day(23))
|
||||||
)
|
)
|
||||||
val actual = EntryList.buildIntervals(Frequency.DAILY, entries)
|
val actual = EntryList.buildIntervals(Frequency.DAILY, entries)
|
||||||
assertThat(actual, equalTo(expected))
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -324,7 +323,7 @@ class EntryListTest {
|
|||||||
EntryList.Interval(day(23), day(22), day(17))
|
EntryList.Interval(day(23), day(22), day(17))
|
||||||
)
|
)
|
||||||
val actual = EntryList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, entries)
|
val actual = EntryList.buildIntervals(Frequency.TWO_TIMES_PER_WEEK, entries)
|
||||||
assertThat(actual, equalTo(expected))
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -339,7 +338,7 @@ class EntryListTest {
|
|||||||
EntryList.Interval(day(30), day(30), day(28))
|
EntryList.Interval(day(30), day(30), day(28))
|
||||||
)
|
)
|
||||||
val actual = EntryList.buildIntervals(Frequency(1, 3), entries)
|
val actual = EntryList.buildIntervals(Frequency(1, 3), entries)
|
||||||
assertThat(actual, equalTo(expected))
|
assertEquals(expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -376,9 +375,9 @@ class EntryListTest {
|
|||||||
val monthStart = LocalDate(2015, month + 1, 1)
|
val monthStart = LocalDate(2015, month + 1, 1)
|
||||||
val actualCount = freq[monthStart]
|
val actualCount = freq[monthStart]
|
||||||
if (monthCount[month] == 0) {
|
if (monthCount[month] == 0) {
|
||||||
assertThat(actualCount, equalTo(null))
|
assertEquals(null, actualCount)
|
||||||
} else {
|
} else {
|
||||||
assertThat(actualCount, equalTo(weekdayCount[month]))
|
assertContentEquals(weekdayCount[month], actualCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
|||||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValue
|
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValue
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class EntryTest {
|
class EntryTest {
|
||||||
@ -18,15 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.CoreMatchers.not
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.junit.Assert.assertThrows
|
import kotlin.test.Test
|
||||||
import org.junit.Test
|
import kotlin.test.assertContentEquals
|
||||||
import java.io.IOException
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertFailsWith
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertNotEquals
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class HabitListTest : BaseUnitTest() {
|
class HabitListTest : BaseUnitTest() {
|
||||||
@ -34,7 +32,6 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
private lateinit var activeHabits: HabitList
|
private lateinit var activeHabits: HabitList
|
||||||
private lateinit var reminderHabits: HabitList
|
private lateinit var reminderHabits: HabitList
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habitsArray = ArrayList()
|
habitsArray = ArrayList()
|
||||||
@ -59,25 +56,25 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSize() {
|
fun testSize() {
|
||||||
assertThat(habitList.size(), equalTo(10))
|
assertEquals(10, habitList.size())
|
||||||
assertThat(activeHabits.size(), equalTo(6))
|
assertEquals(6, activeHabits.size())
|
||||||
assertThat(reminderHabits.size(), equalTo(4))
|
assertEquals(4, reminderHabits.size())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetByPosition() {
|
fun testGetByPosition() {
|
||||||
assertThat(habitList.getByPosition(0), equalTo(habitsArray[0]))
|
assertEquals(habitsArray[0], habitList.getByPosition(0))
|
||||||
assertThat(habitList.getByPosition(3), equalTo(habitsArray[3]))
|
assertEquals(habitsArray[3], habitList.getByPosition(3))
|
||||||
assertThat(habitList.getByPosition(9), equalTo(habitsArray[9]))
|
assertEquals(habitsArray[9], habitList.getByPosition(9))
|
||||||
assertThat(activeHabits.getByPosition(0), equalTo(habitsArray[2]))
|
assertEquals(habitsArray[2], activeHabits.getByPosition(0))
|
||||||
assertThat(reminderHabits.getByPosition(1), equalTo(habitsArray[3]))
|
assertEquals(habitsArray[3], reminderHabits.getByPosition(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetById() {
|
fun testGetById() {
|
||||||
val habit1 = habitsArray[0]
|
val habit1 = habitsArray[0]
|
||||||
val habit2 = habitList.getById(habit1.id!!)
|
val habit2 = habitList.getById(habit1.id!!)
|
||||||
assertThat(habit1, equalTo(habit2))
|
assertEquals(habit1, habit2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -100,41 +97,41 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list.primaryOrder = HabitList.Order.BY_POSITION
|
list.primaryOrder = HabitList.Order.BY_POSITION
|
||||||
assertThat(list.getByPosition(0), equalTo(h3))
|
assertEquals(h3, list.getByPosition(0))
|
||||||
assertThat(list.getByPosition(1), equalTo(h1))
|
assertEquals(h1, list.getByPosition(1))
|
||||||
assertThat(list.getByPosition(2), equalTo(h4))
|
assertEquals(h4, list.getByPosition(2))
|
||||||
assertThat(list.getByPosition(3), equalTo(h2))
|
assertEquals(h2, list.getByPosition(3))
|
||||||
list.primaryOrder = HabitList.Order.BY_NAME_DESC
|
list.primaryOrder = HabitList.Order.BY_NAME_DESC
|
||||||
assertThat(list.getByPosition(0), equalTo(h4))
|
assertEquals(h4, list.getByPosition(0))
|
||||||
assertThat(list.getByPosition(1), equalTo(h3))
|
assertEquals(h3, list.getByPosition(1))
|
||||||
assertThat(list.getByPosition(2), equalTo(h2))
|
assertEquals(h2, list.getByPosition(2))
|
||||||
assertThat(list.getByPosition(3), equalTo(h1))
|
assertEquals(h1, list.getByPosition(3))
|
||||||
list.primaryOrder = HabitList.Order.BY_NAME_ASC
|
list.primaryOrder = HabitList.Order.BY_NAME_ASC
|
||||||
assertThat(list.getByPosition(0), equalTo(h1))
|
assertEquals(h1, list.getByPosition(0))
|
||||||
assertThat(list.getByPosition(1), equalTo(h2))
|
assertEquals(h2, list.getByPosition(1))
|
||||||
assertThat(list.getByPosition(2), equalTo(h3))
|
assertEquals(h3, list.getByPosition(2))
|
||||||
assertThat(list.getByPosition(3), equalTo(h4))
|
assertEquals(h4, list.getByPosition(3))
|
||||||
list.primaryOrder = HabitList.Order.BY_NAME_ASC
|
list.primaryOrder = HabitList.Order.BY_NAME_ASC
|
||||||
list.remove(h1)
|
list.remove(h1)
|
||||||
list.add(h1)
|
list.add(h1)
|
||||||
assertThat(list.getByPosition(0), equalTo(h1))
|
assertEquals(h1, list.getByPosition(0))
|
||||||
list.primaryOrder = HabitList.Order.BY_COLOR_ASC
|
list.primaryOrder = HabitList.Order.BY_COLOR_ASC
|
||||||
list.secondaryOrder = HabitList.Order.BY_NAME_ASC
|
list.secondaryOrder = HabitList.Order.BY_NAME_ASC
|
||||||
assertThat(list.getByPosition(0), equalTo(h3))
|
assertEquals(h3, list.getByPosition(0))
|
||||||
assertThat(list.getByPosition(1), equalTo(h4))
|
assertEquals(h4, list.getByPosition(1))
|
||||||
assertThat(list.getByPosition(2), equalTo(h1))
|
assertEquals(h1, list.getByPosition(2))
|
||||||
assertThat(list.getByPosition(3), equalTo(h2))
|
assertEquals(h2, list.getByPosition(3))
|
||||||
list.primaryOrder = HabitList.Order.BY_COLOR_DESC
|
list.primaryOrder = HabitList.Order.BY_COLOR_DESC
|
||||||
list.secondaryOrder = HabitList.Order.BY_NAME_ASC
|
list.secondaryOrder = HabitList.Order.BY_NAME_ASC
|
||||||
assertThat(list.getByPosition(0), equalTo(h1))
|
assertEquals(h1, list.getByPosition(0))
|
||||||
assertThat(list.getByPosition(1), equalTo(h2))
|
assertEquals(h2, list.getByPosition(1))
|
||||||
assertThat(list.getByPosition(2), equalTo(h4))
|
assertEquals(h4, list.getByPosition(2))
|
||||||
assertThat(list.getByPosition(3), equalTo(h3))
|
assertEquals(h3, list.getByPosition(3))
|
||||||
list.primaryOrder = HabitList.Order.BY_POSITION
|
list.primaryOrder = HabitList.Order.BY_POSITION
|
||||||
assertThat(list.getByPosition(0), equalTo(h3))
|
assertEquals(h3, list.getByPosition(0))
|
||||||
assertThat(list.getByPosition(1), equalTo(h1))
|
assertEquals(h1, list.getByPosition(1))
|
||||||
assertThat(list.getByPosition(2), equalTo(h4))
|
assertEquals(h4, list.getByPosition(2))
|
||||||
assertThat(list.getByPosition(3), equalTo(h2))
|
assertEquals(h2, list.getByPosition(3))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -154,21 +151,20 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
val actualSequence = IntArray(10)
|
val actualSequence = IntArray(10)
|
||||||
for (j in 0..9) {
|
for (j in 0..9) {
|
||||||
val habit = habitList.getByPosition(j)
|
val habit = habitList.getByPosition(j)
|
||||||
assertThat(habit.position, equalTo(j))
|
assertEquals(j, habit.position)
|
||||||
actualSequence[j] = Math.toIntExact(habit.id!!)
|
actualSequence[j] = habit.id!!.toInt()
|
||||||
}
|
}
|
||||||
assertThat(actualSequence, equalTo(expectedSequence[i]))
|
assertContentEquals(expectedSequence[i], actualSequence)
|
||||||
}
|
}
|
||||||
assertThat(activeHabits.indexOf(habitsArray[5]), equalTo(0))
|
assertEquals(0, activeHabits.indexOf(habitsArray[5]))
|
||||||
assertThat(activeHabits.indexOf(habitsArray[2]), equalTo(1))
|
assertEquals(1, activeHabits.indexOf(habitsArray[2]))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testReorder_withInvalidArguments() {
|
fun testReorder_withInvalidArguments() {
|
||||||
val h1 = habitsArray[0]
|
val h1 = habitsArray[0]
|
||||||
val h2 = fixtures.createEmptyHabit()
|
val h2 = fixtures.createEmptyHabit()
|
||||||
assertThrows(IllegalArgumentException::class.java) {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
habitList.reorder(h1, h2)
|
habitList.reorder(h1, h2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,7 +182,6 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(IOException::class)
|
|
||||||
fun testWriteCSV() {
|
fun testWriteCSV() {
|
||||||
val list = modelFactory.buildHabitList()
|
val list = modelFactory.buildHabitList()
|
||||||
val h1 = fixtures.createEmptyHabit()
|
val h1 = fixtures.createEmptyHabit()
|
||||||
@ -211,57 +206,52 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
001,Meditate,YES_NO,Did you meditate this morning?,this is a test description,1,1,#FF8F00,,,,false
|
001,Meditate,YES_NO,Did you meditate this morning?,this is a test description,1,1,#FF8F00,,,,false
|
||||||
002,Run,NUMERICAL,How many miles did you run today?,,1,1,#E64A19,miles,AT_LEAST,2.0,false
|
002,Run,NUMERICAL,How many miles did you run today?,,1,1,#E64A19,miles,AT_LEAST,2.0,false
|
||||||
003,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#AFB42B,,,,false
|
003,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#AFB42B,,,,false
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
assertThat(list.writeCSV(), equalTo(expectedCSV))
|
assertEquals(expectedCSV, list.writeCSV())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testAdd() {
|
fun testAdd() {
|
||||||
val h1 = fixtures.createEmptyHabit()
|
val h1 = fixtures.createEmptyHabit()
|
||||||
assertFalse(h1.isArchived)
|
assertFalse(h1.isArchived)
|
||||||
assertNull(h1.id)
|
assertNull(h1.id)
|
||||||
assertThat(habitList.indexOf(h1), equalTo(-1))
|
assertEquals(-1, habitList.indexOf(h1))
|
||||||
habitList.add(h1)
|
habitList.add(h1)
|
||||||
h1.id!!
|
h1.id!!
|
||||||
assertThat(habitList.indexOf(h1), not(equalTo(-1)))
|
assertNotEquals(-1, habitList.indexOf(h1))
|
||||||
assertThat(activeHabits.indexOf(h1), not(equalTo(-1)))
|
assertNotEquals(-1, activeHabits.indexOf(h1))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testAdd_withFilteredList() {
|
fun testAdd_withFilteredList() {
|
||||||
assertThrows(IllegalStateException::class.java) {
|
assertFailsWith<IllegalStateException> {
|
||||||
activeHabits.add(fixtures.createEmptyHabit())
|
activeHabits.add(fixtures.createEmptyHabit())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testRemove_onFilteredList() {
|
fun testRemove_onFilteredList() {
|
||||||
assertThrows(IllegalStateException::class.java) {
|
assertFailsWith<IllegalStateException> {
|
||||||
activeHabits.remove(fixtures.createEmptyHabit())
|
activeHabits.remove(fixtures.createEmptyHabit())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testReorder_onFilteredList() {
|
fun testReorder_onFilteredList() {
|
||||||
val h1 = fixtures.createEmptyHabit()
|
val h1 = fixtures.createEmptyHabit()
|
||||||
val h2 = fixtures.createEmptyHabit()
|
val h2 = fixtures.createEmptyHabit()
|
||||||
assertThrows(IllegalStateException::class.java) {
|
assertFailsWith<IllegalStateException> {
|
||||||
activeHabits.reorder(h1, h2)
|
activeHabits.reorder(h1, h2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testReorder_onSortedList() {
|
fun testReorder_onSortedList() {
|
||||||
habitList.primaryOrder = HabitList.Order.BY_SCORE_DESC
|
habitList.primaryOrder = HabitList.Order.BY_SCORE_DESC
|
||||||
val h1 = habitsArray[1]
|
val h1 = habitsArray[1]
|
||||||
val h2 = habitsArray[2]
|
val h2 = habitsArray[2]
|
||||||
assertThrows(IllegalStateException::class.java) {
|
assertFailsWith<IllegalStateException> {
|
||||||
habitList.reorder(h1, h2)
|
habitList.reorder(h1, h2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,20 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.`is`
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.hamcrest.core.IsEqual.equalTo
|
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.junit.Assert.assertNotEquals
|
import kotlin.test.Test
|
||||||
import org.junit.Test
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertNotEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class HabitTest : BaseUnitTest() {
|
class HabitTest : BaseUnitTest() {
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
}
|
}
|
||||||
@ -53,22 +49,21 @@ class HabitTest : BaseUnitTest() {
|
|||||||
val habit = modelFactory.buildHabit()
|
val habit = modelFactory.buildHabit()
|
||||||
habit.copyFrom(model)
|
habit.copyFrom(model)
|
||||||
assertEquals(habit.isArchived, model.isArchived)
|
assertEquals(habit.isArchived, model.isArchived)
|
||||||
assertThat(habit.isArchived, `is`(model.isArchived))
|
assertEquals(model.isArchived, habit.isArchived)
|
||||||
assertThat(habit.color, `is`(model.color))
|
assertEquals(model.color, habit.color)
|
||||||
assertThat(habit.frequency, equalTo(model.frequency))
|
assertEquals(model.frequency, habit.frequency)
|
||||||
assertThat(habit.reminder, equalTo(model.reminder))
|
assertEquals(model.reminder, habit.reminder)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_hasReminder() {
|
fun test_hasReminder() {
|
||||||
val h = modelFactory.buildHabit()
|
val h = modelFactory.buildHabit()
|
||||||
assertThat(h.hasReminder(), `is`(false))
|
assertEquals(false, h.hasReminder())
|
||||||
h.reminder = Reminder(8, 30, WeekdayList.EVERY_DAY)
|
h.reminder = Reminder(8, 30, WeekdayList.EVERY_DAY)
|
||||||
assertThat(h.hasReminder(), `is`(true))
|
assertEquals(true, h.hasReminder())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun test_isCompleted() {
|
fun test_isCompleted() {
|
||||||
val h = modelFactory.buildHabit()
|
val h = modelFactory.buildHabit()
|
||||||
assertFalse(h.isCompletedToday())
|
assertFalse(h.isCompletedToday())
|
||||||
@ -78,7 +73,6 @@ class HabitTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun test_isEntered() {
|
fun test_isEntered() {
|
||||||
val h = modelFactory.buildHabit()
|
val h = modelFactory.buildHabit()
|
||||||
assertFalse(h.isEnteredToday())
|
assertFalse(h.isEnteredToday())
|
||||||
@ -88,7 +82,6 @@ class HabitTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun test_isCompleted_numerical() {
|
fun test_isCompleted_numerical() {
|
||||||
val h = modelFactory.buildHabit()
|
val h = modelFactory.buildHabit()
|
||||||
h.type = HabitType.NUMERICAL
|
h.type = HabitType.NUMERICAL
|
||||||
@ -117,12 +110,11 @@ class HabitTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testURI() {
|
fun testURI() {
|
||||||
assertTrue(habitList.isEmpty)
|
assertTrue(habitList.isEmpty)
|
||||||
val h = modelFactory.buildHabit()
|
val h = modelFactory.buildHabit()
|
||||||
habitList.add(h)
|
habitList.add(h)
|
||||||
assertThat(h.id, equalTo(0L))
|
assertEquals(0L, h.id)
|
||||||
assertThat(h.uriString, equalTo("content://org.isoron.uhabits/habit/0"))
|
assertEquals("content://org.isoron.uhabits/habit/0", h.uriString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,23 +18,19 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.hamcrest.number.IsCloseTo
|
|
||||||
import org.hamcrest.number.OrderingComparison
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
open class BaseScoreListTest : BaseUnitTest() {
|
open class BaseScoreListTest : BaseUnitTest() {
|
||||||
protected lateinit var habit: Habit
|
protected lateinit var habit: Habit
|
||||||
protected lateinit var today: LocalDate
|
protected lateinit var today: LocalDate
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
today = getToday()
|
today = getToday()
|
||||||
@ -44,19 +40,23 @@ open class BaseScoreListTest : BaseUnitTest() {
|
|||||||
var current = today
|
var current = today
|
||||||
val scores = habit.scores
|
val scores = habit.scores
|
||||||
for (expectedValue in expectedValues) {
|
for (expectedValue in expectedValues) {
|
||||||
assertThat(scores[current].value, IsCloseTo.closeTo(expectedValue, E))
|
assertCloseTo(expectedValue, scores[current].value, E)
|
||||||
current = current.minus(1)
|
current = current.minus(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val E = 1e-6
|
const val E = 1e-6
|
||||||
|
|
||||||
|
fun assertCloseTo(expected: Double, actual: Double, epsilon: Double) {
|
||||||
|
val diff = kotlin.math.abs(expected - actual)
|
||||||
|
assertTrue(diff <= epsilon, "Expected $expected ± $epsilon, but got $actual (diff=$diff)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class YesNoScoreListTest : BaseScoreListTest() {
|
class YesNoScoreListTest : BaseScoreListTest() {
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createEmptyHabit()
|
habit = fixtures.createEmptyHabit()
|
||||||
@ -161,12 +161,12 @@ class YesNoScoreListTest : BaseScoreListTest() {
|
|||||||
values.add(Entry.NO)
|
values.add(Entry.NO)
|
||||||
}
|
}
|
||||||
check(values)
|
check(values)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(2 / 3.0, E))
|
assertCloseTo(2 / 3.0, habit.scores[today].value, E)
|
||||||
|
|
||||||
// Missing 2 repetitions out of 4 per week, the score should converge to 50%
|
// Missing 2 repetitions out of 4 per week, the score should converge to 50%
|
||||||
habit.frequency = Frequency(4, 7)
|
habit.frequency = Frequency(4, 7)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.5, E))
|
assertCloseTo(0.5, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -195,7 +195,7 @@ class YesNoScoreListTest : BaseScoreListTest() {
|
|||||||
values.add(Entry.YES_MANUAL)
|
values.add(Entry.YES_MANUAL)
|
||||||
}
|
}
|
||||||
check(values)
|
check(values)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(1.0, 1e-3))
|
assertCloseTo(1.0, habit.scores[today].value, 1e-3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -205,43 +205,43 @@ class YesNoScoreListTest : BaseScoreListTest() {
|
|||||||
habit.frequency = Frequency.DAILY
|
habit.frequency = Frequency.DAILY
|
||||||
for (i in 0..89) check(i)
|
for (i in 0..89) check(i)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, OrderingComparison.greaterThan(0.99))
|
assertTrue(habit.scores[today].value > 0.99)
|
||||||
|
|
||||||
// Weekly habits should achieve at least 99% in 9 months
|
// Weekly habits should achieve at least 99% in 9 months
|
||||||
habit = fixtures.createEmptyHabit()
|
habit = fixtures.createEmptyHabit()
|
||||||
habit.frequency = Frequency.WEEKLY
|
habit.frequency = Frequency.WEEKLY
|
||||||
for (i in 0..38) check(7 * i)
|
for (i in 0..38) check(7 * i)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, OrderingComparison.greaterThan(0.99))
|
assertTrue(habit.scores[today].value > 0.99)
|
||||||
|
|
||||||
// Monthly habits should achieve at least 99% in 18 months
|
// Monthly habits should achieve at least 99% in 18 months
|
||||||
habit.frequency = Frequency(1, 30)
|
habit.frequency = Frequency(1, 30)
|
||||||
for (i in 0..17) check(30 * i)
|
for (i in 0..17) check(30 * i)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, OrderingComparison.greaterThan(0.99))
|
assertTrue(habit.scores[today].value > 0.99)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_recompute() {
|
fun test_recompute() {
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.0, E))
|
assertCloseTo(0.0, habit.scores[today].value, E)
|
||||||
check(0, 2)
|
check(0, 2)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.101149, E))
|
assertCloseTo(0.101149, habit.scores[today].value, E)
|
||||||
habit.frequency = Frequency(1, 2)
|
habit.frequency = Frequency(1, 2)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.054816, E))
|
assertCloseTo(0.054816, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_addThenRemove() {
|
fun test_addThenRemove() {
|
||||||
val habit = fixtures.createEmptyHabit()
|
val habit = fixtures.createEmptyHabit()
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.0, E))
|
assertCloseTo(0.0, habit.scores[today].value, E)
|
||||||
habit.originalEntries.add(Entry(today, Entry.YES_MANUAL))
|
habit.originalEntries.add(Entry(today, Entry.YES_MANUAL))
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.051922, E))
|
assertCloseTo(0.051922, habit.scores[today].value, E)
|
||||||
habit.originalEntries.add(Entry(today, Entry.UNKNOWN))
|
habit.originalEntries.add(Entry(today, Entry.UNKNOWN))
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.0, E))
|
assertCloseTo(0.0, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun check(offset: Int) {
|
private fun check(offset: Int) {
|
||||||
@ -288,8 +288,7 @@ open class NumericalScoreListTest : BaseScoreListTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class NumericalAtLeastScoreListTest : NumericalScoreListTest() {
|
class NumericalAtLeastScoreListTest : NumericalScoreListTest() {
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_LEAST)
|
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_LEAST)
|
||||||
@ -336,12 +335,12 @@ class NumericalAtLeastScoreListTest : NumericalScoreListTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_recompute() {
|
fun test_recompute() {
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.0, E))
|
assertCloseTo(0.0, habit.scores[today].value, E)
|
||||||
addEntries(0, 2, 2000)
|
addEntries(0, 2, 2000)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.101149, E))
|
assertCloseTo(0.101149, habit.scores[today].value, E)
|
||||||
habit.frequency = Frequency(1, 2)
|
habit.frequency = Frequency(1, 2)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.072631, E))
|
assertCloseTo(0.072631, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -351,42 +350,41 @@ class NumericalAtLeastScoreListTest : NumericalScoreListTest() {
|
|||||||
habit.frequency = Frequency.DAILY
|
habit.frequency = Frequency.DAILY
|
||||||
for (i in 0..89) addEntry(i, 2000)
|
for (i in 0..89) addEntry(i, 2000)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, OrderingComparison.greaterThan(0.99))
|
assertTrue(habit.scores[today].value > 0.99)
|
||||||
|
|
||||||
// Weekly habits should achieve at least 99% in 9 months
|
// Weekly habits should achieve at least 99% in 9 months
|
||||||
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_LEAST)
|
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_LEAST)
|
||||||
habit.frequency = Frequency.WEEKLY
|
habit.frequency = Frequency.WEEKLY
|
||||||
for (i in 0..38) addEntry(7 * i, 2000)
|
for (i in 0..38) addEntry(7 * i, 2000)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, OrderingComparison.greaterThan(0.99))
|
assertTrue(habit.scores[today].value > 0.99)
|
||||||
|
|
||||||
// Monthly habits should achieve at least 99% in 18 months
|
// Monthly habits should achieve at least 99% in 18 months
|
||||||
habit.frequency = Frequency(1, 30)
|
habit.frequency = Frequency(1, 30)
|
||||||
for (i in 0..17) addEntry(30 * i, 2000)
|
for (i in 0..17) addEntry(30 * i, 2000)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, OrderingComparison.greaterThan(0.99))
|
assertTrue(habit.scores[today].value > 0.99)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldAchieveComparableScoreToProgress() {
|
fun shouldAchieveComparableScoreToProgress() {
|
||||||
addEntries(0, 500, 1000)
|
addEntries(0, 500, 1000)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.5, E))
|
assertCloseTo(0.5, habit.scores[today].value, E)
|
||||||
|
|
||||||
addEntries(0, 500, 500)
|
addEntries(0, 500, 500)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.25, E))
|
assertCloseTo(0.25, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun overeachievingIsntRelevant() {
|
fun overeachievingIsntRelevant() {
|
||||||
addEntry(0, 10000000)
|
addEntry(0, 10000000)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.051922, E))
|
assertCloseTo(0.051922, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NumericalAtLeastScoreListWithSkipTest : NumericalScoreListTest() {
|
class NumericalAtLeastScoreListWithSkipTest : NumericalScoreListTest() {
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_LEAST)
|
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_LEAST)
|
||||||
@ -433,20 +431,19 @@ class NumericalAtLeastScoreListWithSkipTest : NumericalScoreListTest() {
|
|||||||
val initialScore = habit.scores[today].value
|
val initialScore = habit.scores[today].value
|
||||||
|
|
||||||
addEntries(500, 1000, SKIP)
|
addEntries(500, 1000, SKIP)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(initialScore, E))
|
assertCloseTo(initialScore, habit.scores[today].value, E)
|
||||||
|
|
||||||
addEntries(0, 300, 1000)
|
addEntries(0, 300, 1000)
|
||||||
addEntries(300, 500, SKIP)
|
addEntries(300, 500, SKIP)
|
||||||
addEntries(500, 700, 1000)
|
addEntries(500, 700, 1000)
|
||||||
|
|
||||||
// skipped days should be treated as if they never existed
|
// skipped days should be treated as if they never existed
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(initialScore, E))
|
assertCloseTo(initialScore, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NumericalAtMostScoreListTest : NumericalScoreListTest() {
|
class NumericalAtMostScoreListTest : NumericalScoreListTest() {
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_MOST)
|
habit = fixtures.createEmptyNumericalHabit(NumericalHabitType.AT_MOST)
|
||||||
@ -496,28 +493,28 @@ class NumericalAtMostScoreListTest : NumericalScoreListTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun test_recompute() {
|
fun test_recompute() {
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(1.0, E))
|
assertCloseTo(1.0, habit.scores[today].value, E)
|
||||||
addEntries(0, 2, 5000)
|
addEntries(0, 2, 5000)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.898850, E))
|
assertCloseTo(0.898850, habit.scores[today].value, E)
|
||||||
habit.frequency = Frequency(1, 2)
|
habit.frequency = Frequency(1, 2)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.927369, E))
|
assertCloseTo(0.927369, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldAchieveComparableScoreToProgress() {
|
fun shouldAchieveComparableScoreToProgress() {
|
||||||
addEntries(0, 500, 3000)
|
addEntries(0, 500, 3000)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.5, E))
|
assertCloseTo(0.5, habit.scores[today].value, E)
|
||||||
|
|
||||||
addEntries(0, 500, 3500)
|
addEntries(0, 500, 3500)
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.25, E))
|
assertCloseTo(0.25, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun undereachievingIsntRelevant() {
|
fun undereachievingIsntRelevant() {
|
||||||
addEntry(1, 10000000)
|
addEntry(1, 10000000)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.950773, E))
|
assertCloseTo(0.950773, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -526,10 +523,10 @@ class NumericalAtMostScoreListTest : NumericalScoreListTest() {
|
|||||||
|
|
||||||
addEntry(1, 0)
|
addEntry(1, 0)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.948077, E))
|
assertCloseTo(0.948077, habit.scores[today].value, E)
|
||||||
|
|
||||||
addEntry(1, 1000)
|
addEntry(1, 1000)
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
assertThat(habit.scores[today].value, IsCloseTo.closeTo(0.948077, E))
|
assertCloseTo(0.948077, habit.scores[today].value, E)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,16 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.hamcrest.number.IsCloseTo.closeTo
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Score.Companion.compute
|
import org.isoron.uhabits.core.models.Score.Companion.compute
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class ScoreTest : BaseUnitTest() {
|
class ScoreTest : BaseUnitTest() {
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
}
|
}
|
||||||
@ -36,29 +34,34 @@ class ScoreTest : BaseUnitTest() {
|
|||||||
fun test_compute_withDailyHabit() {
|
fun test_compute_withDailyHabit() {
|
||||||
var check = 1
|
var check = 1
|
||||||
val freq = 1.0
|
val freq = 1.0
|
||||||
assertThat(compute(freq, 0.0, check.toDouble()), closeTo(0.051922, E))
|
assertCloseTo(0.051922, compute(freq, 0.0, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.5, check.toDouble()), closeTo(0.525961, E))
|
assertCloseTo(0.525961, compute(freq, 0.5, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.75, check.toDouble()), closeTo(0.762981, E))
|
assertCloseTo(0.762981, compute(freq, 0.75, check.toDouble()), E)
|
||||||
check = 0
|
check = 0
|
||||||
assertThat(compute(freq, 0.0, check.toDouble()), closeTo(0.0, E))
|
assertCloseTo(0.0, compute(freq, 0.0, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.5, check.toDouble()), closeTo(0.474039, E))
|
assertCloseTo(0.474039, compute(freq, 0.5, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.75, check.toDouble()), closeTo(0.711058, E))
|
assertCloseTo(0.711058, compute(freq, 0.75, check.toDouble()), E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_compute_withNonDailyHabit() {
|
fun test_compute_withNonDailyHabit() {
|
||||||
var check = 1
|
var check = 1
|
||||||
val freq = 1 / 3.0
|
val freq = 1 / 3.0
|
||||||
assertThat(compute(freq, 0.0, check.toDouble()), closeTo(0.030314, E))
|
assertCloseTo(0.030314, compute(freq, 0.0, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.5, check.toDouble()), closeTo(0.515157, E))
|
assertCloseTo(0.515157, compute(freq, 0.5, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.75, check.toDouble()), closeTo(0.757578, E))
|
assertCloseTo(0.757578, compute(freq, 0.75, check.toDouble()), E)
|
||||||
check = 0
|
check = 0
|
||||||
assertThat(compute(freq, 0.0, check.toDouble()), closeTo(0.0, E))
|
assertCloseTo(0.0, compute(freq, 0.0, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.5, check.toDouble()), closeTo(0.484842, E))
|
assertCloseTo(0.484842, compute(freq, 0.5, check.toDouble()), E)
|
||||||
assertThat(compute(freq, 0.75, check.toDouble()), closeTo(0.727263, E))
|
assertCloseTo(0.727263, compute(freq, 0.75, check.toDouble()), E)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val E = 1e-6
|
private const val E = 1e-6
|
||||||
|
|
||||||
|
private fun assertCloseTo(expected: Double, actual: Double, epsilon: Double) {
|
||||||
|
val diff = kotlin.math.abs(expected - actual)
|
||||||
|
assertTrue(diff <= epsilon, "Expected $expected ± $epsilon, but got $actual (diff=$diff)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,19 +18,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class StreakListTest : BaseUnitTest() {
|
class StreakListTest : BaseUnitTest() {
|
||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
private lateinit var streaks: StreakList
|
private lateinit var streaks: StreakList
|
||||||
private lateinit var today: LocalDate
|
private lateinit var today: LocalDate
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
habit = fixtures.createLongHabit()
|
habit = fixtures.createLongHabit()
|
||||||
@ -41,18 +39,17 @@ class StreakListTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testGetBest() {
|
fun testGetBest() {
|
||||||
var best = streaks.getBest(4)
|
var best = streaks.getBest(4)
|
||||||
assertThat(best.size, equalTo(4))
|
assertEquals(4, best.size)
|
||||||
assertThat(best[0].length, equalTo(4))
|
assertEquals(4, best[0].length)
|
||||||
assertThat(best[1].length, equalTo(3))
|
assertEquals(3, best[1].length)
|
||||||
assertThat(best[2].length, equalTo(5))
|
assertEquals(5, best[2].length)
|
||||||
assertThat(best[3].length, equalTo(6))
|
assertEquals(6, best[3].length)
|
||||||
best = streaks.getBest(2)
|
best = streaks.getBest(2)
|
||||||
assertThat(best.size, equalTo(2))
|
assertEquals(2, best.size)
|
||||||
assertThat(best[0].length, equalTo(5))
|
assertEquals(5, best[0].length)
|
||||||
assertThat(best[1].length, equalTo(6))
|
assertEquals(6, best[1].length)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -62,7 +59,7 @@ class StreakListTest : BaseUnitTest() {
|
|||||||
habit.originalEntries.add(Entry(today.minus(5), Entry.NO))
|
habit.originalEntries.add(Entry(today.minus(5), Entry.NO))
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
val best = streaks.getBest(5)
|
val best = streaks.getBest(5)
|
||||||
assertThat(best.size, equalTo(1))
|
assertEquals(1, best.size)
|
||||||
assertThat(best[0].length, equalTo(1))
|
assertEquals(1, best[0].length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,10 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.models
|
package org.isoron.uhabits.core.models
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertContentEquals
|
||||||
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@ -31,11 +31,11 @@ class WeekdayListTest : BaseUnitTest() {
|
|||||||
val daysInt = 124
|
val daysInt = 124
|
||||||
val daysArray = booleanArrayOf(false, false, true, true, true, true, true)
|
val daysArray = booleanArrayOf(false, false, true, true, true, true, true)
|
||||||
var list = WeekdayList(daysArray)
|
var list = WeekdayList(daysArray)
|
||||||
assertThat(list.toArray(), equalTo(daysArray))
|
assertContentEquals(daysArray, list.toArray())
|
||||||
assertThat(list.toInteger(), equalTo(daysInt))
|
assertEquals(daysInt, list.toInteger())
|
||||||
list = WeekdayList(daysInt)
|
list = WeekdayList(daysInt)
|
||||||
assertThat(list.toArray(), equalTo(daysArray))
|
assertContentEquals(daysArray, list.toArray())
|
||||||
assertThat(list.toInteger(), equalTo(daysInt))
|
assertEquals(daysInt, list.toInteger())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -48,7 +48,7 @@ class WeekdayListTest : BaseUnitTest() {
|
|||||||
@Test
|
@Test
|
||||||
fun testWeekdayList_IntConstructor_toString() {
|
fun testWeekdayList_IntConstructor_toString() {
|
||||||
val string = WeekdayList(0).toString()
|
val string = WeekdayList(0).toString()
|
||||||
assertThat(string, equalTo("{weekdays: [false,false,false,false,false,false,false]}"))
|
assertEquals("{weekdays: [false,false,false,false,false,false,false]}", string)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -56,6 +56,6 @@ class WeekdayListTest : BaseUnitTest() {
|
|||||||
val string = WeekdayList(
|
val string = WeekdayList(
|
||||||
booleanArrayOf(false, false, true, true, true, true, true)
|
booleanArrayOf(false, false, true, true, true, true, true)
|
||||||
).toString()
|
).toString()
|
||||||
assertThat(string, equalTo("{weekdays: [false,false,true,true,true,true,true]}"))
|
assertEquals("{weekdays: [false,false,true,true,true,true,true]}", string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,8 +24,8 @@ import org.isoron.uhabits.core.BaseUnitTest.Companion.buildMemoryDatabase
|
|||||||
import org.isoron.uhabits.core.database.EntryData
|
import org.isoron.uhabits.core.database.EntryData
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class SQLiteEntryListTest {
|
class SQLiteEntryListTest {
|
||||||
@ -36,7 +36,7 @@ class SQLiteEntryListTest {
|
|||||||
private lateinit var entries: SQLiteEntryList
|
private lateinit var entries: SQLiteEntryList
|
||||||
private val today = LocalDate(2015, 1, 25)
|
private val today = LocalDate(2015, 1, 25)
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
fun setUp() {
|
fun setUp() {
|
||||||
val habitList = factory.buildHabitList()
|
val habitList = factory.buildHabitList()
|
||||||
val habit = factory.buildHabit()
|
val habit = factory.buildHabit()
|
||||||
@ -18,15 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.preferences
|
package org.isoron.uhabits.core.preferences
|
||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.HabitList
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
import org.isoron.uhabits.core.ui.ThemeSwitcher
|
||||||
import org.junit.Before
|
import kotlin.test.BeforeTest
|
||||||
import org.junit.Test
|
import kotlin.test.Test
|
||||||
import org.mockito.kotlin.mock
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
@ -34,11 +32,10 @@ import kotlin.test.assertTrue
|
|||||||
class PreferencesTest : BaseUnitTest() {
|
class PreferencesTest : BaseUnitTest() {
|
||||||
private lateinit var prefs: Preferences
|
private lateinit var prefs: Preferences
|
||||||
|
|
||||||
private var listener: Preferences.Listener = mock()
|
private var listener: Preferences.Listener = object : Preferences.Listener {}
|
||||||
private lateinit var storage: MemoryStorage
|
private lateinit var storage: MemoryStorage
|
||||||
|
|
||||||
@Before
|
@BeforeTest
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
super.setUp()
|
super.setUp()
|
||||||
storage = MemoryStorage()
|
storage = MemoryStorage()
|
||||||
@ -47,69 +44,62 @@ class PreferencesTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testClear() {
|
fun testClear() {
|
||||||
prefs.setDefaultHabitColor(99)
|
prefs.setDefaultHabitColor(99)
|
||||||
prefs.clear()
|
prefs.clear()
|
||||||
assertThat(prefs.getDefaultHabitColor(0), equalTo(0))
|
assertEquals(0, prefs.getDefaultHabitColor(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testHabitColor() {
|
fun testHabitColor() {
|
||||||
assertThat(prefs.getDefaultHabitColor(999), equalTo(999))
|
assertEquals(999, prefs.getDefaultHabitColor(999))
|
||||||
prefs.setDefaultHabitColor(10)
|
prefs.setDefaultHabitColor(10)
|
||||||
assertThat(prefs.getDefaultHabitColor(999), equalTo(10))
|
assertEquals(10, prefs.getDefaultHabitColor(999))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testDefaultOrder() {
|
fun testDefaultOrder() {
|
||||||
assertThat(prefs.defaultPrimaryOrder, equalTo(HabitList.Order.BY_POSITION))
|
assertEquals(HabitList.Order.BY_POSITION, prefs.defaultPrimaryOrder)
|
||||||
prefs.defaultPrimaryOrder = HabitList.Order.BY_SCORE_DESC
|
prefs.defaultPrimaryOrder = HabitList.Order.BY_SCORE_DESC
|
||||||
assertThat(prefs.defaultPrimaryOrder, equalTo(HabitList.Order.BY_SCORE_DESC))
|
assertEquals(HabitList.Order.BY_SCORE_DESC, prefs.defaultPrimaryOrder)
|
||||||
storage.putString("pref_default_order", "BOGUS")
|
storage.putString("pref_default_order", "BOGUS")
|
||||||
assertThat(prefs.defaultPrimaryOrder, equalTo(HabitList.Order.BY_POSITION))
|
assertEquals(HabitList.Order.BY_POSITION, prefs.defaultPrimaryOrder)
|
||||||
assertThat(
|
assertEquals(
|
||||||
storage.getString("pref_default_order", ""),
|
"BY_POSITION",
|
||||||
equalTo("BY_POSITION")
|
storage.getString("pref_default_order", "")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testScoreCardSpinnerPosition() {
|
fun testScoreCardSpinnerPosition() {
|
||||||
assertThat(prefs.scoreCardSpinnerPosition, equalTo(1))
|
assertEquals(1, prefs.scoreCardSpinnerPosition)
|
||||||
prefs.scoreCardSpinnerPosition = 4
|
prefs.scoreCardSpinnerPosition = 4
|
||||||
assertThat(prefs.scoreCardSpinnerPosition, equalTo(4))
|
assertEquals(4, prefs.scoreCardSpinnerPosition)
|
||||||
storage.putInt("pref_score_view_interval", 9000)
|
storage.putInt("pref_score_view_interval", 9000)
|
||||||
assertThat(prefs.scoreCardSpinnerPosition, equalTo(4))
|
assertEquals(4, prefs.scoreCardSpinnerPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testLastHint() {
|
fun testLastHint() {
|
||||||
assertThat(prefs.lastHintNumber, equalTo(-1))
|
assertEquals(-1, prefs.lastHintNumber)
|
||||||
assertNull(prefs.lastHintDate)
|
assertNull(prefs.lastHintDate)
|
||||||
val date = LocalDate(2015, 3, 15)
|
val date = LocalDate(2015, 3, 15)
|
||||||
prefs.updateLastHint(34, date)
|
prefs.updateLastHint(34, date)
|
||||||
assertThat(prefs.lastHintNumber, equalTo(34))
|
assertEquals(34, prefs.lastHintNumber)
|
||||||
assertThat(prefs.lastHintDate, equalTo(date))
|
assertEquals(date, prefs.lastHintDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testTheme() {
|
fun testTheme() {
|
||||||
assertThat(prefs.theme, equalTo(ThemeSwitcher.THEME_AUTOMATIC))
|
assertEquals(ThemeSwitcher.THEME_AUTOMATIC, prefs.theme)
|
||||||
prefs.theme = ThemeSwitcher.THEME_DARK
|
prefs.theme = ThemeSwitcher.THEME_DARK
|
||||||
assertThat(prefs.theme, equalTo(ThemeSwitcher.THEME_DARK))
|
assertEquals(ThemeSwitcher.THEME_DARK, prefs.theme)
|
||||||
assertFalse(prefs.isPureBlackEnabled)
|
assertFalse(prefs.isPureBlackEnabled)
|
||||||
prefs.isPureBlackEnabled = true
|
prefs.isPureBlackEnabled = true
|
||||||
assertTrue(prefs.isPureBlackEnabled)
|
assertTrue(prefs.isPureBlackEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testNotifications() {
|
fun testNotifications() {
|
||||||
assertFalse(prefs.shouldMakeNotificationsSticky())
|
assertFalse(prefs.shouldMakeNotificationsSticky())
|
||||||
prefs.setNotificationsSticky(true)
|
prefs.setNotificationsSticky(true)
|
||||||
@ -117,21 +107,19 @@ class PreferencesTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testAppVersionAndLaunch() {
|
fun testAppVersionAndLaunch() {
|
||||||
assertThat(prefs.lastAppVersion, equalTo(0))
|
assertEquals(0, prefs.lastAppVersion)
|
||||||
prefs.lastAppVersion = 23
|
prefs.lastAppVersion = 23
|
||||||
assertThat(prefs.lastAppVersion, equalTo(23))
|
assertEquals(23, prefs.lastAppVersion)
|
||||||
assertTrue(prefs.isFirstRun)
|
assertTrue(prefs.isFirstRun)
|
||||||
prefs.isFirstRun = false
|
prefs.isFirstRun = false
|
||||||
assertFalse(prefs.isFirstRun)
|
assertFalse(prefs.isFirstRun)
|
||||||
assertThat(prefs.launchCount, equalTo(0))
|
assertEquals(0, prefs.launchCount)
|
||||||
prefs.incrementLaunchCount()
|
prefs.incrementLaunchCount()
|
||||||
assertThat(prefs.launchCount, equalTo(1))
|
assertEquals(1, prefs.launchCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testCheckmarks() {
|
fun testCheckmarks() {
|
||||||
assertFalse(prefs.isCheckmarkSequenceReversed)
|
assertFalse(prefs.isCheckmarkSequenceReversed)
|
||||||
prefs.isCheckmarkSequenceReversed = true
|
prefs.isCheckmarkSequenceReversed = true
|
||||||
@ -142,7 +130,6 @@ class PreferencesTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testDeveloper() {
|
fun testDeveloper() {
|
||||||
assertFalse(prefs.isDeveloper)
|
assertFalse(prefs.isDeveloper)
|
||||||
prefs.isDeveloper = true
|
prefs.isDeveloper = true
|
||||||
@ -150,7 +137,6 @@ class PreferencesTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testFiltering() {
|
fun testFiltering() {
|
||||||
assertFalse(prefs.showArchived)
|
assertFalse(prefs.showArchived)
|
||||||
assertTrue(prefs.showCompleted)
|
assertTrue(prefs.showCompleted)
|
||||||
@ -161,7 +147,6 @@ class PreferencesTest : BaseUnitTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
|
||||||
fun testMidnightDelay() {
|
fun testMidnightDelay() {
|
||||||
assertFalse(prefs.isMidnightDelayEnabled)
|
assertFalse(prefs.isMidnightDelayEnabled)
|
||||||
prefs.isMidnightDelayEnabled = true
|
prefs.isMidnightDelayEnabled = true
|
||||||
@ -20,14 +20,7 @@ package org.isoron.uhabits.core
|
|||||||
|
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.isoron.platform.io.JavaDatabaseOpener
|
import org.isoron.platform.io.JavaDatabaseOpener
|
||||||
import org.isoron.platform.io.TestDatabaseHelper
|
|
||||||
import org.isoron.platform.time.LocalDate
|
|
||||||
import org.isoron.platform.time.setToday
|
|
||||||
import org.isoron.uhabits.core.commands.CommandRunner
|
|
||||||
import org.isoron.uhabits.core.models.HabitList
|
|
||||||
import org.isoron.uhabits.core.models.ModelFactory
|
|
||||||
import org.isoron.uhabits.core.models.memory.MemoryModelFactory
|
import org.isoron.uhabits.core.models.memory.MemoryModelFactory
|
||||||
import org.isoron.uhabits.core.tasks.SingleThreadTaskRunner
|
|
||||||
import org.isoron.uhabits.core.test.HabitFixtures
|
import org.isoron.uhabits.core.test.HabitFixtures
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
@ -46,24 +39,14 @@ import java.util.GregorianCalendar
|
|||||||
import java.util.TimeZone
|
import java.util.TimeZone
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
@RunWith(MockitoJUnitRunner::class)
|
||||||
open class BaseUnitTest {
|
open class JvmBaseUnitTest : BaseUnitTest() {
|
||||||
protected open lateinit var habitList: HabitList
|
|
||||||
protected lateinit var fixtures: HabitFixtures
|
|
||||||
protected lateinit var modelFactory: ModelFactory
|
|
||||||
protected lateinit var taskRunner: SingleThreadTaskRunner
|
|
||||||
protected open lateinit var commandRunner: CommandRunner
|
|
||||||
protected var databaseOpener: org.isoron.platform.io.DatabaseOpener = JavaDatabaseOpener()
|
protected var databaseOpener: org.isoron.platform.io.DatabaseOpener = JavaDatabaseOpener()
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Throws(Exception::class)
|
override fun setUp() {
|
||||||
open fun setUp() {
|
super.setUp()
|
||||||
setToday(LocalDate(2015, 1, 25))
|
habitList = spy(habitList)
|
||||||
val memoryModelFactory = MemoryModelFactory()
|
fixtures = HabitFixtures(modelFactory as MemoryModelFactory, habitList)
|
||||||
habitList = spy(memoryModelFactory.buildHabitList())
|
|
||||||
fixtures = HabitFixtures(memoryModelFactory, habitList)
|
|
||||||
modelFactory = memoryModelFactory
|
|
||||||
taskRunner = SingleThreadTaskRunner()
|
|
||||||
commandRunner = CommandRunner(taskRunner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@ -112,10 +95,4 @@ open class BaseUnitTest {
|
|||||||
IOUtils.copy(original, FileOutputStream(tmpDbFile))
|
IOUtils.copy(original, FileOutputStream(tmpDbFile))
|
||||||
return databaseOpener.open(tmpDbFile.absolutePath)
|
return databaseOpener.open(tmpDbFile.absolutePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun buildMemoryDatabase(): org.isoron.platform.io.Database {
|
|
||||||
return TestDatabaseHelper.createEmptyDatabase()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -27,11 +27,11 @@ import org.isoron.platform.io.JavaFileOpener
|
|||||||
import org.isoron.platform.io.migrateTo
|
import org.isoron.platform.io.migrateTo
|
||||||
import org.isoron.platform.io.querySingle
|
import org.isoron.platform.io.querySingle
|
||||||
import org.isoron.platform.io.run
|
import org.isoron.platform.io.run
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.jupiter.api.Assertions.assertThrows
|
import org.junit.jupiter.api.Assertions.assertThrows
|
||||||
|
|
||||||
class Version22Test : BaseUnitTest() {
|
class Version22Test : JvmBaseUnitTest() {
|
||||||
private lateinit var db: Database
|
private lateinit var db: Database
|
||||||
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
|
|||||||
@ -26,10 +26,10 @@ import org.isoron.platform.io.Database
|
|||||||
import org.isoron.platform.io.JavaFileOpener
|
import org.isoron.platform.io.JavaFileOpener
|
||||||
import org.isoron.platform.io.migrateTo
|
import org.isoron.platform.io.migrateTo
|
||||||
import org.isoron.platform.io.query
|
import org.isoron.platform.io.query
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class Version23Test : BaseUnitTest() {
|
class Version23Test : JvmBaseUnitTest() {
|
||||||
|
|
||||||
private lateinit var db: Database
|
private lateinit var db: Database
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
package org.isoron.uhabits.core.io
|
package org.isoron.uhabits.core.io
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -32,7 +32,7 @@ import java.util.zip.ZipInputStream
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class HabitsCSVExporterTest : BaseUnitTest() {
|
class HabitsCSVExporterTest : JvmBaseUnitTest() {
|
||||||
private lateinit var baseDir: File
|
private lateinit var baseDir: File
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import org.hamcrest.core.IsEqual.equalTo
|
|||||||
import org.isoron.platform.io.JavaFileOpener
|
import org.isoron.platform.io.JavaFileOpener
|
||||||
import org.isoron.platform.io.JavaUserFile
|
import org.isoron.platform.io.JavaUserFile
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Frequency
|
import org.isoron.uhabits.core.models.Frequency
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
@ -36,7 +36,7 @@ import java.io.IOException
|
|||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class ImportTest : BaseUnitTest() {
|
class ImportTest : JvmBaseUnitTest() {
|
||||||
@Before
|
@Before
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
override fun setUp() {
|
override fun setUp() {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.isoron.uhabits.core.models.sqlite
|
|||||||
|
|
||||||
import org.hamcrest.CoreMatchers.equalTo
|
import org.hamcrest.CoreMatchers.equalTo
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.database.HabitRepository
|
import org.isoron.uhabits.core.database.HabitRepository
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.HabitList
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
@ -36,7 +36,7 @@ import org.mockito.kotlin.verify
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
|
|
||||||
class SQLiteHabitListTest : BaseUnitTest() {
|
class SQLiteHabitListTest : JvmBaseUnitTest() {
|
||||||
private lateinit var repository: HabitRepository
|
private lateinit var repository: HabitRepository
|
||||||
private var listener: ModelObservable.Listener = mock()
|
private var listener: ModelObservable.Listener = mock()
|
||||||
private lateinit var habitsArray: ArrayList<Habit>
|
private lateinit var habitsArray: ArrayList<Habit>
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import org.isoron.platform.time.DateUtils
|
|||||||
import org.isoron.platform.time.DateUtils.removeTimezone
|
import org.isoron.platform.time.DateUtils.removeTimezone
|
||||||
import org.isoron.platform.time.DateUtils.setFixedLocalTime
|
import org.isoron.platform.time.DateUtils.setFixedLocalTime
|
||||||
import org.isoron.platform.time.DateUtils.setFixedTimeZone
|
import org.isoron.platform.time.DateUtils.setFixedTimeZone
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.Reminder
|
import org.isoron.uhabits.core.models.Reminder
|
||||||
import org.isoron.uhabits.core.models.WeekdayList
|
import org.isoron.uhabits.core.models.WeekdayList
|
||||||
@ -40,7 +40,7 @@ import org.mockito.kotlin.whenever
|
|||||||
import java.util.TimeZone
|
import java.util.TimeZone
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner::class)
|
@RunWith(MockitoJUnitRunner::class)
|
||||||
class ReminderSchedulerTest : BaseUnitTest() {
|
class ReminderSchedulerTest : JvmBaseUnitTest() {
|
||||||
private val habitId = 10L
|
private val habitId = 10L
|
||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
private lateinit var reminderScheduler: ReminderScheduler
|
private lateinit var reminderScheduler: ReminderScheduler
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.tasks
|
package org.isoron.uhabits.core.tasks
|
||||||
|
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.junit.runners.JUnit4
|
import org.junit.runners.JUnit4
|
||||||
@ -26,7 +26,7 @@ import org.mockito.kotlin.inOrder
|
|||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
|
|
||||||
@RunWith(JUnit4::class)
|
@RunWith(JUnit4::class)
|
||||||
class SingleThreadTaskRunnerTest : BaseUnitTest() {
|
class SingleThreadTaskRunnerTest : JvmBaseUnitTest() {
|
||||||
private lateinit var runner: SingleThreadTaskRunner
|
private lateinit var runner: SingleThreadTaskRunner
|
||||||
private var task: Task = mock()
|
private var task: Task = mock()
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ package org.isoron.uhabits.core.ui.screens.habits.list
|
|||||||
import org.hamcrest.CoreMatchers.equalTo
|
import org.hamcrest.CoreMatchers.equalTo
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||||
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
|
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
@ -31,7 +31,7 @@ import org.mockito.kotlin.reset
|
|||||||
import org.mockito.kotlin.verify
|
import org.mockito.kotlin.verify
|
||||||
import org.mockito.kotlin.verifyNoMoreInteractions
|
import org.mockito.kotlin.verifyNoMoreInteractions
|
||||||
|
|
||||||
class HabitCardListCacheTest : BaseUnitTest() {
|
class HabitCardListCacheTest : JvmBaseUnitTest() {
|
||||||
private lateinit var cache: HabitCardListCache
|
private lateinit var cache: HabitCardListCache
|
||||||
private lateinit var listener: HabitCardListCache.Listener
|
private lateinit var listener: HabitCardListCache.Listener
|
||||||
var today = LocalDate(2015, 1, 25)
|
var today = LocalDate(2015, 1, 25)
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import org.hamcrest.MatcherAssert.assertThat
|
|||||||
import org.hamcrest.Matchers.equalTo
|
import org.hamcrest.Matchers.equalTo
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.preferences.Preferences
|
import org.isoron.uhabits.core.preferences.Preferences
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
@ -32,7 +32,7 @@ import kotlin.test.assertFalse
|
|||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class HintListTest : BaseUnitTest() {
|
class HintListTest : JvmBaseUnitTest() {
|
||||||
private lateinit var hintList: HintList
|
private lateinit var hintList: HintList
|
||||||
private lateinit var hints: Array<String>
|
private lateinit var hints: Array<String>
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import org.hamcrest.MatcherAssert.assertThat
|
|||||||
import org.hamcrest.core.IsEqual.equalTo
|
import org.hamcrest.core.IsEqual.equalTo
|
||||||
import org.isoron.platform.io.JavaUserFile
|
import org.isoron.platform.io.JavaUserFile
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.preferences.Preferences
|
import org.isoron.uhabits.core.preferences.Preferences
|
||||||
@ -42,7 +42,7 @@ import java.nio.file.Files
|
|||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class ListHabitsBehaviorTest : BaseUnitTest() {
|
class ListHabitsBehaviorTest : JvmBaseUnitTest() {
|
||||||
private val dirFinder: ListHabitsBehavior.DirFinder = mock()
|
private val dirFinder: ListHabitsBehavior.DirFinder = mock()
|
||||||
|
|
||||||
private val prefs: Preferences = mock()
|
private val prefs: Preferences = mock()
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.isoron.uhabits.core.ui.screens.habits.list
|
|||||||
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
import org.hamcrest.Matchers.equalTo
|
import org.hamcrest.Matchers.equalTo
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.HabitList
|
import org.isoron.uhabits.core.models.HabitList
|
||||||
import org.isoron.uhabits.core.models.HabitMatcher
|
import org.isoron.uhabits.core.models.HabitMatcher
|
||||||
import org.isoron.uhabits.core.preferences.Preferences
|
import org.isoron.uhabits.core.preferences.Preferences
|
||||||
@ -38,7 +38,7 @@ import org.mockito.kotlin.whenever
|
|||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class ListHabitsMenuBehaviorTest : BaseUnitTest() {
|
class ListHabitsMenuBehaviorTest : JvmBaseUnitTest() {
|
||||||
private lateinit var behavior: ListHabitsMenuBehavior
|
private lateinit var behavior: ListHabitsMenuBehavior
|
||||||
|
|
||||||
private val screen: ListHabitsMenuBehavior.Screen = mock()
|
private val screen: ListHabitsMenuBehavior.Screen = mock()
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.isoron.uhabits.core.ui.screens.habits.list
|
|||||||
|
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
import org.hamcrest.Matchers.equalTo
|
import org.hamcrest.Matchers.equalTo
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.isoron.uhabits.core.models.PaletteColor
|
import org.isoron.uhabits.core.models.PaletteColor
|
||||||
import org.isoron.uhabits.core.ui.callbacks.OnColorPickedCallback
|
import org.isoron.uhabits.core.ui.callbacks.OnColorPickedCallback
|
||||||
@ -36,7 +36,7 @@ import kotlin.test.assertFalse
|
|||||||
import kotlin.test.assertNull
|
import kotlin.test.assertNull
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class ListHabitsSelectionMenuBehaviorTest : BaseUnitTest() {
|
class ListHabitsSelectionMenuBehaviorTest : JvmBaseUnitTest() {
|
||||||
private val screen: ListHabitsSelectionMenuBehavior.Screen = mock()
|
private val screen: ListHabitsSelectionMenuBehavior.Screen = mock()
|
||||||
|
|
||||||
private val adapter: ListHabitsSelectionMenuBehavior.Adapter = mock()
|
private val adapter: ListHabitsSelectionMenuBehavior.Adapter = mock()
|
||||||
|
|||||||
@ -22,7 +22,7 @@ import org.apache.commons.io.FileUtils
|
|||||||
import org.hamcrest.CoreMatchers.equalTo
|
import org.hamcrest.CoreMatchers.equalTo
|
||||||
import org.hamcrest.MatcherAssert.assertThat
|
import org.hamcrest.MatcherAssert.assertThat
|
||||||
import org.isoron.platform.io.JavaUserFile
|
import org.isoron.platform.io.JavaUserFile
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.mockito.kotlin.mock
|
import org.mockito.kotlin.mock
|
||||||
@ -30,7 +30,7 @@ import org.mockito.kotlin.verify
|
|||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
class ShowHabitMenuPresenterTest : BaseUnitTest() {
|
class ShowHabitMenuPresenterTest : JvmBaseUnitTest() {
|
||||||
private lateinit var system: ShowHabitMenuPresenter.System
|
private lateinit var system: ShowHabitMenuPresenter.System
|
||||||
private lateinit var screen: ShowHabitMenuPresenter.Screen
|
private lateinit var screen: ShowHabitMenuPresenter.Screen
|
||||||
private lateinit var habit: Habit
|
private lateinit var habit: Habit
|
||||||
|
|||||||
@ -20,7 +20,7 @@ package org.isoron.uhabits.core.ui.widgets
|
|||||||
|
|
||||||
import org.isoron.platform.time.LocalDate
|
import org.isoron.platform.time.LocalDate
|
||||||
import org.isoron.platform.time.getToday
|
import org.isoron.platform.time.getToday
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValue
|
import org.isoron.uhabits.core.models.Entry.Companion.nextToggleValue
|
||||||
@ -35,7 +35,7 @@ import org.mockito.kotlin.verify
|
|||||||
import org.mockito.kotlin.verifyNoInteractions
|
import org.mockito.kotlin.verifyNoInteractions
|
||||||
import org.mockito.kotlin.whenever
|
import org.mockito.kotlin.whenever
|
||||||
|
|
||||||
class WidgetBehaviorTest : BaseUnitTest() {
|
class WidgetBehaviorTest : JvmBaseUnitTest() {
|
||||||
private lateinit var notificationTray: NotificationTray
|
private lateinit var notificationTray: NotificationTray
|
||||||
private lateinit var preferences: Preferences
|
private lateinit var preferences: Preferences
|
||||||
private lateinit var behavior: WidgetBehavior
|
private lateinit var behavior: WidgetBehavior
|
||||||
|
|||||||
@ -2,12 +2,12 @@ package org.isoron.uhabits.core.utils
|
|||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.isoron.platform.io.JavaUserFile
|
import org.isoron.platform.io.JavaUserFile
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class FileExtensionsTest : BaseUnitTest() {
|
class FileExtensionsTest : JvmBaseUnitTest() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testIsSQLite3File() = runBlocking {
|
fun testIsSQLite3File() = runBlocking {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import kotlinx.coroutines.asCoroutineDispatcher
|
|||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.isoron.platform.time.DateUtils
|
import org.isoron.platform.time.DateUtils
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.JvmBaseUnitTest
|
||||||
import org.isoron.uhabits.core.io.StandardLogging
|
import org.isoron.uhabits.core.io.StandardLogging
|
||||||
import org.isoron.uhabits.core.preferences.Preferences
|
import org.isoron.uhabits.core.preferences.Preferences
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
@ -17,7 +17,7 @@ import kotlin.coroutines.resume
|
|||||||
import kotlin.coroutines.suspendCoroutine
|
import kotlin.coroutines.suspendCoroutine
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class MidnightTimerTest : BaseUnitTest() {
|
class MidnightTimerTest : JvmBaseUnitTest() {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
override fun tearDown() {
|
override fun tearDown() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user