Sha256: 9bcb176b5e58d6c9a1843da8bda612e80cce44b2328ff62e539f43e8ab1072b5

Contents?: true

Size: 1.82 KB

Versions: 28

Compression:

Stored size: 1.82 KB

Contents

using Generators.Input;
using Generators.Output;

namespace Generators.Exercises
{
    public class CustomSet : GeneratorExercise
    {
        protected override void UpdateCanonicalData(CanonicalData canonicalData)
        {
            foreach (var canonicalDataCase in canonicalData.Cases)
            {
                canonicalDataCase.UseVariablesForInput = true;

                if (canonicalDataCase.Input.ContainsKey("set"))
                {
                    if (!(canonicalDataCase.Input["set"] is int[]))
                    {
                        canonicalDataCase.Input["set"] = new UnescapedValue("");
                    }

                    canonicalDataCase.SetConstructorInputParameters("set");
                }
                else
                {
                    if (!(canonicalDataCase.Input["set1"] is int[]))
                    {
                        canonicalDataCase.Input["set1"] = new UnescapedValue("");
                    }

                    canonicalDataCase.SetConstructorInputParameters("set1");
                    canonicalDataCase.Input["set2"] = ConvertCustomSet(canonicalDataCase.Input["set2"]);

                    if (canonicalDataCase.Property == "equal")
                    {
                        canonicalDataCase.Property = "Equals";
                    }
                }

                canonicalDataCase.Expected = ConvertCustomSet(canonicalDataCase.Expected);
            }
        }

        private static dynamic ConvertCustomSet(dynamic value)
        {
            if (value is bool)
                return value;

            if (value is int[] values && values.Length > 0)
            {
                return new UnescapedValue($"new CustomSet({ValueFormatter.Format(values)})");
            }

            return new UnescapedValue($"new CustomSet()");
        }
    }
}

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.179 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.178 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.177 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.176 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.175 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.174 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.173 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.172 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.171 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.170 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.169 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.167 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.166 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.165 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.164 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.163 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.162 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.161 tracks/csharp/generators/Exercises/CustomSet.cs
trackler-2.2.1.160 tracks/csharp/generators/Exercises/CustomSet.cs