mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
buildEntriesFromInterval: selectively copy over
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.isoron.uhabits.core.models
|
||||
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||
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_MANUAL
|
||||
@@ -258,7 +259,7 @@ open class EntryList {
|
||||
/**
|
||||
* Converts a list of intervals into a list of entries. Entries that fall outside of any
|
||||
* interval receive value UNKNOWN. Entries that fall within an interval but do not appear
|
||||
* in [original] receive value YES_AUTO. Entries provided in [original] are just copied over.
|
||||
* in [original] receive value YES_AUTO. Entries provided in [original] are copied over.
|
||||
*
|
||||
* The intervals should be sorted by timestamp. The first element in the list should
|
||||
* correspond to the newest interval.
|
||||
@@ -303,8 +304,10 @@ open class EntryList {
|
||||
// Copy original entries
|
||||
original.forEach { entry ->
|
||||
val offset = entry.timestamp.daysUntil(to)
|
||||
if (result[offset].value == UNKNOWN || entry.value == SKIP || entry.value == YES_MANUAL) {
|
||||
result[offset] = entry
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -248,8 +248,10 @@ class EntryListTest {
|
||||
val entries = listOf(
|
||||
Entry(day(1), YES_MANUAL),
|
||||
Entry(day(2), NO),
|
||||
Entry(day(4), NO),
|
||||
Entry(day(5), YES_MANUAL),
|
||||
Entry(day(10), YES_MANUAL),
|
||||
Entry(day(11), NO),
|
||||
)
|
||||
val intervals = listOf(
|
||||
EntryList.Interval(day(2), day(2), day(1)),
|
||||
@@ -258,7 +260,7 @@ class EntryListTest {
|
||||
)
|
||||
val expected = listOf(
|
||||
Entry(day(1), YES_MANUAL),
|
||||
Entry(day(2), NO),
|
||||
Entry(day(2), YES_AUTO),
|
||||
Entry(day(3), UNKNOWN),
|
||||
Entry(day(4), YES_AUTO),
|
||||
Entry(day(5), YES_MANUAL),
|
||||
@@ -267,6 +269,7 @@ class EntryListTest {
|
||||
Entry(day(8), YES_AUTO),
|
||||
Entry(day(9), YES_AUTO),
|
||||
Entry(day(10), YES_MANUAL),
|
||||
Entry(day(11), NO),
|
||||
)
|
||||
val actual = EntryList.buildEntriesFromInterval(entries, intervals)
|
||||
assertThat(actual, equalTo(expected))
|
||||
|
||||
Reference in New Issue
Block a user