scala import zio.test.Assertion._ import zio.test._ object MathSpec extends DefaultRunnableSpec { def spec: ZSpec[Environment, Failure] = suite("MathSpec")( test("addition") { val result = math.add(2, 3) assert(result)(equalTo(5)) }, testM("division") { for { result <- math.divide(10, 2) } yield assert(result)(equalTo(5)) } ) } object math { def add(a: Int, b: Int): Int = a + b def divide(a: Int, b: Int): IO[ArithmeticException, Int] = if (b != 0) UIO(a / b) else IO.fail(new ArithmeticException("Division by zero")) } object Main extends App { TestRunner.run(MathSpec) }


上一篇:
下一篇:
切换中文