From 56d606ac53a739642b8e42417ccd36c1896de24f Mon Sep 17 00:00:00 2001 From: Jacob Bosco Date: Sat, 29 Oct 2022 13:11:26 +0530 Subject: [PATCH] WTA #44: Fixed test that checks for streak across multiple months. --- .../domain/RecalculateLatestStreakService.kt | 2 - .../RecalculateLatestStreakServiceTest.kt | 60 +++++++++++++++---- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt b/home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt index bc4351cb..ccb2832b 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt @@ -31,7 +31,6 @@ class RecalculateLatestStreakService @Inject constructor( .getLatestStreakInRange() } .map { - println("it: $it, start: $start, end: $end, count: $count, days: ${it.days}") when (it.days) { count -> { val streakFromNextDuration = calculate( @@ -39,7 +38,6 @@ class RecalculateLatestStreakService @Inject constructor( value = value, unit = unit ).bind() - println("streakFromNextDuration: $streakFromNextDuration") if (streakFromNextDuration == StreakRange.ZERO) it else it + streakFromNextDuration } diff --git a/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt b/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt index eaa759a9..2d0b5312 100644 --- a/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt +++ b/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt @@ -247,16 +247,38 @@ internal class RecalculateLatestStreakServiceTest { runTest { val start1 = LocalDate(2022, 4, 30) val end1 = start1.minus(1, DateTimeUnit.MONTH) + val count1 = end1.daysUntil(start1) + 1 + val days1 = List(count1) { it } + val start2 = end1.minus(1, DateTimeUnit.DAY) val end2 = start2.minus(1, DateTimeUnit.MONTH) + val count2 = end2.daysUntil(start2) + 1 + val days2 = List(count2) { it } + val start3 = end2.minus(1, DateTimeUnit.DAY) val end3 = start3.minus(1, DateTimeUnit.MONTH) + val count3 = end3.daysUntil(start3) + 1 + val days3 = List(count3) { it } + val start4 = end3.minus(1, DateTimeUnit.DAY) val end4 = start4.minus(1, DateTimeUnit.MONTH) + val count4 = end4.daysUntil(start4) + 1 + val days4 = List(count4) { it } + val start5 = end4.minus(1, DateTimeUnit.DAY) val end5 = start5.minus(1, DateTimeUnit.MONTH) - val count = end1.daysUntil(start1) + 1 - val days = List(count) { it } + val count5 = end5.daysUntil(start5) + 1 + val days5 = List(count5) { it } + + val start6 = end5.minus(1, DateTimeUnit.DAY) + val end6 = start6.minus(1, DateTimeUnit.MONTH) + val count6 = end6.daysUntil(start6) + 1 + val days6 = List(count6) { it } + + val start7 = end6.minus(1, DateTimeUnit.DAY) + val end7 = start7.minus(1, DateTimeUnit.MONTH) + val count7 = end7.daysUntil(start7) + 1 + val days7 = emptyList() robot.buildService() .mockGetDataForRange( @@ -264,7 +286,7 @@ internal class RecalculateLatestStreakServiceTest { end1.toString(), Stats( totalTime = Time.ZERO, - dailyStats = createDailyStats(count, days, end1), + dailyStats = createDailyStats(count1, days1, end1), range = StatsRange(start1, end1) ).right(), ) @@ -273,7 +295,7 @@ internal class RecalculateLatestStreakServiceTest { end2.toString(), Stats( totalTime = Time.ZERO, - dailyStats = createDailyStats(count, days, end2), + dailyStats = createDailyStats(count2, days2, end2), range = StatsRange(start2, end2) ).right(), ) @@ -282,11 +304,7 @@ internal class RecalculateLatestStreakServiceTest { end3.toString(), Stats( totalTime = Time.ZERO, - dailyStats = createDailyStats( - count, - days.take(end3.daysUntil(start3) + 1), - end3 - ), + dailyStats = createDailyStats(count3, days3, end3), range = StatsRange(start3, end3) ).right(), ) @@ -295,7 +313,7 @@ internal class RecalculateLatestStreakServiceTest { end4.toString(), Stats( totalTime = Time.ZERO, - dailyStats = createDailyStats(count, days, end4), + dailyStats = createDailyStats(count4, days4, end4), range = StatsRange(start4, end4) ).right(), ) @@ -304,10 +322,28 @@ internal class RecalculateLatestStreakServiceTest { end5.toString(), Stats( totalTime = Time.ZERO, - dailyStats = createDailyStats(count, emptyList(), end5), + dailyStats = createDailyStats(count5, days5, end5), range = StatsRange(start5, end5) ).right(), ) + .mockGetDataForRange( + start6.toString(), + end6.toString(), + Stats( + totalTime = Time.ZERO, + dailyStats = createDailyStats(count6, days6, end6), + range = StatsRange(start6, end6) + ).right(), + ) + .mockGetDataForRange( + start7.toString(), + end7.toString(), + Stats( + totalTime = Time.ZERO, + dailyStats = createDailyStats(count7, days7, end7), + range = StatsRange(start7, end7) + ).right(), + ) .calculate( start = start1, value = 1, @@ -315,7 +351,7 @@ internal class RecalculateLatestStreakServiceTest { ) .resultShouldBe( StreakRange( - start = end4, + start = end6, end = start1, ).right() )