diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba41720 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +**/.idea +**/bin +**/obj +**/.DS_Store +**/.vs +**/*.DotSettings.user + +**.csproj.user + +**.orig diff --git a/RomanNumbers.sln b/RomanNumbers.sln new file mode 100644 index 0000000..a21aa66 --- /dev/null +++ b/RomanNumbers.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RomanNumbers", "RomanNumbers\RomanNumbers.csproj", "{04E6EE40-4E55-484A-9470-8114CE66D5A6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RomanNumbers_Tests", "RomanNumbers_Tests\RomanNumbers_Tests.csproj", "{BD117369-C26D-4456-BE0E-635A6CC49B6E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04E6EE40-4E55-484A-9470-8114CE66D5A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04E6EE40-4E55-484A-9470-8114CE66D5A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04E6EE40-4E55-484A-9470-8114CE66D5A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04E6EE40-4E55-484A-9470-8114CE66D5A6}.Release|Any CPU.Build.0 = Release|Any CPU + {BD117369-C26D-4456-BE0E-635A6CC49B6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BD117369-C26D-4456-BE0E-635A6CC49B6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BD117369-C26D-4456-BE0E-635A6CC49B6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BD117369-C26D-4456-BE0E-635A6CC49B6E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/RomanNumbers/GlobalUsings.cs b/RomanNumbers/GlobalUsings.cs new file mode 100644 index 0000000..5773852 --- /dev/null +++ b/RomanNumbers/GlobalUsings.cs @@ -0,0 +1,4 @@ +// Global using directives + +global using static System.Console; +global using static System.IO.File; \ No newline at end of file diff --git a/RomanNumbers/Program.cs b/RomanNumbers/Program.cs new file mode 100644 index 0000000..3caa1c2 --- /dev/null +++ b/RomanNumbers/Program.cs @@ -0,0 +1,27 @@ +var p = ReadAllLines(args[0]); + +string[][] x = +[ + ["I", "IV", "V", "I"], + ["X", "XL", "L", "X", "X"], + ["C", "CD", "D", "C", "C"], + ["M"] +]; + +foreach (var l in p) +{ + var o = ""; + var i = 1; + foreach (var h in l.Reverse()) + { + var e = h - '0'; + o = + e == 1 && i != 1 ? x[i - 1][4] + o : + e < 4 && e != 0 ? new string(x[i - 1][0][0], e) + o : + e == 4 ? x[i - 1][1] + o : + e < 10 && e != 0 ? x[i - 1][2] + new string(x[i - 1][3][0], e - 5) + o : + o; + i++; + } + WriteLine(o); +} diff --git a/RomanNumbers/RomanNumbers.csproj b/RomanNumbers/RomanNumbers.csproj new file mode 100644 index 0000000..f9839e8 --- /dev/null +++ b/RomanNumbers/RomanNumbers.csproj @@ -0,0 +1,22 @@ + + + + Exe + net9.0 + enable + enable + + + + + Always + + + + + + <_Parameter1>RomanNumbers_Tests + + + + diff --git a/RomanNumbers/input.txt b/RomanNumbers/input.txt new file mode 100644 index 0000000..841c1f0 --- /dev/null +++ b/RomanNumbers/input.txt @@ -0,0 +1,23 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +20 +25 +31 +43 +50 +55 +60 +90 +104 +243 +401 +3277 diff --git a/RomanNumbers_Tests/Program.cs b/RomanNumbers_Tests/Program.cs new file mode 100644 index 0000000..9de60b1 --- /dev/null +++ b/RomanNumbers_Tests/Program.cs @@ -0,0 +1,75 @@ +using System.Diagnostics; +using Xunit; + +namespace RomanNumbers_Tests; + +public class RomanNumberConversionTests +{ + // [Fact] + // public void TestConsoleOutput() + // { + // // Setup test file + // var testFilePath = Path.GetTempFileName(); + // File.WriteAllText(testFilePath, "42\n99"); + // + // // Redirect console output + // var originalOut = Console.Out; + // using var output = new StringWriter(); + // Console.SetOut(output); + // + // // Run your minimal program + // Program.Main(new[] { testFilePath }); + // + // // Check results + // var result = output.ToString().Trim(); + // Assert.Equal("XLII\nXCIX", result); + // + // // Cleanup + // Console.SetOut(originalOut); + // File.Delete(testFilePath); + // } + + [Fact] + public void TestEndToEnd() + { + // Create test input file + // var inputPath = Path.Combine(Path.GetTempPath(), "test-input.txt"); + // File.WriteAllText(inputPath, "27\n238\n2019"); + var programPath = "C:\\source\\playground\\code_golf\\RomanNumbers_Tests\\bin\\Debug\\net9.0\\RomanNumbers.exe"; + var inputFilePath = "C:\\source\\playground\\code_golf\\RomanNumbers_Tests\\input.txt"; + var expectedOutputFilePath = "C:\\source\\playground\\code_golf\\RomanNumbers_Tests\\output.txt"; + + var expectedOutput = File.ReadAllText(expectedOutputFilePath); + var expectedOutputLines = expectedOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + // Build process to run your compiled app + var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = programPath, + Arguments = inputFilePath, + RedirectStandardOutput = true, + UseShellExecute = false + } + }; + + // Run and capture output + process.Start(); + var output = process.StandardOutput.ReadToEnd(); + var lines = output.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + Assert.NotEmpty(lines); + for (var i = 0; i < lines.Length; i++) + { + var line = lines[i]; + var expected = expectedOutputLines[i]; + Assert.Equal(expected, line); + } + + process.WaitForExit(); + + //Assert.Equal("XXVII\nCCXXXVIII\nMMXIX", output.Trim()); + //File.Delete(inputPath); + } +} \ No newline at end of file diff --git a/RomanNumbers_Tests/RomanNumbers_Tests.csproj b/RomanNumbers_Tests/RomanNumbers_Tests.csproj new file mode 100644 index 0000000..3913a46 --- /dev/null +++ b/RomanNumbers_Tests/RomanNumbers_Tests.csproj @@ -0,0 +1,18 @@ + + + + net9.0 + enable + enable + true + + + + + + + + + + + diff --git a/RomanNumbers_Tests/input.txt b/RomanNumbers_Tests/input.txt new file mode 100644 index 0000000..841c1f0 --- /dev/null +++ b/RomanNumbers_Tests/input.txt @@ -0,0 +1,23 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +20 +25 +31 +43 +50 +55 +60 +90 +104 +243 +401 +3277 diff --git a/RomanNumbers_Tests/output.txt b/RomanNumbers_Tests/output.txt new file mode 100644 index 0000000..359d4d8 --- /dev/null +++ b/RomanNumbers_Tests/output.txt @@ -0,0 +1,23 @@ +I +II +III +IV +V +VI +VII +VIII +VIIII +X +XI +XX +XXV +XXXI +XLIII +L +LV +LX +LXXXX +CIV +CCXLIII +CDI +MMMCCLXXVII \ No newline at end of file