Scala: DateTime型のプロパティテスト
Specs2 + ScalaCheck の例。
依存ライブラリ
libraryDependencies ++ = Seq( "com.github.nscala-time" %% "nscala-time" % "1.8.0" , "org.specs2" %% "specs2-core" % "3.4" % "test" , "org.scalacheck" %% "scalacheck" % "1.12.2" % "test" ) |
実装例
Arbitrary ベース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import com.github.nscala _ time.time.Imports.DateTime import org.scalacheck.{Gen, Arbitrary} import org.specs 2 .ScalaCheck import org.specs 2 .mutable.Specification class DateTimeSpec extends Specification with ScalaCheck { implicit val arbDateTime : Arbitrary[DateTime] = Arbitrary(Gen.choose( 0 L, Long.MaxValue).map( new DateTime( _ ))) "DateTime" should { "do something" in prop { t : DateTime = > t must ??? // write tests here } } } |
Gen ベース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import com.github.nscala _ time.time.Imports.DateTime import org.scalacheck.{Gen, Prop} import org.specs 2 .ScalaCheck import org.specs 2 .mutable.Specification class DateTimeSpec extends Specification with ScalaCheck { private val genDateTime = Gen.choose( 0 L, Long.MaxValue).map( new DateTime( _ )) "DateTime" should { "do something" in Prop.forAll(genDateTime) { t : DateTime = > t must ??? // write tests here } } } |
0 件のコメント:
コメントを投稿