Skip to content

Commit d60d74b

Browse files
authored
Fix tests when current streak is 0 (#199)
1 parent 0b0ce86 commit d60d74b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/StatsTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ public function testValidUsername(): void
5656
// test length of longest streak matches time between start and end dates
5757
$longestStreakDelta = strtotime($stats["longestStreak"]["end"]) - strtotime($stats["longestStreak"]["start"]);
5858
$this->assertEquals($longestStreakDelta / 60 / 60 / 24 + 1, $stats["longestStreak"]["length"]);
59+
// if the current streak is 0, the start date should be the same as the end date
60+
if ($stats["currentStreak"]["length"] == 0) {
61+
$this->assertEquals($stats["currentStreak"]["start"], $stats["currentStreak"]["end"]);
62+
}
5963
// test length of current streak matches time between start and end dates
60-
$currentStreakDelta = strtotime($stats["currentStreak"]["end"]) - strtotime($stats["currentStreak"]["start"]);
61-
$this->assertEquals($currentStreakDelta / 60 / 60 / 24 + 1, $stats["currentStreak"]["length"]);
64+
else {
65+
$currentStreakDelta = strtotime($stats["currentStreak"]["end"]) - strtotime($stats["currentStreak"]["start"]);
66+
$this->assertEquals($currentStreakDelta / 60 / 60 / 24 + 1, $stats["currentStreak"]["length"]);
67+
}
6268
}
6369

6470
/**

0 commit comments

Comments
 (0)