I'm trying to unit test a small program I wrote.
My problem is that I can't see an easy way to unit test my top level class (Matcher) that exposes a single public method (MatchAll).
I do have tests for my inner classes, but they are largely trivial.
Let me present a problem and a sketch of my solution:
Problem: Given list of people, list of their preferred teams and rankings for each team, find a match that both maximizes team rank and takes candidate preferences into consideration.
- Candidate - Holds a list of preferred teams and a rank score for each respective team
- Team - Holds list of accepted candidates. As long as the team has room, it accepts any candidate. Once it fills up, it only accepts candidates that improve its score. It also purges the candidate with lowest score.
Team exposes the following methods:
Matcher - Contains the list of candidates and list of teams and implements the core logic of assigning candidates to a team.
My matching logic is as follows (Pseudocode):
function Matchall() while candidates != empty c <- candidates.getFirst() for each t in c.teams betterMatch = t.IsBetterMatch(c) if betterMatch weakest = t.purgeWeakest() t.Add(c) candidates.add(weakest)
Assuming team methods are thoroughly tested, how would you suggest to test this function?
The tests that I can think of for this function are very complex both to formulate and to setup.
When two candidates have same rank and want the same team and the team has room for only one, the first one should be assigned to the team. Second one should be assigned to another team down his preference list.
It seems to me that they fall more under the integration tests category, which is why I'm confused. It's my understanding that the unit tests should be short and simple to write