我正在研究一个 scala 测试用例并使用 printwriter 填充一些数据。这对我来说没有任何意义 - 看起来 appender 只是在 3/4 处停止。
您不需要用于字数统计的代码,因为您可以看到文件中的最后一行不完整:
hello world duck duck sauce sauce mazing ninjakeyboard skills ninja
hello world duck duck sauce
日志:
[info] Give a file with 10 words repeated on 1000 lines and file handler
[info] - should give us an array of 10000 words *** FAILED ***
[info] 8434 did not equal 10000 (WordCountFileHandler.scala:20)
代码:
import java.io.PrintWriter
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import WordCountFileHandler.WordCountFileHandler
class WordCountFileHandler extends FlatSpec with ShouldMatchers {
"Give a file with 10 words repeated on 1000 lines and file handler" should "give us an array of 10000 words" in {
val filename = java.util.UUID.randomUUID().toString
val testFile = new PrintWriter( filename , "UTF-8")
for (x <- 1 to 1000) yield {testFile.println("hello world duck duck sauce sauce mazing ninjakeyboard skills ninja")}
testFile.close()
val testOutput = WordCountFileHandler (filename)
testOutput.size should equal(1)
//testOutput.head.foreach(println(_))
testOutput.head.size should equal (10000)
}
}