What real life situations can assertions be used for? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

What real life situations can assertions be used for?

13th Sep 2016, 2:28 PM
4 ответов
+ 3
Simple testing and debugging of course! For example, you wrote a function that doubles a number, and you want to test it. You may want to write a file with some testcases like assert f(2) == 4 assert f(0) == 0 and run it every time you change your f() function to make sure that its behaviour hasn't changed.
13th Sep 2016, 10:20 PM
trueneu - avatar
+ 1
Assertion is used on unit testing of code block. It helps to validate the input and output of a function and raise appropriate exception for negative values.
17th Sep 2016, 4:20 AM
+ 1
Use it for input test. Also... the simplest way to check how it goes.
17th Sep 2016, 4:21 PM
Alex D
Alex D - avatar
+ 1
only used for debugging?
19th Dec 2016, 3:33 AM
Nahuel Retamoso
Nahuel Retamoso - avatar