Skip to content

Instantly share code, notes, and snippets.

@yoshihiro503
Created July 3, 2012 09:54
Show Gist options
  • Save yoshihiro503/3038807 to your computer and use it in GitHub Desktop.
Save yoshihiro503/3038807 to your computer and use it in GitHub Desktop.
コップ本の3.6節の例題の別解を自動テストしてみた
import org.scalacheck.Properties
import org.scalacheck.Prop._
import Cop3_6._
/**
* ScalaCheck を使った自動テスト
*/
object Check extends Properties("コップ本3.6") {
//リストの要素がすべて同じかどうか判定する便利関数
def allSame[A](xs : List[A]) : Boolean =
if (xs.isEmpty) true else xs.forall(_ == xs(0))
//========= ここからテスト ===========
property("バー('|')の位置が揃っているか") = forAll {
(lines : List[String]) => {
val barPositions = formatLines(lines).map(_.indexOf('|'))
allSame(barPositions)
}
}
}
@yoshihiro503
Copy link
Author

テスト対象のコードはこちら
https://gist.github.com/3032192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment