Sha256: 88a96b3a25bf333d173b654d04cc02a1e9efb0573e33e835bfb782d0c6330639

Contents?: true

Size: 1.75 KB

Versions: 86

Compression:

Stored size: 1.75 KB

Contents

using Generators.Input;
using Generators.Output;

namespace Generators.Exercises
{
    public class Connect : GeneratorExercise
    {
        protected override void UpdateCanonicalData(CanonicalData canonicalData)
        {
            foreach (var canonicalDataCase in canonicalData.Cases)
            {
                canonicalDataCase.UseVariablesForConstructorParameters = true;
                canonicalDataCase.SetConstructorInputParameters("board");
                canonicalDataCase.Property = "result";
                canonicalDataCase.Properties["board"] = ToMultiLineString(canonicalDataCase.Properties["board"]);

                //convert to enum
                switch (canonicalDataCase.Properties["expected"])
                {
                    case "X":
                        canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.Black");
                        break;
                    case "O":
                        canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.White");
                        break;
                    case "":
                        canonicalDataCase.Properties["expected"] = new UnescapedValue("ConnectWinner.None");
                        break;
                }
            }
        }

        private UnescapedValue ToMultiLineString(string[] input)
        {
            const string template = 
@"new [] 
{ 
    {% if input.size == 0 %}string.Empty{% else %}{% for item in {{input}} %}{% if forloop.length == 1 %}""{{item}}""{% break %}{% endif %}""{{item}}""{% if forloop.last == false %},{% else %}{{string.Empty}}{% endif %}
    {% endfor %}{% endif %} 
}";

            return new UnescapedValue(TemplateRenderer.RenderInline(template, new { input }));
        }
    }
}

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
trackler-2.2.1.151 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.150 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.149 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.148 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.147 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.146 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.145 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.144 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.143 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.142 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.141 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.140 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.139 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.138 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.137 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.136 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.135 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.134 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.133 tracks/csharp/generators/Exercises/Connect.cs
trackler-2.2.1.132 tracks/csharp/generators/Exercises/Connect.cs