Can you have simple unit tests for complicated function? For example: Turing test for AI.
Do you always can find simple unit tests for any complicated enough function / algorithm?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.Sign up to join this community
The Turing test would make a very poor unit test because (a) it is difficult (impossible ?) to automate and (b) the evaluation of the test output to produce a pass or fail result is subjective. In fact, it might not even be possible to devise useful unit tests (in the usual sense) for strong AI - how would unit tests distinguish between true AI and a program that simply responded by rote ?
But simple unit tests for other complicated functions are certainly possible. As long as the function produces output that can be objectively evaluated then you can write unit test cases for it. For example, a Travelling Salesman Problem solver could be a very complicated program, but a unit test plan is very simple:
(a) test edge cases - 0 cities, 1 city, 2 cities
(b) test some simple cases with known solutions e.g. 3 cities in scalene triangle, 4 cities at corners of a rectangle, solved examples from TSPLIB
In the case of the travelling salesman problem, you can easily write unit test that find _ some_ bugs but not all: construct an instance and find a solution. Then increase some distance between cities that are part of the optimal solution and solve again. The shortest distance should not become less. And then you repeat.
An algorithm that doesn’t find an optimal solution ( when it is supposed to) would likely find solutions that are sometimes less and sometimes more close to optimal. So if you give it instances where the optimal value should have non- decreasing values a non- optimal solution might produce decreasing values sometimes.