add compile & test worker

This commit is contained in:
prixod
2025-10-24 23:46:51 +04:00
parent 3d854c3470
commit 6cead15a5f
19 changed files with 849 additions and 13 deletions

View File

@@ -0,0 +1,54 @@
namespace LiquidCode.Tester.Worker.Services;
public class OutputCheckerService : IOutputCheckerService
{
private readonly ILogger<OutputCheckerService> _logger;
public OutputCheckerService(ILogger<OutputCheckerService> logger)
{
_logger = logger;
}
public async Task<bool> CheckOutputAsync(string actualOutput, string expectedOutputPath)
{
try
{
var expectedOutput = await File.ReadAllTextAsync(expectedOutputPath);
// Normalize outputs for comparison
var normalizedActual = NormalizeOutput(actualOutput);
var normalizedExpected = NormalizeOutput(expectedOutput);
var match = normalizedActual == normalizedExpected;
if (!match)
{
_logger.LogDebug("Output mismatch. Expected length: {ExpectedLength}, Actual length: {ActualLength}",
normalizedExpected.Length, normalizedActual.Length);
}
return match;
}
catch (Exception ex)
{
_logger.LogError(ex, "Error checking output against {ExpectedFile}", expectedOutputPath);
return false;
}
}
private string NormalizeOutput(string output)
{
// Remove trailing whitespace from each line and normalize line endings
var lines = output.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)
.Select(line => line.TrimEnd())
.ToList();
// Remove trailing empty lines
while (lines.Count > 0 && string.IsNullOrWhiteSpace(lines[^1]))
{
lines.RemoveAt(lines.Count - 1);
}
return string.Join("\n", lines);
}
}