-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from amanjpro/upkeep/add-oldest-missing-period…
…-age-to-api Upkeep/add oldest missing period age to api
- Loading branch information
Showing
10 changed files
with
135 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package me.amanj.greenish | ||
|
||
import me.amanj.greenish.models.PeriodHealth | ||
|
||
package object checker { | ||
protected[checker] def computeOldest(periodHealths: Seq[PeriodHealth]): Int = { | ||
val missingIndex = periodHealths.indexWhere(!_.ok) | ||
if(missingIndex == -1) 0 | ||
else periodHealths.length - missingIndex | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package me.amanj.greenish.checker | ||
|
||
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
import me.amanj.greenish.models.PeriodHealth | ||
|
||
class CheckerSpec() extends AnyWordSpecLike with Matchers { | ||
|
||
"computeOldest" must { | ||
"work for empty period health lists" in { | ||
val periods = Seq.empty[PeriodHealth] | ||
val actual = computeOldest(periods) | ||
val expected = 0 | ||
actual shouldBe expected | ||
} | ||
|
||
"work when the first period is missing" in { | ||
val periods = Seq( | ||
PeriodHealth("kaka", false), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
) | ||
val actual = computeOldest(periods) | ||
val expected = 4 | ||
actual shouldBe expected | ||
} | ||
|
||
"work when a middle period is missing" in { | ||
val periods = Seq( | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", false), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
) | ||
val actual = computeOldest(periods) | ||
val expected = 3 | ||
actual shouldBe expected | ||
} | ||
|
||
"work when the last period is missing" in { | ||
val periods = Seq( | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", false), | ||
) | ||
val actual = computeOldest(periods) | ||
val expected = 1 | ||
actual shouldBe expected | ||
} | ||
|
||
"work when more than a period is missing" in { | ||
val periods = Seq( | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", false), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", false), | ||
) | ||
val actual = computeOldest(periods) | ||
val expected = 3 | ||
actual shouldBe expected | ||
} | ||
|
||
"work when no period is missing" in { | ||
val periods = Seq( | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
PeriodHealth("kaka", true), | ||
) | ||
val actual = computeOldest(periods) | ||
val expected = 0 | ||
actual shouldBe expected | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters