diff --git a/exercises/practice/all-your-base/.meta/Generator.tpl b/exercises/practice/all-your-base/.meta/Generator.tpl new file mode 100644 index 0000000000..57418803fd --- /dev/null +++ b/exercises/practice/all-your-base/.meta/Generator.tpl @@ -0,0 +1,20 @@ +using System; +using Xunit; + +public class AllYourBaseTests +{ + {{for testCase in testCases}} + [Fact{{if !for.first}}(Skip = "Remove this Skip property to run this test"){{end}}] + public void {{testCase.testMethodName}}() + { + {{if testCase.expected.error}} + int[] digits = {{testCase.input.digits}}; + Assert.Throws(() => AllYourBase.Rebase({{testCase.input.inputBase}}, digits, {{testCase.input.outputBase}})); + {{else}} + int[] digits = {{testCase.input.digits}}; + int[] expected = {{testCase.expected}}; + Assert.Equal(expected, AllYourBase.Rebase({{testCase.input.inputBase}}, digits, {{testCase.input.outputBase}})); + {{end}} + } + {{end}} +} diff --git a/exercises/practice/all-your-base/AllYourBaseTests.cs b/exercises/practice/all-your-base/AllYourBaseTests.cs index 14f7f5a24e..0b8a287600 100644 --- a/exercises/practice/all-your-base/AllYourBaseTests.cs +++ b/exercises/practice/all-your-base/AllYourBaseTests.cs @@ -6,201 +6,159 @@ public class AllYourBaseTests [Fact] public void Single_bit_one_to_decimal() { - var inputBase = 2; - var digits = new[] { 1 }; - var outputBase = 10; - var expected = new[] { 1 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1]; + int[] expected = [1]; + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Binary_to_single_decimal() { - var inputBase = 2; - var digits = new[] { 1, 0, 1 }; - var outputBase = 10; - var expected = new[] { 5 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1, 0, 1]; + int[] expected = [5]; + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Single_decimal_to_binary() { - var inputBase = 10; - var digits = new[] { 5 }; - var outputBase = 2; - var expected = new[] { 1, 0, 1 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [5]; + int[] expected = [1, 0, 1]; + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 2)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Binary_to_multiple_decimal() { - var inputBase = 2; - var digits = new[] { 1, 0, 1, 0, 1, 0 }; - var outputBase = 10; - var expected = new[] { 4, 2 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1, 0, 1, 0, 1, 0]; + int[] expected = [4, 2]; + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Decimal_to_binary() { - var inputBase = 10; - var digits = new[] { 4, 2 }; - var outputBase = 2; - var expected = new[] { 1, 0, 1, 0, 1, 0 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [4, 2]; + int[] expected = [1, 0, 1, 0, 1, 0]; + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 2)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Trinary_to_hexadecimal() { - var inputBase = 3; - var digits = new[] { 1, 1, 2, 0 }; - var outputBase = 16; - var expected = new[] { 2, 10 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1, 1, 2, 0]; + int[] expected = [2, 10]; + Assert.Equal(expected, AllYourBase.Rebase(3, digits, 16)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Hexadecimal_to_trinary() { - var inputBase = 16; - var digits = new[] { 2, 10 }; - var outputBase = 3; - var expected = new[] { 1, 1, 2, 0 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [2, 10]; + int[] expected = [1, 1, 2, 0]; + Assert.Equal(expected, AllYourBase.Rebase(16, digits, 3)); } [Fact(Skip = "Remove this Skip property to run this test")] - public void Number_15_bit_integer() + public void Fifteen_bit_integer() { - var inputBase = 97; - var digits = new[] { 3, 46, 60 }; - var outputBase = 73; - var expected = new[] { 6, 10, 45 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [3, 46, 60]; + int[] expected = [6, 10, 45]; + Assert.Equal(expected, AllYourBase.Rebase(97, digits, 73)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Empty_list() { - var inputBase = 2; - var digits = Array.Empty(); - var outputBase = 10; - var expected = new[] { 0 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = []; + int[] expected = [0]; + Assert.Equal(expected, AllYourBase.Rebase(2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Single_zero() { - var inputBase = 10; - var digits = new[] { 0 }; - var outputBase = 2; - var expected = new[] { 0 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [0]; + int[] expected = [0]; + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 2)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Multiple_zeros() { - var inputBase = 10; - var digits = new[] { 0, 0, 0 }; - var outputBase = 2; - var expected = new[] { 0 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [0, 0, 0]; + int[] expected = [0]; + Assert.Equal(expected, AllYourBase.Rebase(10, digits, 2)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Leading_zeros() { - var inputBase = 7; - var digits = new[] { 0, 6, 0 }; - var outputBase = 10; - var expected = new[] { 4, 2 }; - Assert.Equal(expected, AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [0, 6, 0]; + int[] expected = [4, 2]; + Assert.Equal(expected, AllYourBase.Rebase(7, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Input_base_is_one() { - var inputBase = 1; - var digits = new[] { 0 }; - var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [0]; + Assert.Throws(() => AllYourBase.Rebase(1, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Input_base_is_zero() { - var inputBase = 0; - var digits = Array.Empty(); - var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = []; + Assert.Throws(() => AllYourBase.Rebase(0, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Input_base_is_negative() { - var inputBase = -2; - var digits = new[] { 1 }; - var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1]; + Assert.Throws(() => AllYourBase.Rebase(-2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Negative_digit() { - var inputBase = 2; - var digits = new[] { 1, -1, 1, 0, 1, 0 }; - var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1, -1, 1, 0, 1, 0]; + Assert.Throws(() => AllYourBase.Rebase(2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Invalid_positive_digit() { - var inputBase = 2; - var digits = new[] { 1, 2, 1, 0, 1, 0 }; - var outputBase = 10; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1, 2, 1, 0, 1, 0]; + Assert.Throws(() => AllYourBase.Rebase(2, digits, 10)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Output_base_is_one() { - var inputBase = 2; - var digits = new[] { 1, 0, 1, 0, 1, 0 }; - var outputBase = 1; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1, 0, 1, 0, 1, 0]; + Assert.Throws(() => AllYourBase.Rebase(2, digits, 1)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Output_base_is_zero() { - var inputBase = 10; - var digits = new[] { 7 }; - var outputBase = 0; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [7]; + Assert.Throws(() => AllYourBase.Rebase(10, digits, 0)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Output_base_is_negative() { - var inputBase = 2; - var digits = new[] { 1 }; - var outputBase = -7; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1]; + Assert.Throws(() => AllYourBase.Rebase(2, digits, -7)); } [Fact(Skip = "Remove this Skip property to run this test")] public void Both_bases_are_negative() { - var inputBase = -2; - var digits = new[] { 1 }; - var outputBase = -7; - Assert.Throws(() => AllYourBase.Rebase(inputBase, digits, outputBase)); + int[] digits = [1]; + Assert.Throws(() => AllYourBase.Rebase(-2, digits, -7)); } } diff --git a/generators/Naming.cs b/generators/Naming.cs index e27556d8e3..378acf2171 100644 --- a/generators/Naming.cs +++ b/generators/Naming.cs @@ -17,6 +17,6 @@ private static string Transform(string str, int index) => ? i.ToWords() : str.Dehumanize(); - private static IEnumerable Words(this string str) => str.Split(' '); + private static IEnumerable Words(this string str) => str.Split(' ', '-'); private static string Unwords(this IEnumerable strs) => string.Join(' ', strs); } \ No newline at end of file