我正在编写一个scala测试用例,并使用printwriter填充一些数据。这没有任何意义,所以我-它看起来像附加器只是停止了四分之三的方式。
您不需要用于字数统计的代码,因为您可以看到文件中的最后一行是不完整的:
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)
}
}发布于 2013-02-11 08:34:02
看起来缓冲区没有刷新--我遗漏了file.close(),在添加它之后,它就可以工作了!很抱歉浪费你的时间。
谢谢,
https://stackoverflow.com/questions/14804295
复制相似问题