-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate MinutesSpec to use ScalaCheckDrivenPropertyChecks
- Loading branch information
Showing
4 changed files
with
32 additions
and
38 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 |
---|---|---|
@@ -1,52 +1,33 @@ | ||
package wen.types | ||
|
||
import eu.timepit.refined.{W, refineV} | ||
import eu.timepit.refined.numeric.Interval | ||
import org.scalacheck.{Arbitrary, Gen} | ||
import org.scalacheck.Prop.forAll | ||
import org.scalactic.TypeCheckedTripleEquals | ||
import org.scalatestplus.scalacheck.Checkers | ||
import org.scalatest.{Matchers, WordSpec} | ||
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks | ||
import wen.test.Arbitraries._ | ||
import wen.test.Generators._ | ||
import wen.refine.refineMinute | ||
import wen.types.NumericTypes.NumericMinute | ||
|
||
class MinuteSpec extends WordSpec with Matchers with TypeCheckedTripleEquals with Checkers { | ||
class MinuteSpec extends WordSpec with Matchers with TypeCheckedTripleEquals with ScalaCheckDrivenPropertyChecks { | ||
|
||
"Minute" should { | ||
|
||
"be created with a value between 0 and 59" in { | ||
|
||
val minute = for { | ||
m <- Gen.choose(0, 59) | ||
} yield Minute(m) | ||
|
||
val prop = forAll(minute) { m => | ||
m !==(None) | ||
} | ||
check(prop) | ||
"be created with a value between 0 and 59" in forAll { minute: Option[Minute] => | ||
minute should !==(None) | ||
} | ||
|
||
"fail to be created with an Minute not between 0 and 59" in { | ||
val minute = for { | ||
m <- Arbitrary.arbitrary[Int] suchThat (x => x < 0 || x > 59) | ||
} yield Minute(m) | ||
|
||
val prop = forAll(minute) { m => | ||
m ===(None) | ||
} | ||
check(prop) | ||
"fail to be created with an Minute not between 0 and 59" in forAll(failedMinuteGen) { failedMinute: Option[Minute] => | ||
failedMinute ===(None) | ||
} | ||
|
||
"creates a minute from a numeric minute" in { | ||
val numericMinute = Gen.choose(0, 59) | ||
"creates a minute from a numeric minute" in forAll(minuteAsIntGen) { minuteAsInt: Int => | ||
|
||
val prop = forAll[Int, Boolean](numericMinute) { m: Int => | ||
refineV[Interval.Closed[W.`0`.T, W.`59`.T]](m) | ||
.fold(_ => false, { x => | ||
val numericMinute = Minute(x) | ||
val optionMinute = Minute(m).get | ||
numericMinute ===(optionMinute)}) | ||
refineMinute(minuteAsInt) match { | ||
case Right(m: NumericMinute) => | ||
Minute(m) shouldBe a[Minute] | ||
Minute(m) should ===(Minute(minuteAsInt).get) | ||
case _ => fail | ||
} | ||
|
||
check(prop) | ||
} | ||
} | ||
} |