i want to know that some programmer use assert in their program , is there any advantage of using assert while running the program on judge where all the constraints are defined and are guaranteed that variables follow these constrains ??
like this program PRETNUM tester1 solution.in this solution tester uses assert for all the constraints.
@ajay154Assert statement can be used to debug your program running on online judge. Whenever assert statement returns false, online judge throws a Run Time Error.
Example : Assume that you are getting WA due to some variable say X is exceeding some limit say Y. Now if you put a assert statement such as assert(X <= Y); , you will receive a RTE instead of WA and you will know that variable X is exceeding limit Y.
I don’t really believe there’s any real “advantage” in using asserts during a contest, at least, using asserts will not make your solutions better from the algorithmic point of view…
Usually, testers always use asserts when writing their solutions (which are written during the testing phase of the contest, done on the “backstage”, if you want to put it that way) because they need to make sure that the input files are well formatted and respect the given constrains. This is done mostly for two reasons:
It ensures that the test data is formatted and consistent with the constrains given on the problem statement;
It gives the problem setter’s the possibility of fixing any mistakes, if there are any;
This way, it is 100% checked that the problem is well-written and that the test data is well formatted.
As this is done during the testing phase, competitors usually don’t need to use asserts when writing code
@betlista you can throw a runtime error whenever the constraint is broken. Pretty much the same in java. Just some extra characters to code the assert function.