Making sense of the madness

Now that we have the gold standard test written, we can begin to safely refactor the code. Any changes that we try to make that break the gold standard test will have to be undone and a new approach will have to be taken.

Looking at the Mastermind class, all those variables at the top of the Play method can be moved out to be class level fields. This will make them available to all the code within the class and help to both figure out what they are for and how often they are used in the app:

private char[] g;private char[] p = new[] { 'A', 'A', 'A', 'A' };private int i = 0;private int j = 0;private int x = 0;private int c = 0;

Next, we will just work our way down the Play method, extracting all that we can into ...

Get Practical Test-Driven Development using C# 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.