Scala编程思想测试类AtomicTest.scala
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Scala编程思想测试类AtomicTest.scala相关的知识,希望对你有一定的参考价值。
Scala编程思想附录1的测试类。
package com.atomicscala
import language.implicitConversions
import java.io.FileWriter
class AtomicTest[T](val target:T) {
val errorLog = "_AtomicTestErrors.txt"
def tst[E](expected:E)(test: => Boolean){
println(target)
if(test == false) {
val msg = "[Error] expected:\n" +
expected
println(msg)
val el = new FileWriter(errorLog,true)
el.write(target + msg + "\n")
el.close()
}
}
def str = // Safely convert to a string
Option(target).getOrElse("").toString
def is(expected:String) = tst(expected) {
expected.replaceAll("\r\n","\n") == str
}
def is[E](expected:E) = tst(expected) {
expected == target
}
def beginsWith(exp:String) = tst(exp) {
str.startsWith(
exp.replaceAll("\r\n","\n"))
}
}
object AtomicTest {
implicit def any2Atomic[T](target:T) =
new AtomicTest(target)
}
以上是关于Scala编程思想测试类AtomicTest.scala的主要内容,如果未能解决你的问题,请参考以下文章