Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit-testing a complex algorithm

Tags:

People also ask

How complex should unit tests be?

The general rule for unit tests is to test the smallest possible piece that you can test. A good rule is that each test should exercise exactly a single method from a public API. That means it should only execute this method and no other, not even transiently.

What is the purpose of unit testing?

The main objective of unit testing is to isolate written code to test and determine if it works as intended. Unit testing is an important step in the development process, because if done correctly, it can help detect early flaws in code which may be more difficult to find in later testing stages.


How would you write tests for testing a solution to some rather complex algorithm like the N Queens problem? What I mean is what should be the right approach for testing an algorithm that

  1. has many solutions (you don't know / don't care how many of them exist),

  2. you can only have a small subset of all the possible solutions, and

  3. verifying that a solution is correct can be a little bit tricky (maybe comparable in complexity with the algorithm itself).

I know that these conditions are not present in the N-Queens problem itself, but I mentioned it to provide sort of an example.