[英]How do I write a Scala unit test to verify that a function is called with some particular function as a parameter?
[英]How write a property test for particular list content
我有以下功能,想通過ScalaCheck進行測試:
object Windows {
val Directory = "^[a-zA-Z]:\\\\(((?![<>:\"/\\\\|?*]).)+((?<![ .])\\\\)?)*$".r
def arePathsValid(paths: List[String]): Eval[List[String]] = {
Foldable[List]
.foldRight(paths, Eval.later(List.empty[String]))((a: String, b: Eval[List[String]]) => {
Directory.findFirstIn(a) match {
case Some(a) => b.map(a :: _)
case None => b
}
})
}
}
我嘗試從開始:
val propPaths = forAll { l: List[String] => ??? }
但是無法為該屬性編寫實現。
應該在List
隨機生成的String
,應具有Windows模式路徑,例如:
C:\temp\foo
財產如何實施?
您可以像這樣添加Windows路徑前綴:
val strGen = Gen.alphaStr // Or any other String generator
val windowsPathGen = strGen.map("C:\temp\foo" + _)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.