#include <assert.h>
int i, a[10];
for (i = 0; i < 10; ++i)
{
assert(0 <= i && i < 10);
a[i] = 10-i;
}
for (i = 0; i < 10; ++i)
{
assert(0 <= i && i < 10);
assert(0 <= a[i] && a[i] < 10);
a[a[i]] = a[i];
}
// By default, assertions are disabled
// java –enableassertions Test
int score = 10;
assert score >= 10 : " Below";
System.out.println("score is "+score);
assert(a > 0, "Expected a positive number");
$assert(Foo.sizeof == 8, "Foo sizecheck at compile time failed");
use std::debug
use std::debug::assert::{assert}
fn main() {
std::debug::ENABLE = true
let x = 200
assert(x < 200)
}
class Person
|int| age
setter age
// "expect" will actually add an Error to a list of errors
expect (value >= 0) ("bad age $value set!")
.age = value
main
|| p = person()
p.age = -10
if !stderr.ok
"Oof we got some errors"
Languages with Assert Statements include C, Java, C3, Jule, Speedie
Languages without Assert Statements include progsbase
View all concepts with or missing a hasAssertStatements measurement
Read more about Assert Statements on the web: 1.