Skip to content
CShift0.45

Assert

Checks for tests (test "name" { ... }, run by cshiftc test, see docs/language/testing.md): a check that fails panics, which ends the test as failed and shows the reason and the line of the test that made the check.

test "MinMax finds both ends"
{
var (lo, hi) = MinMax([3, 1, 7]);
Assert.Equal(1, lo);
Assert.Equal(7, hi);
Assert.True(lo < hi);
}

The checks work outside of tests as well: in a program, a failed check is a panic like any other.

Name Description
True Checks that condition is true.
False Checks that condition is false.
Equal Checks that actual equals expected (with ==: numbers, strings, enums, tuples, …).
NotEqual Checks that actual differs from notExpected (with !=).
Near Checks that the floating-point numbers differ by at most tolerance.
Fail Fails the test: for a branch that must not be reached.
void True(bool condition)

Checks that condition is true.

Since 0.42

void True(bool condition, string message)

Checks that condition is true; message says what was expected.

Since 0.42

void False(bool condition)

Checks that condition is false.

Since 0.42

void False(bool condition, string message)

Checks that condition is false; message says what was expected.

Since 0.42

void Equal<T>(T expected, T actual)

Checks that actual equals expected (with ==: numbers, strings, enums, tuples, …). The message shows both values (as $"{value}" writes them).

Since 0.42

void NotEqual<T>(T notExpected, T actual)

Checks that actual differs from notExpected (with !=).

Since 0.42

void Near(double expected, double actual, double tolerance)

Checks that the floating-point numbers differ by at most tolerance.

Since 0.42

void Fail(string message)

Fails the test: for a branch that must not be reached.

Since 0.42