问题描述
我已经在 Scala 中编程了大约一个星期,但没有使用 sbt - 我下载了“用于 Windows 的 Scala 二进制文件”(使用 Windows 10)并且刚刚使用文本编辑器编写脚本,并通过编译和执行命令行,例如
/** Calculate factorial of n
* Pre: n >= 0
* Post: returns n! */
def fact(n: Int) : BigInt = {
require(n>=0)
if(n==0) 1 else fact(n-1)*n
}
// Main method
def main(args: Array[String]) : Unit = {
print("Please input a number: ")
val n = scala.io.StdIn.readInt()
if(n>=0){
val f = fact(n)
println("The factorial of "+n+" is "+f)
}
else println("Sorry,negative numbers aren't allowed")
}
}
然后:
到目前为止,一切都很好。输入:ScalaTest。
import org.scalatest.funsuite.AnyFunSuite
import Factorial.fact
class FactTest extends AnyFunSuite {
test("0! is 1"){ assert(fact(0) === 1) }
test("5! is 120") { assert(fact(5) === 120) }
test("3! is 5") {assert(fact(3) === 5) } //Want to see what happens when the test isn't passed
}
但这不会编译。
我正在运行 Scala 2.13.4,所以版本都匹配(我相信?)
我对正在发生的事情的最佳猜测是我不认为 scalac 实际上在查找/使用 ScalaTest 文件,但我不知道为什么。
有什么帮助吗?
编辑:添加了 funsuite Scalatest jar,但仍然无法正常工作...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)