– Placing everything together and adding a bit to it.
**NOTE:**Also refer to gultus and balajiganapath answers
DataTypes & Overfloaw
Make a note of the constrains and get the maximum possible value that will be generated at any instance. And make sure your datatype will hold that value.
(Approx) 32Bit integer can hold upto 9digit values while 64Bit can hold upto 19Digits
Very Large Sets
In some cases we cannot test individual values, like for example if you are using Prime Sieve and you want to test its correctness. Put a counter and check how many primes are generated. Now compare these with values on Web. Then randomly check few values and that will do the work.
There are many online calculators which even expresses very hard mathematical answers.
Refer - WRA
This website answers questions like “primes <= (10^9)”. It is very useful for testing.
Floating Point Precision
In many problems we are asked to print only 2(or some x) digits after the decimal point.In this type of problems be very careful with what is actually asked. In few questions they ask to print only 2 digits after decimal point by rounding off and in other they ask you not to roundoff
Ex: value is 3.1476…
2 Decimals Rounded is 3.15
2 Decimals Without Rounding is 3.14
One more common error is Re-Initializing few values at the start of every test case. Ex:Counters;
Check for working of the program at extreme values. Not just the answer but try and print every value that is calculated during the process and check for correctness of all the values. This will make sure the METHOD being used is correct.
Brute Force Testing
For testing you can always use another program which does the same work but with low efficiency and high perfection.
When the constrains are small print all the values and check randomly. Even for larger values print values at every interval of 50 or 100 and check those. Mainly notice that none of then are 0. Because 0 occurs due to Datatype Overflow error.
This topic is limitless. To mention a few make sure your code is first following correct execution order. Insert print statements before,inside and after ever loop/conditionals to check how it is working.
Segmentation Fault - Use a similar method and find where exactly the program is breaking.
Then Check for following exceptions - Array Out Of Bound and Null Pointer Access Violation.