assert(condition: bool, message: string = "assertion failed") - > ()- Модуль
- std.
test → - Получатель
- Неприменимо
- Минимальное число аргументов
- 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 }
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения resolve. Ненулевой код завершения.
selected-name-not-exported at
main.tpz:1:19
Reject the removed forAllBool helper
Ссылкаimport std.test { forAllBool }
Нет стандартного вывода.Ожидаемый результат
Ожидаемый результат
Этап отклонения resolve. Ненулевой код завершения.
selected-name-not-exported at
main.tpz:1:19