diff --git a/exercises/all-your-base/AllYourBaseTest.cs b/exercises/all-your-base/AllYourBaseTest.cs index 796996a598..7bab626460 100644 --- a/exercises/all-your-base/AllYourBaseTest.cs +++ b/exercises/all-your-base/AllYourBaseTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.1.0 of the canonical data. +// This file was auto-generated based on version 2.0.0 of the canonical data. using Xunit; using System; @@ -91,7 +91,8 @@ public void Empty_list() var inputBase = 2; var inputDigits = new int[0]; var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, inputDigits, outputBase)); + var expected = new[] { 0 }; + Assert.Equal(expected, AllYourBase.Rebase(inputBase, inputDigits, outputBase)); } [Fact(Skip = "Remove to run test")] @@ -100,7 +101,8 @@ public void Single_zero() var inputBase = 10; var inputDigits = new[] { 0 }; var outputBase = 2; - Assert.Throws(() => AllYourBase.Rebase(inputBase, inputDigits, outputBase)); + var expected = new[] { 0 }; + Assert.Equal(expected, AllYourBase.Rebase(inputBase, inputDigits, outputBase)); } [Fact(Skip = "Remove to run test")] @@ -109,7 +111,8 @@ public void Multiple_zeros() var inputBase = 10; var inputDigits = new[] { 0, 0, 0 }; var outputBase = 2; - Assert.Throws(() => AllYourBase.Rebase(inputBase, inputDigits, outputBase)); + var expected = new[] { 0 }; + Assert.Equal(expected, AllYourBase.Rebase(inputBase, inputDigits, outputBase)); } [Fact(Skip = "Remove to run test")] @@ -118,7 +121,8 @@ public void Leading_zeros() var inputBase = 7; var inputDigits = new[] { 0, 6, 0 }; var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, inputDigits, outputBase)); + var expected = new[] { 4, 2 }; + Assert.Equal(expected, AllYourBase.Rebase(inputBase, inputDigits, outputBase)); } [Fact(Skip = "Remove to run test")] diff --git a/exercises/all-your-base/Example.cs b/exercises/all-your-base/Example.cs index 0ef49b3730..00fc78091f 100644 --- a/exercises/all-your-base/Example.cs +++ b/exercises/all-your-base/Example.cs @@ -8,16 +8,20 @@ public static int[] Rebase(int inputBase, int[] inputDigits, int outputBase) { if (inputBase < 2) throw new ArgumentException("Invalid input base."); if (outputBase < 2) throw new ArgumentException("Invalid output base."); - if (inputDigits.Length == 0) throw new ArgumentException("Empty input digits."); - return ToDigits(outputBase, FromDigits(inputBase, inputDigits)); + var inputDigitsWithoutLeadingZeros = inputDigits.SkipWhile(digit => digit == 0).ToArray(); + + if (inputDigitsWithoutLeadingZeros.Length == 0) + return new[] { 0 }; + + return ToDigits(outputBase, FromDigits(inputBase, inputDigitsWithoutLeadingZeros)); } private static int FromDigits(int fromBase, int[] fromDigits) { return fromDigits.Aggregate(0, (acc, x) => { - if (x < 0 || x >= fromBase || (x == 0 & acc == 0)) throw new ArgumentException("Invalid input digit"); + if (x < 0 || x >= fromBase) throw new ArgumentException("Invalid input digit"); return acc*fromBase + x; }); diff --git a/exercises/nth-prime/NthPrimeTest.cs b/exercises/nth-prime/NthPrimeTest.cs index 0ed1699694..8f334d8a50 100644 --- a/exercises/nth-prime/NthPrimeTest.cs +++ b/exercises/nth-prime/NthPrimeTest.cs @@ -1,4 +1,4 @@ -// This file was auto-generated based on version 1.0.0 of the canonical data. +// This file was auto-generated based on version 2.0.0 of the canonical data. using Xunit; using System; diff --git a/generators/Exercises/AllYourBase.cs b/generators/Exercises/AllYourBase.cs index 29290dc8a3..d9a288a2d7 100644 --- a/generators/Exercises/AllYourBase.cs +++ b/generators/Exercises/AllYourBase.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Generators.Input; namespace Generators.Exercises @@ -9,7 +10,7 @@ protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) { - canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is null ? typeof(ArgumentException) : null; + canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is Dictionary ? typeof(ArgumentException) : null; canonicalDataCase.UseVariablesForInput = true; canonicalDataCase.UseVariableForExpected = true; } diff --git a/generators/Exercises/NthPrime.cs b/generators/Exercises/NthPrime.cs index 7ed2cad7c9..bea5e4d7d4 100644 --- a/generators/Exercises/NthPrime.cs +++ b/generators/Exercises/NthPrime.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Generators.Input; namespace Generators.Exercises @@ -8,7 +9,7 @@ public class NthPrime : Exercise protected override void UpdateCanonicalData(CanonicalData canonicalData) { foreach (var canonicalDataCase in canonicalData.Cases) - canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is bool ? typeof(ArgumentOutOfRangeException) : null; + canonicalDataCase.ExceptionThrown = canonicalDataCase.Expected is Dictionary ? typeof(ArgumentOutOfRangeException) : null; } } } \ No newline at end of file