Testing the Strategy
To test the strategy example classes we can use a console application containing all of the above code. Add the code shown below to the Main method and then execute the program. The test code creates a new scoreboard and displays three scores. Each score using a different scoring algorithm.
Scoreboard board = new Scoreboard();
Console.Write("Man ");
board.Scoring = new MensScoringAlgorithm();
board.ShowScore(8, new TimeSpan(0, 1, 31));
Console.Write("Woman ");
board.Scoring = new WomensScoringAlgorithm();
board.ShowScore(9, new TimeSpan(0, 1, 49));
Console.Write("Child ");
board.Scoring = new ChildrensScoringAlgorithm();
board.ShowScore(5, new TimeSpan(0, 3, 2));
/* OUTPUT
Man 782
Woman 873
Child 909
*/
4 May 2009