-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9 switch to absolute values rather than % when looking for spikes
- Loading branch information
1 parent
0165a74
commit 850ef42
Showing
6 changed files
with
87 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package bad.robot.temperature | ||
|
||
import java.lang.Math._ | ||
|
||
case class Barrier(degrees: Degrees) { | ||
|
||
def breached(previous: Temperature, current: Temperature) = { | ||
abs(current.celsius - previous.celsius) > degrees | ||
} | ||
} |
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 |
---|---|---|
|
@@ -19,4 +19,4 @@ object PercentageDifference { | |
case _ => BigDecimal(value).setScale(2, RoundingMode.HALF_UP).toDouble | ||
} | ||
|
||
} | ||
} |
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,37 @@ | ||
package bad.robot.temperature | ||
|
||
import org.specs2.mutable.Specification | ||
|
||
import scala.Double._ | ||
|
||
class BarrierTest extends Specification { | ||
|
||
"No breach" >> { | ||
val barrier = Barrier(5) | ||
barrier.breached(Temperature(10.23), Temperature(11.22)) must_== false | ||
barrier.breached(Temperature(-10.23), Temperature(-10.23)) must_== false | ||
barrier.breached(Temperature(0), Temperature(0)) must_== false | ||
barrier.breached(Temperature(23.12), Temperature(23.12)) must_== false | ||
barrier.breached(Temperature(23.12), Temperature(24.11)) must_== false | ||
} | ||
|
||
"Positive breach" >> { | ||
val barrier = Barrier(1) | ||
barrier.breached(Temperature(10.23), Temperature(11.24)) must_== true | ||
barrier.breached(Temperature(10.24), Temperature(11.23)) must_== false | ||
} | ||
|
||
"Negative breach" >> { | ||
val barrier = Barrier(1) | ||
barrier.breached(Temperature(-10.23), Temperature(-11.24)) must_== true | ||
barrier.breached(Temperature(-10.24), Temperature(-11.23)) must_== false | ||
} | ||
|
||
"NaN" >> { | ||
val barrier = Barrier(1) | ||
barrier.breached(Temperature(-10.23), Temperature(NaN)) must_== false | ||
barrier.breached(Temperature(NaN), Temperature(10.23)) must_== false | ||
barrier.breached(Temperature(NaN), Temperature(NaN)) must_== false | ||
} | ||
|
||
} |
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