{"id":28802,"date":"2020-04-29T00:00:00","date_gmt":"2020-04-28T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/golden-master-pattern-codice-legacy-non-ti-temo\/"},"modified":"2021-05-21T20:20:37","modified_gmt":"2021-05-21T18:20:37","slug":"golden-master-pattern-dont-fear-the-legacy-code","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/","title":{"rendered":"Golden Master Pattern: don&#8217;t fear the legacy code!"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"26724\" data-permalink=\"https:\/\/blexin.com\/en\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"fe85ca6d-91d7-4ead-9d01-d4adddef4e5e\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-26724\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Anyone who works in the software development world will have had the need to add features on the legacy code, perhaps inherited from the previous team, and on which you need to make an urgent fix.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many definitions of legacy code can be found in literature, the one that I prefer is: \u201cBy&nbsp;<strong>Legacy code<\/strong>, we mean the&nbsp;<strong>profitable code&nbsp;<\/strong>that we&nbsp;<strong>feel afraid to change\u201d<\/strong>. This definition contains two fundamental concepts:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>The code has to be profitable. If it doesn\u2019t, we have no interest in changing it.&nbsp;<\/li><li>It must breed fear of modifying it because we can introduce new bug o break thing with shadow dependencies.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The ease of making mistakes increases when:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The code is not covered by tests.&nbsp;<\/li><li>The code is not clean; the single-responsibility principle is not respected.&nbsp;<\/li><li>The code is badly designed, or becomes ill-structured over time: making a change to a piece of code can have some side effects.&nbsp;<\/li><li>You haven\u2019t the time to get thorough knowledge of what you are modifying.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A powerful weapon that we have available as developers is the tests. The tests give us security on the result and are a way to detect errors quickly. But how can we test code which we don\u2019t know? Building a Unit Test suite would provide us an in-depth knowledge of the project, but it would keep long time with high cost. If we cannot test details, we can use&nbsp;<strong>Characterization Test<\/strong>, which is tests that describe the behavior of a piece of software.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A pattern that plays an important role in this situation is&nbsp;<strong>Golden Master Pattern<\/strong>. The basic idea is straightforward: if we can\u2019t go deep in detail, we need some indicators of the entire execution. We catch the output (stdout, images, log files, etc.) of a correct execution, and this is our Golden Master, that we can use for expected output. If the output of current execution matches, we can be confident that our change hasn\u2019t introduced new errors.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To show the use of the Golden Master Pattern, let\u2019s start with an example (the complete code can be found&nbsp;<a href=\"https:\/\/github.com\/ntonjeta\/GoldenMasterExample\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>). Our company develops games for command line, including the Tic Tac Toe Game (the implementation is taken from&nbsp;<a href=\"https:\/\/www.c-sharpcorner.com\/UploadFile\/75a48f\/tic-tac-toe-game-in-C-Sharp\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>), our boss asks us to change the game to give the ability of resize game board. Let&#8217;s take a look at the code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nnamespace Tris\n{\n\u00a0\u00a0\u00a0\u00a0public class Game\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/making array and\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/by default I am providing 0-9 where no use of zero\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static char&#x5B;] arr = { &#039;0&#039;, &#039;1&#039;, &#039;2&#039;, &#039;3&#039;, &#039;4&#039;, &#039;5&#039;, &#039;6&#039;, &#039;7&#039;, &#039;8&#039;, &#039;9&#039; };\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static int player = 1; \/\/By default player 1 is set\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static int choice; \/\/This holds the choice at which position user want to mark\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ The flag variable checks who has won if its value is 1 then someone has won the match if -1 then Match has Draw if 0 then match is still running\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0static int flag = 0;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0public static void run()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0do\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.Clear();\/\/ whenever loop will be again start then screen will be clear\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Player1:X and Player2:O&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\\n&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (player % 2 == 0)\/\/checking the chance of the player\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Player 2 Chance&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Player 1 Chance&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\\n&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Board();\/\/ calling the board Function\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0choice = int.Parse(Console.ReadLine());\/\/Taking users choice\u00a0\u00a0 \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ checking that position where user want to run is marked (with X or O) or not\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (arr&#x5B;choice] != &#039;X&#039; &amp;&amp; arr&#x5B;choice] != &#039;O&#039;)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (player % 2 == 0) \/\/if chance is of player 2 then mark O else mark X\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0arr&#x5B;choice] = &#039;O&#039;;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0player++;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0arr&#x5B;choice] = &#039;X&#039;;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0player++;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else \/\/If there is any position where user wants to run and that is already marked then show message and load board again\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Sorry the row {0} is already marked with {1}&quot;, choice, arr&#x5B;choice]);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\\n&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Please wait 2 second board is loading again.....&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Thread.Sleep(2000);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0flag = CheckWin();\/\/ calling of check win\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} while (flag != 1 &amp;&amp; flag != -1);\/\/ This loof will be run until all cell of the grid is not marked with X and O or some player is not winner \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.Clear();\/\/ clearing the console\u00a0 \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Board();\/\/ getting filled board again\u00a0 \n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (flag == 1)\/\/ if flag value is 1 then someone has win or means who played marked last time which has win\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Player {0} has won&quot;, (player % 2) + 1);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else\/\/ if flag value is -1 the match will be drawn and no one is the winner\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Draw&quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.ReadLine();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ Board method which creats board\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private static void Board()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0 &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0 {0}\u00a0 |\u00a0 {1}\u00a0 |\u00a0 {2}&quot;, arr&#x5B;1], arr&#x5B;2], arr&#x5B;3]);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;_____|_____|_____ &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0 &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0 {0}\u00a0 |\u00a0 {1}\u00a0 |\u00a0 {2}&quot;, arr&#x5B;4], arr&#x5B;5], arr&#x5B;6]);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;_____|_____|_____ &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0 &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0 {0}\u00a0 |\u00a0 {1}\u00a0 |\u00a0 {2}&quot;, arr&#x5B;7], arr&#x5B;8], arr&#x5B;9]);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0 |\u00a0\u00a0\u00a0\u00a0\u00a0 &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private static int CheckWin()\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#region Horzontal Winning Condtion\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Winning Condition For First Row\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (arr&#x5B;1] == arr&#x5B;2] &amp;&amp; arr&#x5B;2] == arr&#x5B;3])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Winning Condition For Second Row\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;4] == arr&#x5B;5] &amp;&amp; arr&#x5B;5] == arr&#x5B;6])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Winning Condition For Third Row\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;6] == arr&#x5B;7] &amp;&amp; arr&#x5B;7] == arr&#x5B;8])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#endregion\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#region vertical Winning Condtion\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Winning Condition For First Column\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;1] == arr&#x5B;4] &amp;&amp; arr&#x5B;4] == arr&#x5B;7])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Winning Condition For Second Column\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;2] == arr&#x5B;5] &amp;&amp; arr&#x5B;5] == arr&#x5B;8])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/Winning Condition For Third Column\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;3] == arr&#x5B;6] &amp;&amp; arr&#x5B;6] == arr&#x5B;9])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#endregion\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#region Diagonal Winning Condition\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;1] == arr&#x5B;5] &amp;&amp; arr&#x5B;5] == arr&#x5B;9])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;3] == arr&#x5B;5] &amp;&amp; arr&#x5B;5] == arr&#x5B;7])\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#endregion\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#region Checking For Draw\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ If all the cells or values filled with X or O then any player has won the match\u00a0 \n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else if (arr&#x5B;1] != &#039;1&#039; &amp;&amp; arr&#x5B;2] != &#039;2&#039; &amp;&amp; arr&#x5B;3] != &#039;3&#039; &amp;&amp; arr&#x5B;4] != &#039;4&#039; &amp;&amp; arr&#x5B;5] != &#039;5&#039; &amp;&amp; arr&#x5B;6] != &#039;6&#039; &amp;&amp; arr&#x5B;7] != &#039;7&#039; &amp;&amp; arr&#x5B;8] != &#039;8&#039; &amp;&amp; arr&#x5B;9] != &#039;9&#039;)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return -1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0#endregion\n\u00a0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 0;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">At a quick reading, the code appears confused, the responsibility is not correctly separated, and the variable names are not meaningful. After an accurate reading, we are able to found the game board, which was stored in \u2018static char[] arr\u2019. Adding new elements to the array has no effects because the array accesses directly in PrintBoard and CheckWin functions. Now we know that to resize a game board, a large part of the code must be changed.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new project and run game:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass Program\n{\n\u00a0\u00a0\u00a0\u00a0static void Main(string&#x5B;] args)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Game.run();\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">As soon as we printed the board, the game asks for user input. We can automate by reading the input from file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass Program\n{\n\u00a0\u00a0\u00a0\u00a0private const string InputPath = &quot;input.txt&quot;;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0public static void Main(string&#x5B;] args)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var input = new StreamReader(new FileStream(InputPath, FileMode.Open));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.SetIn(input);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Game.run();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0input.Close();\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The set of all input is too large to use brute-force testing. What we can do is&nbsp;<strong>sampling<\/strong>&nbsp;the input. To do that, we consider the possible final scores of a tic tac toe game:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Player 1 Wins<\/li><li>Player 2 Wins<\/li><li>Draw<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Select the minimum set of test that cover the three cases, writing the paths in text files and collect results in the golendenMaster folder:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nclass Program\n{\n\u00a0\u00a0\u00a0\u00a0private const string InputFolderPath = &quot;input\/&quot;;\n\u00a0\u00a0\u00a0\u00a0private const string OutputFolderPath = &quot;goldenMaster\/&quot;;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0public static void Main(string&#x5B;] args)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0int i = 1;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0foreach (var filePath in Directory.GetFiles(InputFolderPath)) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var input = new StreamReader(new FileStream(filePath, FileMode.Open));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var output = new StreamWriter(new FileStream(OutputFolderPath + &quot;output&quot; + i.ToString() + &quot;.txt&quot; , FileMode.CreateNew));\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.SetIn(input);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.SetOut(output);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Game.run();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0input.Close();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0output.Close();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0i++;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The three results files represent our Golden Master, basing on which we can build some Characterization Tests:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n&#x5B;Test]\npublic void WinPlayerOne()\n{\n\u00a0\u00a0\u00a0\u00a0inputPath = InputFolderPath + &quot;input1.txt&quot;;\n\u00a0\u00a0\u00a0\u00a0outputPath = OutputFolderPath + &quot;output.txt&quot;;\n\u00a0\u00a0\u00a0\u00a0var goldenMasterOutput = GoldenMasterOutput + &quot;output1.txt&quot;;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0var input = new StreamReader(new FileStream(inputPath, FileMode.Open));\n\u00a0\u00a0\u00a0\u00a0var output = new StreamWriter(new FileStream(outputPath, FileMode.CreateNew));\n\u00a0\u00a0\u00a0\u00a0Console.SetIn(input);\n\u00a0\u00a0\u00a0\u00a0Console.SetOut(output);\n\u00a0\n\u00a0\u00a0\u00a0\u00a0Game.run();\n\u00a0\n\u00a0\u00a0\u00a0\u00a0input.Close();\n\u00a0\u00a0\u00a0\u00a0output.Close();\n\u00a0\n\u00a0\u00a0\u00a0\u00a0Assert.True(AreFileEquals(goldenMasterOutput, outputPath));\n}\n\u00a0\nprivate bool AreFileEquals(string expectedPath, string actualPath)\n{\n\u00a0\u00a0\u00a0\u00a0byte&#x5B;] bytes1 = Encoding.Convert(Encoding.ASCII, Encoding.ASCII, Encoding.ASCII.GetBytes(File.ReadAllText(expectedPath)));\n\u00a0\u00a0\u00a0\u00a0byte&#x5B;] bytes2 = Encoding.Convert(Encoding.ASCII, Encoding.ASCII, Encoding.ASCII.GetBytes(File.ReadAllText(actualPath)));\n\u00a0\n\u00a0\u00a0\u00a0\u00a0return bytes1.SequenceEqual(bytes2);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">As long as the tests are green, we can refactor without fear of breaking something. One possible result could be the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic static void run()\n{\n\u00a0\u00a0\u00a0\u00a0char&#x5B;] board = { &#039;0&#039;, &#039;1&#039;, &#039;2&#039;, &#039;3&#039;, &#039;4&#039;, &#039;5&#039;, &#039;6&#039;, &#039;7&#039;, &#039;8&#039;, &#039;9&#039; };\n\u00a0\u00a0\u00a0\u00a0int actualPlayer = 1;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0while (CheckWin(board) == 0)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PrintPlayerChoise(actualPlayer);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PrintBoard(board);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var choice = ReadPlayerChoise();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (isBoardCellAlreadyTaken(board&#x5B;choice]))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PrintCellIsAlreadyMarketMessage(board&#x5B;choice], choice);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0continue;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0board&#x5B;choice] = GetPlayerMarker(actualPlayer);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0actualPlayer = UpdatePlayer(actualPlayer);\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0PrintResult(board, actualPlayer);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">From this block of code come to light the concept of Board and his responsibility. Let\u2019s try to extract behavior in the new&nbsp;<strong>Board&nbsp;<\/strong>class. The new Board should be able to:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Print board<\/li><li>Mark the player choice&nbsp;<\/li><li>Check if there is a winner<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Using TDD (for more details, read the<a href=\"https:\/\/www.blexin.com\/en-US\/Article\/Blog\/TDD-the-whole-code-is-guilty-until-proven-innocent-38\" target=\"_blank\" rel=\"noreferrer noopener\">&nbsp;article by Adolfo<\/a>) to develop a resizable Board ( find the complete code of test&nbsp;<a href=\"https:\/\/github.com\/ntonjeta\/GoldenMasterExample\/blob\/master\/test\/GoldenMasterExampleTest\/BoardShould.cs\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>&nbsp;and the one of class&nbsp;<a href=\"https:\/\/github.com\/ntonjeta\/GoldenMasterExample\/blob\/master\/lib\/Game\/Board.cs\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>). Now try to insert them in the game, and check if the Golden Master remains green:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nprivate const int Boardsize = 3;\n\u00a0\npublic static void run()\n{\n\u00a0\u00a0\u00a0\u00a0Board board = new Board(Boardsize);\n\u00a0\u00a0\u00a0\u00a0int actualPlayer = 1;\n\u00a0\n\u00a0\u00a0\u00a0\u00a0while (board.CheckWin() == -1)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PrintPlayerChoise(actualPlayer);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(board.Print());\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var choice = ReadPlayerChoise();\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (!board.UpdateBoard(actualPlayer, choice))\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0PrintCellIsAlreadyMarketMessage(board.GetCellValue(choice), choice);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0continue;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0actualPlayer = UpdatePlayer(actualPlayer);\n\u00a0\u00a0\u00a0\u00a0}\n\u00a0\n\u00a0\u00a0\u00a0\u00a0PrintResult(board, actualPlayer);\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">At this point we can restore the stdin\/stdout and read the dimensions of board from user:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Program\n{\n\u00a0\u00a0\u00a0\u00a0public static void Main(string&#x5B;] args)\n\u00a0\u00a0\u00a0\u00a0{\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Console.WriteLine(&quot;Insert Diagonal dimension of Board: &quot;);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var boardSize = int.Parse(Console.ReadLine());\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Game.run(boardSize);\n\u00a0\u00a0\u00a0\u00a0}\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">As you have seen, thanks to Golden Master Pattern, we are able to dominate legacy code and refactor without fear. But all that glitters is not gold: using the Golden Master can be hard in case of \u201cnoise output\u201d, which is the output useless for execution, but that changes over time (es. timestamp, thread name, etc. ). In this case, we can filter output and consider only the significant part.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope it will be useful for you the next time you inherit a legacy project: after all, we fear what we cannot control only!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See you at the next article<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s see together how to modify legacy code ensuring it works thanks to the Golden Master Pattern<\/p>\n","protected":false},"author":196716249,"featured_media":26724,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_crdt_document":"","inline_featured_image":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false},"categories":[688637524],"tags":[688637542,688637384],"class_list":["post-28802","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-dotnetcore-en","tag-c-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Golden Master Pattern: don&#039;t fear the legacy code! - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Golden Master Pattern: don&#039;t fear the legacy code! - Blexin\" \/>\n<meta property=\"og:description\" content=\"Let\u2019s see together how to modify legacy code ensuring it works thanks to the Golden Master Pattern\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-28T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-21T18:20:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Antonio Tammaro\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Antonio Tammaro\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/\"},\"author\":{\"name\":\"Antonio Tammaro\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/6e574a2e13d47c9167c5cfb475d9bfc5\"},\"headline\":\"Golden Master Pattern: don&#8217;t fear the legacy code!\",\"datePublished\":\"2020-04-28T22:00:00+00:00\",\"dateModified\":\"2021-05-21T18:20:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/\"},\"wordCount\":847,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1\",\"keywords\":[\".NetCore\",\"C#\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/\",\"name\":\"Golden Master Pattern: don't fear the legacy code! - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2020-04-28T22:00:00+00:00\",\"dateModified\":\"2021-05-21T18:20:37+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/6e574a2e13d47c9167c5cfb475d9bfc5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/golden-master-pattern-dont-fear-the-legacy-code\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Golden Master Pattern: don&#8217;t fear the legacy code!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/6e574a2e13d47c9167c5cfb475d9bfc5\",\"name\":\"Antonio Tammaro\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ddb88ac3dfb067ae6f1592d451eab3587e41bbbe98325961161cc286844e8d0d?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ddb88ac3dfb067ae6f1592d451eab3587e41bbbe98325961161cc286844e8d0d?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ddb88ac3dfb067ae6f1592d451eab3587e41bbbe98325961161cc286844e8d0d?s=96&d=identicon&r=g\",\"caption\":\"Antonio Tammaro\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/antonio-tammaroblexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Golden Master Pattern: don't fear the legacy code! - Blexin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/","og_locale":"en_US","og_type":"article","og_title":"Golden Master Pattern: don't fear the legacy code! - Blexin","og_description":"Let\u2019s see together how to modify legacy code ensuring it works thanks to the Golden Master Pattern","og_url":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/","og_site_name":"Blexin","article_published_time":"2020-04-28T22:00:00+00:00","article_modified_time":"2021-05-21T18:20:37+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i1.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Antonio Tammaro","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Antonio Tammaro","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/"},"author":{"name":"Antonio Tammaro","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/6e574a2e13d47c9167c5cfb475d9bfc5"},"headline":"Golden Master Pattern: don&#8217;t fear the legacy code!","datePublished":"2020-04-28T22:00:00+00:00","dateModified":"2021-05-21T18:20:37+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/"},"wordCount":847,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1","keywords":[".NetCore","C#"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/","url":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/","name":"Golden Master Pattern: don't fear the legacy code! - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1","datePublished":"2020-04-28T22:00:00+00:00","dateModified":"2021-05-21T18:20:37+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/6e574a2e13d47c9167c5cfb475d9bfc5"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/golden-master-pattern-dont-fear-the-legacy-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"Golden Master Pattern: don&#8217;t fear the legacy code!"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/6e574a2e13d47c9167c5cfb475d9bfc5","name":"Antonio Tammaro","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ddb88ac3dfb067ae6f1592d451eab3587e41bbbe98325961161cc286844e8d0d?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ddb88ac3dfb067ae6f1592d451eab3587e41bbbe98325961161cc286844e8d0d?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ddb88ac3dfb067ae6f1592d451eab3587e41bbbe98325961161cc286844e8d0d?s=96&d=identicon&r=g","caption":"Antonio Tammaro"},"url":"https:\/\/blexin.com\/en\/author\/antonio-tammaroblexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/fe85ca6d-91d7-4ead-9d01-d4adddef4e5e.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-7uy","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716249"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=28802"}],"version-history":[{"count":4,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28802\/revisions"}],"predecessor-version":[{"id":32932,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/28802\/revisions\/32932"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/26724"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=28802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=28802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=28802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}