Add missing tests for RepetitionList and Habit

This commit is contained in:
2017-05-30 08:19:28 -04:00
parent 8a29fbf07d
commit 6ccfb53329
12 changed files with 118 additions and 27 deletions

View File

@@ -43,7 +43,7 @@ public class ToggleRepetitionCommand extends Command
@Override
public void execute()
{
habit.getRepetitions().toggleTimestamp(timestamp);
habit.getRepetitions().toggle(timestamp);
}
@NonNull

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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;
}