50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
|
|
using TeamUp.Modules.Skills.Domain;
|
||
|
|
using TeamUp.Modules.Skills.Eval;
|
||
|
|
using Xunit;
|
||
|
|
|
||
|
|
namespace TeamUp.IntegrationTests;
|
||
|
|
|
||
|
|
/// <summary>Unit coverage for the eval harness (no database). Uses a stub executor for the model.</summary>
|
||
|
|
public sealed class SkillEvaluatorTests
|
||
|
|
{
|
||
|
|
private sealed class StubExecutor(Func<string, string> respond) : ISkillExecutor
|
||
|
|
{
|
||
|
|
public Task<string> ExecuteAsync(string skillBody, string input, CancellationToken cancellationToken = default) =>
|
||
|
|
Task.FromResult(respond(input));
|
||
|
|
}
|
||
|
|
|
||
|
|
private static List<GoldenExample> Golden(string input, string expected) =>
|
||
|
|
[new GoldenExample { Input = input, Expected = expected }];
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Passes_when_output_matches_expected()
|
||
|
|
{
|
||
|
|
var report = await new SkillEvaluator().EvaluateAsync(
|
||
|
|
Golden("anything", "a clear logout button in the header"),
|
||
|
|
"body",
|
||
|
|
new StubExecutor(_ => "a clear logout button in the header"));
|
||
|
|
|
||
|
|
Assert.True(report.Passed);
|
||
|
|
Assert.Equal(0d, report.WorstDistance, precision: 3);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Fails_when_output_diverges()
|
||
|
|
{
|
||
|
|
var report = await new SkillEvaluator().EvaluateAsync(
|
||
|
|
Golden("anything", "a clear logout button in the header"),
|
||
|
|
"body",
|
||
|
|
new StubExecutor(_ => "something completely unrelated and very different indeed"));
|
||
|
|
|
||
|
|
Assert.False(report.Passed);
|
||
|
|
Assert.True(report.WorstDistance > 0.34);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Fails_when_there_are_no_golden_tests()
|
||
|
|
{
|
||
|
|
var report = await new SkillEvaluator().EvaluateAsync([], "body", new StubExecutor(_ => "x"));
|
||
|
|
Assert.False(report.Passed);
|
||
|
|
}
|
||
|
|
}
|