Skip to content

Commit

Permalink
Changing scalatest to scalacheck
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghaffari1992 committed Dec 16, 2022
1 parent a6b98ab commit 6f34d04
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/test/scala/symsim/examples/concrete/pumping/PumpSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import symsim.concrete.Randomized.given
import CanTestIn.given
import CanTestIn.*

import org.scalatest.*
import prop.*
import org.scalacheck.{Arbitrary, Gen, Prop}
import org.scalacheck.Arbitrary.*
import org.scalacheck.Gen
import org.scalatest.prop.Whenever
import org.scalacheck.Prop.{forAll, forAllNoShrink, propBoolean, exists}
import org.scalacheck.Prop.forAll
import org.scalacheck.Prop.*
import examples.concrete.pumping.*

/** Sanity tests for Randomized as a Scheduler */
class PumpSpec
extends org.scalatest.freespec.AnyFreeSpec,
org.scalatestplus.scalacheck.Checkers:
// To eliminate the warning on Pumping, until scalacheck makes it open
import scala.language.adhocExtensions


"Sanity checks for symsim.concrete.pumping" - {
class PumpSpec
extends org.scalacheck.Properties ("Pumping"):

// Generators of test data
val flow = Gen.choose[Double] (FLOW_MIN, FLOW_MAX)
Expand All @@ -35,42 +32,40 @@ class PumpSpec

// Tests

"The tank level never can be negative" in check {
property ("The tank level never can be negative") = {
forAll (flow, head, head_mean, tank, time, water, past_head_mean, actions) {
(f, h, hm, tl, t, w, phm, a) =>
for (s1, r) <- Pump.step (PumpState (f, h, hm, tl, t, w, phm)) (a)
yield s1.tl >= TANK_MIN
}
}

"There is an observable state for each valid state in the environment" in check {
forAllNoShrink (flow, head, head_mean, tank, time, water, past_head_mean, actions) {
property ("There is an observable state for each valid state in the environment") = {
forAll (flow, head, head_mean, tank, time, water, past_head_mean, actions) {
(f, h, hm, tl, t, w, phm, a) =>
val (s1, r) = Pump.step (PumpState (f, h, hm, tl, t, w, phm)) (a).head
exists (obsStates) {s => s == Pump.discretize (s1)}
exists (obsStates) {s => s == Pump.observe (s1)}
}
}

"The time can be more than TANK_MAX (comparing is not correct)" in check {
property ("The time can be more than TANK_MAX (comparing is not correct)") = {
exists (time) { t =>
t > TANK_MAX
}
}

"Test getDemand" in check {
forAllNoShrink (time) { t1 =>
property ("Test getDemand") = {
forAll (time) { t1 =>
exists (time) {t2 => Pump.getDemand (t1) != Pump.getDemand (t2)}
}
}

"There is an action for each state which results no overflow" in check {
forAllNoShrink(flow, head, head_mean, tank, time, water, past_head_mean) {
property ("There is an action for each state which results no overflow") = {
forAll (flow, head, head_mean, tank, time, water, past_head_mean) {
(f, h, hm, tl, t, w, phm) =>
exists(actions) { a =>
for (s1, r) <- Pump.step(PumpState(f, h, hm, tl, t, w, phm))(a)
yield (s1.tl <= TANK_MAX)
}
}
}

}

0 comments on commit 6f34d04

Please sign in to comment.