From 85fb24e2aae10bf837c3c021fa4d9b624a7cd965 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 6 Feb 2025 20:51:06 +0100 Subject: [PATCH] Remove generators --- .../Exercises/Generators/Bowling.cs | 90 -------------- .../Exercises/Generators/CircularBuffer.cs | 53 -------- .../Exercises/Generators/Clock.cs | 57 --------- .../Exercises/Generators/ComplexNumbers.cs | 84 ------------- .../Exercises/Generators/CustomSet.cs | 54 -------- .../Exercises/Generators/DndCharacter.cs | 117 ------------------ .../Exercises/Generators/GoCounting.cs | 87 ------------- .../Exercises/Generators/HighScores.cs | 36 ------ .../Exercises/Generators/RationalNumbers.cs | 34 ----- 9 files changed, 612 deletions(-) delete mode 100644 generators.deprecated/Exercises/Generators/Bowling.cs delete mode 100644 generators.deprecated/Exercises/Generators/CircularBuffer.cs delete mode 100644 generators.deprecated/Exercises/Generators/Clock.cs delete mode 100644 generators.deprecated/Exercises/Generators/ComplexNumbers.cs delete mode 100644 generators.deprecated/Exercises/Generators/CustomSet.cs delete mode 100644 generators.deprecated/Exercises/Generators/DndCharacter.cs delete mode 100644 generators.deprecated/Exercises/Generators/GoCounting.cs delete mode 100644 generators.deprecated/Exercises/Generators/HighScores.cs delete mode 100644 generators.deprecated/Exercises/Generators/RationalNumbers.cs diff --git a/generators.deprecated/Exercises/Generators/Bowling.cs b/generators.deprecated/Exercises/Generators/Bowling.cs deleted file mode 100644 index a502d017a..000000000 --- a/generators.deprecated/Exercises/Generators/Bowling.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Bowling : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - if (testMethod.Expected is int) - testMethod.UseVariableForTested = true; - else - testMethod.ExceptionThrown = typeof(ArgumentException); - - testMethod.InputParameters = Array.Empty(); - - testMethod.Arrange = RenderArrange(testMethod); - testMethod.Act = RenderAct(testMethod); - testMethod.Assert = RenderAssert(testMethod); - } - - private string RenderArrange(TestMethod testMethod) - { - var builder = new StringBuilder(); - builder.AppendLine(Render.Variable("sut", "new BowlingGame()")); - - if (!testMethod.Input.ContainsKey("previousRolls")) - return builder.ToString(); - - var previousRolls = testMethod.Input["previousRolls"] as int[] ?? Array.Empty(); - builder.Append(Render.Variable("previousRolls", Render.ObjectMultiLine(previousRolls))); - - return builder.ToString(); - } - - private string? RenderAssert(TestMethod testMethod) - { - if (testMethod.ExceptionThrown != null && testMethod.Input.ContainsKey("roll")) - { - var actual = Render.Object(testMethod.Input["roll"]); - return Render.AssertThrows(testMethod.ExceptionThrown, $"sut.Roll({actual})"); - } - - if (testMethod.ExceptionThrown == null || testMethod.Property != "score") - return testMethod.Assert; - - return Render.AssertThrows(testMethod.ExceptionThrown, "sut.Score()"); - } - - private string RenderAct(TestMethod testMethod) - { - var act = new StringBuilder(); - act.AppendLine("DoRoll(previousRolls, sut);"); - - if (testMethod.ExceptionThrown != null) - { - return act.ToString(); - } - - if (testMethod.Input.ContainsKey("roll")) - { - act.AppendLine($"sut.Roll({testMethod.Input["roll"]});"); - act.AppendLine(Render.Variable("actual", "sut.Score()")); - return act.ToString(); - } - - act.AppendLine(Render.Variable("actual", "sut.Score()")); - return act.ToString(); - } - - protected override void UpdateTestClass(TestClass testClass) => AddDoRollMethod(testClass); - - private static void AddDoRollMethod(TestClass testClass) => - testClass.AdditionalMethods.Add(@" -private void DoRoll(IEnumerable rolls, BowlingGame sut) -{ - foreach (var roll in rolls) - { - sut.Roll(roll); - } -}"); - - protected override void UpdateNamespaces(ISet namespaces) - { - namespaces.Add(typeof(Array).Namespace!); - namespaces.Add(typeof(ICollection<>).Namespace!); - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/CircularBuffer.cs b/generators.deprecated/Exercises/Generators/CircularBuffer.cs deleted file mode 100644 index 134ea0fbf..000000000 --- a/generators.deprecated/Exercises/Generators/CircularBuffer.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class CircularBuffer : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) => testMethod.Assert = RenderAssert(testMethod); - - private string RenderAssert(TestMethod testMethod) - { - var assert = new StringBuilder(); - assert.AppendLine(RenderSut(testMethod)); - - foreach (var operation in testMethod.Input["operations"]) - assert.AppendLine(RenderOperation(operation)); - - return assert.ToString(); - } - - private string RenderSut(TestMethod testMethod) - => Render.Variable("buffer", $"new CircularBuffer(capacity: {testMethod.Input["capacity"]})"); - - private string RenderOperation(dynamic operation) => - operation["operation"] switch - { - "read" => RenderReadOperation(operation), - "write" => RenderWriteOperation(operation), - "overwrite" => RenderOverwriteOperation(operation), - "clear" => RenderClearOperation(), - _ => throw new ArgumentOutOfRangeException($"Unknown operation type: {operation["operation"]}") - }; - - private string RenderReadOperation(dynamic operation) - => operation["should_succeed"] - ? Render.AssertEqual(operation["expected"].ToString(), "buffer.Read()") - : Render.AssertThrows("buffer.Read()"); - - private string RenderWriteOperation(dynamic operation) - => operation["should_succeed"] - ? $"buffer.Write({operation["item"]});" - : Render.AssertThrows($"buffer.Write({operation["item"]})"); - - private static string RenderOverwriteOperation(dynamic operation) - => $"buffer.Overwrite({operation["item"]});"; - - private static string RenderClearOperation() - => "buffer.Clear();"; - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(InvalidOperationException).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/Clock.cs b/generators.deprecated/Exercises/Generators/Clock.cs deleted file mode 100644 index 92d601cd2..000000000 --- a/generators.deprecated/Exercises/Generators/Clock.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class Clock : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.ConstructorInputParameters = new[] { "hour", "minute" }; - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - - if (testMethod.Property == "create") - UpdateTestMethodForCreateProperty(testMethod); - else if (testMethod.Property == "equal") - UpdateTestMethodForEqualProperty(testMethod); - else - UpdateTestMethodForConsistencyProperty(testMethod); - } - - protected override void UpdateTestClass(TestClass testClass) => - testClass.AdditionalMethods.Add(@"[Fact(Skip = ""Remove this Skip property to run this test"")] -public void Clocks_are_immutable() -{ - var sut = new Clock(0, 0); - var sutPlus1 = sut.Add(1); - Assert.NotEqual(sutPlus1, sut); -}"); - - private static void UpdateTestMethodForCreateProperty(TestMethod testMethod) => testMethod.TestedMethod = "ToString"; - - private void UpdateTestMethodForEqualProperty(TestMethod testMethod) - { - var clock1 = testMethod.Input["clock1"]; - testMethod.Input["clock1"] = new UnescapedValue($"new Clock({clock1["hour"]}, {clock1["minute"]})"); - - var clock2 = testMethod.Input["clock2"]; - testMethod.Input["hour"] = clock2["hour"]; - testMethod.Input["minute"] = clock2["minute"]; - - testMethod.Assert = RenderEqualToAssert(testMethod); - } - - private string RenderEqualToAssert(TestMethod testMethod) - { - var expected = Render.Object(testMethod.Input["clock1"]); - - return testMethod.Expected - ? Render.AssertEqual(expected, "sut") - : Render.AssertNotEqual(expected, "sut"); - } - - private void UpdateTestMethodForConsistencyProperty(TestMethod testMethod) => testMethod.Assert = RenderConsistencyToAssert(testMethod); - - private string RenderConsistencyToAssert(TestMethod testMethod) - => Render.AssertEqual(Render.Object(testMethod.Expected), $"sut.{testMethod.TestedMethod}({testMethod.Input["value"]}).ToString()"); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/ComplexNumbers.cs b/generators.deprecated/Exercises/Generators/ComplexNumbers.cs deleted file mode 100644 index c2ed6881c..000000000 --- a/generators.deprecated/Exercises/Generators/ComplexNumbers.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using DotLiquid.Tags; - -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class ComplexNumbers : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestedClass = "ComplexNumber"; - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - - testMethod.UseVariableForExpected = IsComplexNumber(testMethod.Expected); - testMethod.Expected = ConvertToType(testMethod.Expected); - - var constructorParamName = testMethod.Input.ContainsKey("z") ? "z" : "z1"; - testMethod.Input["real"] = ConvertToDouble(testMethod.Input[constructorParamName], 0); - testMethod.Input["imaginary"] = ConvertToDouble(testMethod.Input[constructorParamName], 1); - - testMethod.InputParameters = GetInputParameters(testMethod, constructorParamName); - testMethod.ConstructorInputParameters = new[] {"real", "imaginary"}; - - var keys = testMethod.Input.Keys.ToArray(); - - foreach (var key in keys) - testMethod.Input[key] = ConvertToType(testMethod.Input[key]); - - testMethod.Assert = RenderAssert(testMethod); - } - - private static string[] GetInputParameters(TestMethod testMethod, string constructorParamName) - => testMethod.Input.Keys.Where(x => x != constructorParamName).ToArray(); - - private string? RenderAssert(TestMethod testMethod) => testMethod.UseVariableForExpected - ? RenderComplexNumberAssert(testMethod) - : testMethod.Assert; - - private string RenderComplexNumberAssert(TestMethod testMethod) - { - var inputParameters = testMethod.Input.ContainsKey("z") ? "" : Render.Object(testMethod.Input["z2"]); - var actual = $"sut.{testMethod.TestedMethod}({inputParameters})"; - - var assert = new StringBuilder(); - assert.AppendLine(Render.AssertEqualWithin("expected.Real()", $"{actual}.Real()", 7)); - assert.AppendLine(Render.AssertEqualWithin("expected.Imaginary()", $"{actual}.Imaginary()", 7)); - - return assert.ToString(); - } - - private object ConvertToType(dynamic rawValue) - => IsComplexNumber(rawValue) - ? RenderComplexNumber(rawValue) - : rawValue; - - private UnescapedValue RenderComplexNumber(dynamic rawValue) - => new($"new ComplexNumber({Render.Object(ConvertToDouble(rawValue, 0))}, {Render.Object(ConvertToDouble(rawValue, 1))})"); - - private static bool IsComplexNumber(object rawValue) => rawValue is int[] || rawValue is double[] || rawValue is float[] || rawValue is JArray; - - private static object ConvertToDouble(dynamic value, int index) => - value switch - { - string _ => ParseDouble(value), - int _ => ParseDouble(value), - double _ => ParseDouble(value), - _ => ParseDouble(value[index]) - }; - - private static object ParseDouble(dynamic value) => - double.TryParse(value.ToString(), out double result ) ? - result : - new UnescapedValue(value.ToString().Replace("e", "Math.E").Replace("pi", "Math.PI") - .Replace("ln(2)", "Math.Log(2.0)")); - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Math).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/CustomSet.cs b/generators.deprecated/Exercises/Generators/CustomSet.cs deleted file mode 100644 index 2069a2a7e..000000000 --- a/generators.deprecated/Exercises/Generators/CustomSet.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class CustomSet : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - testMethod.Expected = ConvertToCustomSet(testMethod.Expected); - - if (testMethod.Input.ContainsKey("set")) - UpdateTestMethodForSingleSetProperty(testMethod); - else - UpdateTestMethodForMultipleSetsProperty(testMethod); - } - - private static void UpdateTestMethodForSingleSetProperty(TestMethod testMethod) - { - if (testMethod.Input["set"] is JArray) - { - testMethod.Input["set"] = new UnescapedValue(""); - } - - testMethod.ConstructorInputParameters = new[] {"set"}; - } - - private void UpdateTestMethodForMultipleSetsProperty(TestMethod testMethod) - { - if (testMethod.Input["set1"] is JArray) - { - testMethod.Input["set1"] = new UnescapedValue(""); - } - - testMethod.ConstructorInputParameters = new[] {"set1"}; - testMethod.Input["set2"] = ConvertToCustomSet(testMethod.Input["set2"]); - - if (testMethod.Property == "equal") - { - testMethod.TestedMethod = "Equals"; - } - } - - private dynamic ConvertToCustomSet(dynamic value) => - value switch - { - bool _ => value, - int[] values when values.Length > 0 => new UnescapedValue($"new CustomSet({Render.Object(values)})"), - _ => new UnescapedValue("new CustomSet()") - }; -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/DndCharacter.cs b/generators.deprecated/Exercises/Generators/DndCharacter.cs deleted file mode 100644 index 34f52e643..000000000 --- a/generators.deprecated/Exercises/Generators/DndCharacter.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Exercism.CSharp.Helpers; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class DndCharacter : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestMethodName = testMethod.Description.Replace("-", "minus_").ToTestMethodName(); - - if (testMethod.Property == "ability") - UpdateTestMethodForAbilityProperty(testMethod); - else if (testMethod.Property == "character") - UpdateTestMethodForCharacterProperty(testMethod); - else if (testMethod.Property == "strength") - UpdateTestMethodForStrengthProperty(testMethod); - } - - protected override void UpdateTestClass(TestClass testClass) => AddTestMethodForDistribution(testClass); - - private void UpdateTestMethodForAbilityProperty(TestMethod testMethod) - => testMethod.Assert = RenderAssertForAbilityProperty(testMethod); - - private string RenderAssertForAbilityProperty(TestMethod testMethod) - { - var assert = new StringBuilder(); - assert.AppendLine("for (var i = 0; i < 10; i++)"); - assert.AppendLine("{"); - assert.AppendLine(RenderAssertForAbilityRange($"{testMethod.TestedClass}.{testMethod.TestedMethod}()").Indent()); - assert.AppendLine("}"); - return assert.ToString(); - } - - private void UpdateTestMethodForCharacterProperty(TestMethod testMethod) - => testMethod.Assert = RenderAssertForCharacterProperty(testMethod); - - private string RenderAssertForCharacterProperty(TestMethod testMethod) - { - var assert = new StringBuilder(); - assert.AppendLine("for (var i = 0; i < 10; i++)"); - assert.AppendLine("{"); - assert.AppendLine(Render.Variable("sut", $"{testMethod.TestedClass}.Generate()").Indent()); - assert.AppendLine(RenderAssertForAbilityRange("sut.Strength").Indent()); - assert.AppendLine(RenderAssertForAbilityRange("sut.Dexterity").Indent()); - assert.AppendLine(RenderAssertForAbilityRange("sut.Constitution").Indent()); - assert.AppendLine(RenderAssertForAbilityRange("sut.Intelligence").Indent()); - assert.AppendLine(RenderAssertForAbilityRange("sut.Wisdom").Indent()); - assert.AppendLine(RenderAssertForAbilityRange("sut.Charisma").Indent()); - assert.AppendLine(Render.AssertEqual($"sut.Hitpoints", $"10 + {testMethod.TestedClass}.Modifier(sut.Constitution)").Indent()); - assert.AppendLine("}"); - return assert.ToString(); - } - - private string RenderAssertForAbilityRange(string ability) => Render.AssertInRange(ability, 3, 18); - - private void UpdateTestMethodForStrengthProperty(TestMethod testMethod) - => testMethod.Assert = RenderAssertForStrengthProperty(testMethod); - - private string RenderAssertForStrengthProperty(TestMethod testMethod) - { - var assert = new StringBuilder(); - assert.AppendLine("for (var i = 0; i < 10; i++)"); - assert.AppendLine("{"); - assert.AppendLine(Render.Variable("sut", $"{testMethod.TestedClass}.Generate()").Indent()); - assert.AppendLine(Render.AssertEqual("sut.Strength", "sut.Strength").Indent()); - assert.AppendLine(Render.AssertEqual("sut.Dexterity", "sut.Dexterity").Indent()); - assert.AppendLine(Render.AssertEqual("sut.Constitution", "sut.Constitution").Indent()); - assert.AppendLine(Render.AssertEqual("sut.Intelligence", "sut.Intelligence").Indent()); - assert.AppendLine(Render.AssertEqual("sut.Wisdom", "sut.Wisdom").Indent()); - assert.AppendLine(Render.AssertEqual("sut.Charisma", "sut.Charisma").Indent()); - assert.AppendLine("}"); - return assert.ToString(); - } - - private static void AddTestMethodForDistribution(TestClass testClass) => - testClass.AdditionalMethods.Add(@" -[Fact(Skip = ""Remove this Skip property to run this test"")] -public void Random_ability_is_distributed_correctly() -{ - var expectedDistribution = new Dictionary - { - [3] = 1, [4] = 4, - [5] = 10, [6] = 21, - [7] = 38, [8] = 62, - [9] = 91, [10] = 122, - [11] = 148, [12] = 167, - [13] = 172, [14] = 160, - [15] = 131, [16] = 94, - [17] = 54, [18] = 21 - }; - - var actualDistribution = new Dictionary(expectedDistribution); - foreach (var key in actualDistribution.Keys) - actualDistribution[key] = 0; - - const int times = 250; - const int possibleCombinationsCount = 6*6*6*6; // 4d6 - for (var i = 0; i < times * possibleCombinationsCount; i++) - actualDistribution[DndCharacter.Ability()]++; - - const double minTimes = times * 0.8; - const double maxTimes = times * 1.2; - foreach (var k in expectedDistribution.Keys) - Assert.InRange(actualDistribution[k], expectedDistribution[k] * minTimes, expectedDistribution[k] * maxTimes); -}"); - - protected override void UpdateNamespaces(ISet namespaces) - { - namespaces.Add(typeof(Enumerable).Namespace!); - namespaces.Add(typeof(Dictionary).Namespace!); - } -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/GoCounting.cs b/generators.deprecated/Exercises/Generators/GoCounting.cs deleted file mode 100644 index 98badcee6..000000000 --- a/generators.deprecated/Exercises/Generators/GoCounting.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Exercism.CSharp.Output; -using Exercism.CSharp.Output.Rendering; -using Newtonsoft.Json.Linq; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class GoCounting : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.UseVariablesForInput = true; - testMethod.UseVariableForExpected = true; - testMethod.UseVariablesForConstructorParameters = true; - testMethod.UseVariableForTested = true; - - testMethod.Input["board"] = new MultiLineString(testMethod.Input["board"]); - testMethod.ConstructorInputParameters = new[] { "board" }; - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - - if (testMethod.Property == "territory") - UpdateTestMethodForTerritoryProperty(testMethod); - else - UpdateTestMethodForTerritoriesProperty(testMethod); - } - - private void UpdateTestMethodForTerritoryProperty(TestMethod testMethod) - { - testMethod.Input["coordinate"] = (testMethod.Input["x"], testMethod.Input["y"]); - testMethod.InputParameters = new[] {"coordinate"}; - - if (testMethod.ExpectedIsError) - { - testMethod.ExceptionThrown = typeof(ArgumentException); - } - else - { - var owner = RenderOwner(testMethod.Expected!["owner"]!); - var territory = RenderTerritory(testMethod.Expected["territory"]); - testMethod.Expected = (owner, territory); - testMethod.Assert = RenderTerritoryAssert(); - } - } - - private void UpdateTestMethodForTerritoriesProperty(TestMethod testMethod) - { - var expected = new[] - { - "new Dictionary>", - "{", - $" [Owner.Black] = {RenderTerritory(testMethod.Expected!["territoryBlack"])},", - $" [Owner.White] = {RenderTerritory(testMethod.Expected!["territoryWhite"])},", - $" [Owner.None] = {RenderTerritory(testMethod.Expected!["territoryNone"])}", - "}" - }; - - testMethod.Expected = new UnescapedValue(string.Join(Environment.NewLine, expected)); - testMethod.Assert = RenderTerritoriesAssert(); - } - - private string RenderTerritoryAssert() - { - var assert = new StringBuilder(); - assert.AppendLine(Render.AssertEqual("expected.Item1", "actual.Item1")); - assert.AppendLine(Render.AssertEqual("expected.Item2", "actual.Item2")); - return assert.ToString(); - } - - private string RenderTerritoriesAssert() - { - var territoriesAssert = new StringBuilder(); - territoriesAssert.AppendLine(Render.AssertEqual("expected[Owner.Black]", "actual[Owner.Black]")); - territoriesAssert.AppendLine(Render.AssertEqual("expected[Owner.White]", "actual[Owner.White]")); - territoriesAssert.AppendLine(Render.AssertEqual("expected[Owner.None]", "actual[Owner.None]")); - return territoriesAssert.ToString(); - } - - private UnescapedValue RenderOwner(dynamic owner) => Render.Enum("Owner", owner); - - private string RenderTerritory(dynamic territory) - => Render.Object(((JArray)territory).Select(coordinate => (coordinate[0]!.ToObject(), coordinate[1]!.ToObject())).ToHashSet()); - - protected override void UpdateNamespaces(ISet namespaces) => namespaces.Add(typeof(Dictionary).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/HighScores.cs b/generators.deprecated/Exercises/Generators/HighScores.cs deleted file mode 100644 index 03963a6d6..000000000 --- a/generators.deprecated/Exercises/Generators/HighScores.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Channels; - -using Exercism.CSharp.Output; - -using Humanizer; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class HighScores : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) - { - testMethod.TestedMethodType = TestedMethodType.InstanceMethod; - testMethod.ConstructorInputParameters = new[] { "scores" }; - - testMethod.Input["scores"] = new List(testMethod.Input["scores"]); - - if (testMethod.Expected is IEnumerable) - testMethod.Expected = new List(testMethod.Expected); - - if (testMethod.Scenarios.Contains("immutable")) - { - var beforeProperty = testMethod.Property.Substring(0, testMethod.Property.IndexOf("After", StringComparison.Ordinal)).Replace("Best", "PersonalBest").Replace("TopThree", "PersonalTopThree").Pascalize(); - var afterProperty = testMethod.Property.Substring(testMethod.Property.IndexOf("After", StringComparison.Ordinal) + 5).Replace("Best", "PersonalBest").Replace("TopThree", "PersonalTopThree").Pascalize(); - - testMethod.Act = $"var _ = sut.{afterProperty}();"; - testMethod.TestedMethod = beforeProperty; - } - } - - protected override void UpdateNamespaces(ISet namespaces) => - namespaces.Add(typeof(List).Namespace!); -} \ No newline at end of file diff --git a/generators.deprecated/Exercises/Generators/RationalNumbers.cs b/generators.deprecated/Exercises/Generators/RationalNumbers.cs deleted file mode 100644 index 817ac233b..000000000 --- a/generators.deprecated/Exercises/Generators/RationalNumbers.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using Exercism.CSharp.Output; - -namespace Exercism.CSharp.Exercises.Generators; - -internal class RationalNumbers : ExerciseGenerator -{ - protected override void UpdateTestMethod(TestMethod testMethod) => testMethod.Assert = RenderAssert(testMethod); - - private string RenderAssert(TestMethod testMethod) - { - switch (testMethod.Property) - { - case "add": - case "sub": - case "mul": - case "div": - const string operationsWithOverloading = "add|+|sub|-|mul|*|div|/"; - var operationCode = operationsWithOverloading.Substring(operationsWithOverloading.IndexOf(testMethod.Property, StringComparison.OrdinalIgnoreCase) + 4, 1); - return Render.AssertEqual(RenderRationalNumber(testMethod.Expected), $"{RenderRationalNumber(testMethod.Input["r1"])} {operationCode} ({RenderRationalNumber(testMethod.Input["r2"])})"); - case "abs": - case "reduce": - return Render.AssertEqual(RenderRationalNumber(testMethod.Expected), $"{RenderRationalNumber(testMethod.Input["r"])}.{testMethod.TestedMethod}()"); - case "exprational": - return Render.AssertEqual(RenderRationalNumber(testMethod.Expected), $"{RenderRationalNumber(testMethod.Input["r"])}.{testMethod.TestedMethod}({testMethod.Input["n"]})"); - case "expreal": - return Render.AssertEqualWithin(Render.Object(testMethod.Expected), $"{testMethod.Input["x"]}.{testMethod.TestedMethod}({RenderRationalNumber(testMethod.Input["r"])})", 7); - default: - throw new ArgumentOutOfRangeException(); - } - } - - private static string RenderRationalNumber(dynamic input) => $"new RationalNumber({input[0]}, {input[1]})"; -} \ No newline at end of file