Files
Heimdall/tests/Heimdall.Infrastructure.Tests/PlateOcrTests.cs
T
arnaud.dartois 3208bc93fe
Heimdall Gitea / Detect CI scope (pull_request) Successful in 1m27s
Heimdall Gitea / Build and tests (pull_request) Failing after 12m27s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 4s
feat: complete local camera and operations acceptance
2026-11-05 11:02:41 +01:00

45 lines
1.5 KiB
C#

using Heimdall.Infrastructure.Services;
using Shouldly;
using Xunit;
namespace Heimdall.Infrastructure.Tests;
public sealed class PlateOcrTests
{
[Fact]
public void Parses_synthetic_tsv_word_and_confidence()
{
const string fixture = "level\tpage_num\tblock_num\tpar_num\tline_num\tword_num\tleft\ttop\twidth\theight\tconf\ttext\n" +
"5\t1\t1\t1\t1\t1\t0\t0\t100\t30\t92.5\tAB-123-CD\n";
var result = TesseractPlateOcr.ParseTsv(fixture);
result.ShouldNotBeNull();
result!.Text.ShouldBe("AB-123-CD");
result.Confidence.ShouldBe(0.925);
}
[Fact]
public void Rejects_empty_or_unconfident_tsv_rows()
{
var result = TesseractPlateOcr.ParseTsv("header\n5\t1\t1\t1\t1\t1\t0\t0\t1\t1\t-1\t");
result.ShouldBeNull();
}
[Fact]
public void OCR_options_are_bounded_when_enabled()
{
new PlateOcrOptions { Enabled = true, MaxImageBytes = 128 }.IsValid().ShouldBeFalse();
new PlateOcrOptions { Enabled = true, TimeoutSeconds = 100 }.IsValid().ShouldBeFalse();
new PlateOcrOptions { Enabled = false, MaxImageBytes = 0 }.IsValid().ShouldBeTrue();
}
[Fact]
public void Accepts_bounded_synthetic_plate_crop_and_rejects_invalid_bytes()
{
var fixture = File.ReadAllBytes(Path.Combine(AppContext.BaseDirectory, "Fixtures", "synthetic-plate.png"));
TesseractPlateOcr.IsSafeImage(fixture).ShouldBeTrue();
TesseractPlateOcr.IsSafeImage(new byte[32]).ShouldBeFalse();
}
}