1
장난감의 예입니다 : 내가 반환하는 방법 last[T](ts: Seq[T]): Try[T]
이시험 유형) 여기 scalatest와
중 하나
- 에 싸여 비어 있지 않은리스트의 마지막 요소
Success
또는 NoSuchElementException
이Failure
으로 싸여 있습니다.
나는 scalatest doc pertaining to TryValues을 읽고 다음 scalatest 함께했다되었습니다
"The solution" should "Find the last element of a non-empty list" in {
last(Seq(1, 1, 2, 3, 5, 8)).success.value should equal (8)
// ...
}
it should "Fail with NoSuchElementException on an empty list" in {
// Option 1: what I would like to do but is not working
last(Nil).failure.exception should be a[NoSuchElementException]
// Option 2: is working but actually throws the Exception, and does not test explicitly test if was in a Failure
a [NoSuchElementException] should be thrownBy {last(Nil).get}
}
내 옵션 1 일을 만들 수있는 방법이 있나요?
정말 일치 구문을 ... 감사! –