diff --git a/src/test/scala/com/github/agourlay/cornichon/examples/math/MathScenario.scala b/src/test/scala/com/github/agourlay/cornichon/examples/math/MathScenario.scala index 0cbbe570c..d4f525de9 100644 --- a/src/test/scala/com/github/agourlay/cornichon/examples/math/MathScenario.scala +++ b/src/test/scala/com/github/agourlay/cornichon/examples/math/MathScenario.scala @@ -18,7 +18,7 @@ class MathScenario extends CornichonFeature with MathSteps { } - Scenario("Random draw should eventually converge") { + Scenario("Random draw should eventually be identical") { When I generate_random_int("random-1") @@ -33,7 +33,7 @@ class MathScenario extends CornichonFeature with MathSteps { Scenario("MonteCarlo approximation of PI") { - Repeat(1000) { + Repeat(5000) { Given I generate_random_double("x") @@ -45,7 +45,9 @@ class MathScenario extends CornichonFeature with MathSteps { And I estimate_pi_from_ratio("inside", "pi") - Then assert double_value_between("pi", 3.10, 3.16) + Then assert double_value("pi").isBetween(3.1, 3.2) + + And I show_session("pi") } } diff --git a/src/test/scala/com/github/agourlay/cornichon/examples/math/MathSteps.scala b/src/test/scala/com/github/agourlay/cornichon/examples/math/MathSteps.scala index b7161c4b4..42f2c67cb 100644 --- a/src/test/scala/com/github/agourlay/cornichon/examples/math/MathSteps.scala +++ b/src/test/scala/com/github/agourlay/cornichon/examples/math/MathSteps.scala @@ -20,7 +20,7 @@ trait MathSteps { def generate_random_int(target: String, max: Int = 100) = EffectStep( - title = s"Generate random Int into $target (max=$max)", + title = s"Generate random Int into '$target' (max=$max)", effect = s ⇒ { s.addValue(target, Random.nextInt(max).toString) } @@ -28,22 +28,24 @@ trait MathSteps { def generate_random_double(target: String) = EffectStep( - title = s"Generate random Double into $target", + title = s"Generate random Double into '$target'", effect = s ⇒ { s.addValue(target, Random.nextDouble().toString) } ) - def double_value_between(source: String, low: Double, high: Double) = - AssertStep( - title = s"Double value of $source is between $low and $high", - action = s ⇒ { - val v = s.get(source).toDouble - DetailedStepAssertion(true, v > low && v < high, ratioError(v, low, high)) - } - ) + case class double_value(source: String) { + def isBetween(low: Double, high: Double) = + AssertStep( + title = s"Double value of '$source' is between '$low' and '$high'", + action = s ⇒ { + val v = s.get(source).toDouble + DetailedStepAssertion(true, v > low && v < high, ratioError(v, low, high)) + } + ) + } - def ratioError(v: Double, low: Double, high: Double): Boolean ⇒ String = b ⇒ s"$v is not between $low and $high" + private def ratioError(v: Double, low: Double, high: Double): Boolean ⇒ String = b ⇒ s"$v is not between $low and $high" def calculate_point_in_circle(target: String) = EffectStep( title = s"Calculate points inside circle", @@ -57,7 +59,7 @@ trait MathSteps { def estimate_pi_from_ratio(inside: String, target: String) = EffectStep( - title = s"Estimate PI from ration into $target", + title = s"Estimate PI from ration into key '$target'", effect = s ⇒ { val insides = s.getHistory(inside) val trial = insides.size