mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-10 02:58:51 -06:00
Tweak snapIntervalsTogether so that "1 time every x days" habits work better
This commit is contained in:
@@ -319,16 +319,31 @@ public class CheckmarkListTest extends BaseUnitTest
|
||||
public void test_snapIntervalsTogether_1() throws Exception
|
||||
{
|
||||
ArrayList<CheckmarkList.Interval> original = new ArrayList<>();
|
||||
original.add(new CheckmarkList.Interval(day(40), day(40), day(34)));
|
||||
original.add(new CheckmarkList.Interval(day(25), day(25), day(19)));
|
||||
original.add(new CheckmarkList.Interval(day(16), day(16), day(10)));
|
||||
original.add(new CheckmarkList.Interval(day(27), day(27), day(21)));
|
||||
original.add(new CheckmarkList.Interval(day(20), day(20), day(14)));
|
||||
original.add(new CheckmarkList.Interval(day(12), day(12), day(6)));
|
||||
original.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
||||
|
||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||
expected.add(new CheckmarkList.Interval(day(40), day(40), day(34)));
|
||||
expected.add(new CheckmarkList.Interval(day(25), day(25), day(19)));
|
||||
expected.add(new CheckmarkList.Interval(day(18), day(16), day(12)));
|
||||
expected.add(new CheckmarkList.Interval(day(11), day(8), day(5)));
|
||||
expected.add(new CheckmarkList.Interval(day(29), day(27), day(23)));
|
||||
expected.add(new CheckmarkList.Interval(day(22), day(20), day(16)));
|
||||
expected.add(new CheckmarkList.Interval(day(15), day(12), day(9)));
|
||||
expected.add(new CheckmarkList.Interval(day(8), day(8), day(2)));
|
||||
|
||||
CheckmarkList.snapIntervalsTogether(original);
|
||||
assertThat(original, equalTo(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_snapIntervalsTogether_2() throws Exception
|
||||
{
|
||||
ArrayList<CheckmarkList.Interval> original = new ArrayList<>();
|
||||
original.add(new CheckmarkList.Interval(day(11), day(8), day(5)));
|
||||
original.add(new CheckmarkList.Interval(day(6), day(4), day(0)));
|
||||
|
||||
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
|
||||
expected.add(new CheckmarkList.Interval(day(13), day(8), day(7)));
|
||||
expected.add(new CheckmarkList.Interval(day(6), day(4), day(0)));
|
||||
|
||||
CheckmarkList.snapIntervalsTogether(original);
|
||||
assertThat(original, equalTo(expected));
|
||||
|
||||
@@ -153,9 +153,9 @@ public class ScoreListTest extends BaseUnitTest
|
||||
habit.getScores().groupBy(DateUtils.TruncateField.MONTH, Calendar.SATURDAY);
|
||||
|
||||
assertThat(list.size(), equalTo(5));
|
||||
assertThat(list.get(0).getValue(), closeTo(0.653659, E));
|
||||
assertThat(list.get(1).getValue(), closeTo(0.622715, E));
|
||||
assertThat(list.get(2).getValue(), closeTo(0.520997, E));
|
||||
assertThat(list.get(0).getValue(), closeTo(0.687724, E));
|
||||
assertThat(list.get(1).getValue(), closeTo(0.636747, E));
|
||||
assertThat(list.get(2).getValue(), closeTo(0.533860, E));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user