Make skips freeze score (#630)

pull/644/head
Kristian Tashkov 5 years ago committed by GitHub
parent f44556e281
commit a4ef657897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -286,7 +286,7 @@ public abstract class ScoreList implements Iterable<Score>
double percentageCompleted = Math.min(1, rollingSum / 1000 / habit.getTargetValue()); double percentageCompleted = Math.min(1, rollingSum / 1000 / habit.getTargetValue());
previousValue = Score.compute(1.0, previousValue, percentageCompleted); previousValue = Score.compute(1.0, previousValue, percentageCompleted);
} }
else else if (checkmarkValues[offset] != Checkmark.SKIP)
{ {
double value = Math.min(1, checkmarkValues[offset]); double value = Math.min(1, checkmarkValues[offset]);
previousValue = Score.compute(freq, previousValue, value); previousValue = Score.compute(freq, previousValue, value);

@ -125,6 +125,49 @@ public class ScoreListTest extends BaseUnitTest
} }
} }
@Test
public void test_getValueWithSkip()
{
toggleRepetitions(0, 20);
addSkip(5);
addSkip(10);
addSkip(11);
double expectedValues[] = {
0.596033,
0.573910,
0.550574,
0.525961,
0.500000,
0.472617,
0.472617,
0.443734,
0.413270,
0.381137,
0.347244,
0.347244,
0.347244,
0.311495,
0.273788,
0.234017,
0.192067,
0.147820,
0.101149,
0.051922,
0.000000,
0.000000,
0.000000
};
ScoreList scores = habit.getScores();
Timestamp current = DateUtils.getToday();
for (double expectedValue : expectedValues)
{
assertThat(scores.getValue(current), closeTo(expectedValue, E));
current = current.minus(1);
}
}
@Test @Test
public void test_getValues() public void test_getValues()
{ {
@ -197,4 +240,11 @@ public class ScoreListTest extends BaseUnitTest
for (int i = from; i < to; i++) for (int i = from; i < to; i++)
reps.toggle(today.minus(i)); reps.toggle(today.minus(i));
} }
private void addSkip(final int day)
{
RepetitionList reps = habit.getRepetitions();
Timestamp today = DateUtils.getToday();
reps.toggle(today.minus(day), Checkmark.SKIP);
}
} }

Loading…
Cancel
Save