Skip to content

Commit

Permalink
#9 include spiked temperature in output
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyweston committed Oct 11, 2017
1 parent 8875fd2 commit a9318be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ class ErrorOnTemperatureSpike(delegate: TemperatureWriter) extends TemperatureWr

def write(measurement: Measurement): Error \/ Unit = {

val spiked = measurement.temperatures.filter(current => {
val spiked = measurement.temperatures.flatMap(current => {
temperatures.get(current.name) match {
case Some(previous) if spikeBetween(current, previous) => true
case _ => false
case Some(previous) if spikeBetween(current, previous) => List((current.name, previous, current.temperature))
case _ => Nil
}
})

if (spiked.nonEmpty) {
-\/(SensorSpikeError(spiked.map(_.name), spiked.map(_.temperature), List()))
-\/(SensorSpikeError(spiked.map(_._1), previous = spiked.map(_._2), current = spiked.map(_._3)))
} else {
measurement.temperatures.foreach(current => temperatures.update(current.name, current.temperature))
delegate.write(measurement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class ErrorOnTemperatureSpikeTest extends Specification {
case e: SensorSpikeError => e.message must_==
"""An unexpected spike was encountered on:
| sensor(s) : A
| previous temperatures : 51.1 °C
| spiked temperatures :
| previous temperatures : 21.6 °C
| spiked temperatures : 51.1 °C
|""".stripMargin
}
}
Expand All @@ -113,8 +113,8 @@ class ErrorOnTemperatureSpikeTest extends Specification {
case e: SensorSpikeError => e.message must_==
"""An unexpected spike was encountered on:
| sensor(s) : A1, A2
| previous temperatures : 51.4 °C, 51.1 °C
| spiked temperatures :
| previous temperatures : 21.1 °C, 21.3 °C
| spiked temperatures : 51.4 °C, 51.1 °C
|""".stripMargin
}
}
Expand Down

0 comments on commit a9318be

Please sign in to comment.