ScoreList: Fix interaction between SKIP and rolling sum

pull/655/head
Alinson S. Xavier 5 years ago
parent c429cb41c0
commit ddea9e78a9

@ -298,17 +298,19 @@ 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(freq, previousValue, percentageCompleted); previousValue = Score.compute(freq, previousValue, percentageCompleted);
} }
else if (checkmarkValues[offset] != Checkmark.SKIP) else
{ {
if (checkmarkValues[offset] == YES_MANUAL) if (checkmarkValues[offset] == YES_MANUAL)
rollingSum += 1.0; rollingSum += 1.0;
if (offset + denominator < checkmarkValues.length) if (offset + denominator < checkmarkValues.length)
if (checkmarkValues[offset + denominator] == YES_MANUAL) if (checkmarkValues[offset + denominator] == YES_MANUAL)
rollingSum -= 1.0; rollingSum -= 1.0;
if (checkmarkValues[offset] != SKIP)
{
double percentageCompleted = Math.min(1, rollingSum / numerator); double percentageCompleted = Math.min(1, rollingSum / numerator);
previousValue = Score.compute(freq, previousValue, percentageCompleted); previousValue = Score.compute(freq, previousValue, percentageCompleted);
} }
}
scores.add(new Score(from.plus(i), previousValue)); scores.add(new Score(from.plus(i), previousValue));
} }

@ -20,7 +20,6 @@
package org.isoron.uhabits.core.models; package org.isoron.uhabits.core.models;
import org.isoron.uhabits.core.*; import org.isoron.uhabits.core.*;
import org.isoron.uhabits.core.test.*;
import org.isoron.uhabits.core.utils.*; import org.isoron.uhabits.core.utils.*;
import org.junit.*; import org.junit.*;
@ -119,13 +118,7 @@ public class ScoreListTest extends BaseUnitTest
0.000000 0.000000
}; };
ScoreList scores = habit.getScores(); checkScoreValues(expectedValues);
Timestamp current = DateUtils.getToday();
for (double expectedValue : expectedValues)
{
assertThat(scores.getValue(current), closeTo(expectedValue, E));
current = current.minus(1);
}
} }
@Test @Test
@ -162,13 +155,26 @@ public class ScoreListTest extends BaseUnitTest
0.000000 0.000000
}; };
ScoreList scores = habit.getScores(); checkScoreValues(expectedValues);
Timestamp current = DateUtils.getToday();
for (double expectedValue : expectedValues)
{
assertThat(scores.getValue(current), closeTo(expectedValue, E));
current = current.minus(1);
} }
@Test
public void test_getValueWithSkip2()
{
toggle(5);
addSkip(4);
double[] expectedValues = {
0.041949,
0.044247,
0.046670,
0.049226,
0.051922,
0.051922,
0.0
};
checkScoreValues(expectedValues);
} }
@Test @Test
@ -349,4 +355,15 @@ public class ScoreListTest extends BaseUnitTest
Timestamp today = DateUtils.getToday(); Timestamp today = DateUtils.getToday();
reps.toggle(today.minus(day), Checkmark.SKIP); reps.toggle(today.minus(day), Checkmark.SKIP);
} }
private void checkScoreValues(double[] expectedValues)
{
Timestamp current = DateUtils.getToday();
ScoreList scores = habit.getScores();
for (double expectedValue : expectedValues)
{
assertThat(scores.getValue(current), closeTo(expectedValue, E));
current = current.minus(1);
}
}
} }

Loading…
Cancel
Save