zoukankan      html  css  js  c++  java
  • 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: " +
            expected
          println(msg)
          val el = new FileWriter(errorLog,true)
          el.write(target + msg + " ")
          el.close()
      }
    }
    def str = // Safely convert to a string
      Option(target).getOrElse("").toString
    def is(expected:String) = tst(expected) {
      expected.replaceAll(" "," ") == str
    }
    def is[E](expected:E) = tst(expected) {
      expected == target
    }
    def beginsWith(exp:String) = tst(exp) {
      str.startsWith(
        exp.replaceAll(" "," "))
      }
    }

    object AtomicTest {
      implicit def any2Atomic[T](target:T) =
        new AtomicTest(target)
    }

  • 相关阅读:
    敏捷开发第五天
    敏捷开发第四天
    系统用户分析模型
    第三天敏捷开发
    第二天敏捷开发
    敏捷开发第一天
    第三周学习总结
    [学习笔记]莫队算法
    【网络流】Modular Production Line
    [学习笔记]set的使用
  • 原文地址:https://www.cnblogs.com/flymercurial/p/7846689.html
Copyright © 2011-2022 走看看