Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/.idea
**/bin
**/obj
**/.DS_Store
**/.vs
**/*.DotSettings.user

**.csproj.user

**.orig
22 changes: 22 additions & 0 deletions RomanNumbers.sln
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions RomanNumbers/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Global using directives

global using static System.Console;
global using static System.IO.File;
27 changes: 27 additions & 0 deletions RomanNumbers/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
}
22 changes: 22 additions & 0 deletions RomanNumbers/RomanNumbers.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Content Include="./input.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>RomanNumbers_Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions RomanNumbers/input.txt
Original file line number Diff line number Diff line change
@@ -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
75 changes: 75 additions & 0 deletions RomanNumbers_Tests/Program.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions RomanNumbers_Tests/RomanNumbers_Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\RomanNumbers\RomanNumbers.csproj" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions RomanNumbers_Tests/input.txt
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions RomanNumbers_Tests/output.txt
Original file line number Diff line number Diff line change
@@ -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