mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Add missing tests for RepetitionList and Habit
This commit is contained in:
@@ -43,7 +43,7 @@ public class ToggleRepetitionCommand extends Command
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
habit.getRepetitions().toggleTimestamp(timestamp);
|
||||
habit.getRepetitions().toggle(timestamp);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
@@ -322,7 +322,13 @@ public class Habit
|
||||
public synchronized boolean isCompletedToday()
|
||||
{
|
||||
int todayCheckmark = getCheckmarks().getTodayValue();
|
||||
if (isNumerical()) return todayCheckmark >= data.targetValue;
|
||||
if (isNumerical())
|
||||
{
|
||||
if(getTargetType() == AT_LEAST)
|
||||
return todayCheckmark >= data.targetValue;
|
||||
else
|
||||
return todayCheckmark <= data.targetValue;
|
||||
}
|
||||
else return (todayCheckmark != UNCHECKED);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ public abstract class RepetitionList
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Repetition getOldest();
|
||||
|
||||
@Nullable
|
||||
/**
|
||||
* Returns the newest repetition in the list.
|
||||
@@ -184,8 +185,11 @@ public abstract class RepetitionList
|
||||
* @return the repetition that has been added or removed.
|
||||
*/
|
||||
@NonNull
|
||||
public Repetition toggleTimestamp(long timestamp)
|
||||
public Repetition toggle(long timestamp)
|
||||
{
|
||||
if(habit.isNumerical())
|
||||
throw new IllegalStateException("habit must NOT be numerical");
|
||||
|
||||
timestamp = DateUtils.getStartOfDay(timestamp);
|
||||
Repetition rep = getByTimestamp(timestamp);
|
||||
|
||||
@@ -207,4 +211,15 @@ public abstract class RepetitionList
|
||||
*/
|
||||
@NonNull
|
||||
public abstract long getTotalCount();
|
||||
|
||||
public void toggle(long timestamp, int value)
|
||||
{
|
||||
if(!habit.isNumerical())
|
||||
throw new IllegalStateException("habit must be numerical");
|
||||
|
||||
Repetition rep = getByTimestamp(timestamp);
|
||||
if(rep != null) remove(rep);
|
||||
add(new Repetition(timestamp, value));
|
||||
habit.invalidateNewerThan(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class HabitFixtures
|
||||
81, 83, 89, 90, 91, 95, 102, 103, 108, 109, 120};
|
||||
|
||||
for (int mark : marks)
|
||||
habit.getRepetitions().toggleTimestamp(today - mark * day);
|
||||
habit.getRepetitions().toggle(today - mark * day);
|
||||
|
||||
return habit;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class HabitFixtures
|
||||
long timestamp = DateUtils.getStartOfToday();
|
||||
for (boolean c : NON_DAILY_HABIT_CHECKS)
|
||||
{
|
||||
if (c) habit.getRepetitions().toggleTimestamp(timestamp);
|
||||
if (c) habit.getRepetitions().toggle(timestamp);
|
||||
timestamp -= DateUtils.millisecondsInOneDay;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user