Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ◇C++, ◇Clojure, ◇Scala


[ edit | logout ]
[ sandbox | passwd ]

assert vs check

assert

It raises AssertionDefect on failure and the program terminates.

To ignore assert statements, compile with the --assertions:off flag or the -d:danger definition.

assert 1 + 1 == 3

Output:

.../assert.nim(5) assert
.../lib/std/assertions.nim(45) failedAssertImpl
.../lib/std/assertions.nim(40) raiseAssert
.../lib/system/fatal.nim(62) sysFatal
Error: unhandled exception: .../assert.nim(5, 1) `1 + 1 == 3`  [AssertionDefect]

assert is suitable for development-time checks that can be safely omitted in production.

check

It's from std/unittest . It's designed for tests, gives nicer output showing exactly what values were compared.

Use check inside test blocks for unit tests.

import std/unittest


func twice(n: int): int =
  2 * n

test "twice":
  check twice(5) == 10

echo "The double of 3 is ", twice(3)

Output:

[OK] twice
The double of 3 is 6

𝥶Notice that unit tests can be mixed with normal code.

When a check fails, it prints something like this:

.../check.nim(11, 17): Check failed: twice(5) == 12
twice(5) was 10
[FAILED] twice
The double of 3 is 6

If a unit test fails, the program continues to run.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 May 01, 08:10