Properties of assert

This lesson explains different properties associated with assert in detail.

Using assert checks #

Use assert checks even if absolutely true. A large set of program errors are caused by assumptions that are thought to be absolutely true.
For that reason, take advantage of assert checks even if they feel unnecessary. Let’s look at the following function that returns the days of months in a given year:

int[] monthDays(int year) { 
    int[] days = [
       31, februaryDays(year),
       31, 30, 31, 30, 31, 31, 30, 31, 30, 31 
    ];

    assert((sum(days) == 365) || 
          
...
Access this course and 1400+ top-rated courses and projects.