assert(condition: bool, message: string = "assertion failed") - > ()- 수신자
- 해당 없음
- 최소 인자 수
- 1
- 최대 인자 수
- 2
Declaration and parameters
링크사용 조건
기본 포함 · 미정
Import std.test in language mode 5.21.
The current compiler selects std/test.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
수신자
매개변수 제약
Test programs iterate supplied values with the ordinary for statement. The same statement applies to integers, booleans, strings, and other iterable element types.
std.test does not export forAllInt or forAllBool. Assertions inside a for body retain the same assertion behavior as a direct call.
관련 규칙 · Repeat assertions with for →결과
The declared result type is ().
효과
실패
Result and effects
링크Checks a boolean condition with a failure message.
Related entries
링크Repeat assertions with for
링크Repeat assertions with for
Test programs iterate supplied values with the ordinary for statement. The same statement applies to integers, booleans, strings, and other iterable element types.
std.test does not export forAllInt or forAllBool. Assertions inside a for body retain the same assertion behavior as a direct call.
이유
The removed helpers repeated an existing loop and added no test meaning. Ordinary iteration works for every element type and keeps loop control and assertion order visible.
Use one loop for every element type
링크import std.testimport std.iolet mut sum = 0for value in ([2, 3, 5]) {sum += value}let mut trueCount = 0for value in ([true, false, true]) {if (value) { trueCount += 1 }}let mut labels = ""for value in (["A", "B", "C"]) {labels = labels + value}test.assertEq(sum, 10)test.assertEq(trueCount, 2)test.assertEq(labels, "ABC")io.writeLine("all values checked")
all values checked
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
all values checked
Reject the removed forAllInt helper
링크import std.test { forAllInt }
표준 출력 없음.기대 결과
Reject the removed forAllBool helper
링크import std.test { forAllBool }
표준 출력 없음.