Created
July 3, 2012 09:54
-
-
Save yoshihiro503/3038807 to your computer and use it in GitHub Desktop.
コップ本の3.6節の例題の別解を自動テストしてみた
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
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
テスト対象のコードはこちら
https://gist.github.com/3032192