校历优化

This commit is contained in:
biss committed 2026-09-29 09:33:25 +08:00
1 parent 0ef0d4d399
commit 4ef4164b00
6 files changed
+196 -39

No files matched your search

@@ -1,6 +1,7 @@
using CaptchaKit.AspNetCore;
using CaptchaKit;
using Microsoft.Extensions.DependencyInjection;
using SkiaSharp;
namespace Jiaowu.Api.Tests;
@@ -34,6 +35,28 @@ public sealed class CaptchaKitIntegrationTests
Assert.True(challenge.Challenge.ImageBytes!.AsSpan().StartsWith(new byte[] { 137, 80, 78, 71 }));
}
[Fact]
public void Selection_visual_keeps_the_target_character_visible_above_noise()
{
var challenge = new SkiaTextCaptchaGenerator().CreateVisualChallenge(
new CaptchaGenerationRequest("test", DateTimeOffset.UtcNow.AddMinutes(1), 5),
"A", "choice-A", CaptchaChallengeType.Selection, "请选择对应字符");
using var bitmap = SKBitmap.Decode(challenge.Challenge.ImageBytes!);
Assert.NotNull(bitmap);
var targetPixelCount = 0;
for (var y = 0; y < bitmap!.Height; y++)
for (var x = bitmap.Width / 4; x < bitmap.Width * 3 / 4; x++)
{
var pixel = bitmap.GetPixel(x, y);
if (pixel.Red <= 30 && pixel.Green is >= 40 and <= 60 && pixel.Blue is >= 70 and <= 90)
targetPixelCount++;
}
Assert.True(targetPixelCount > 20, "The target character should be visibly rendered in the image center.");
}
[Fact]
public void Random_generator_produces_each_enabled_challenge_type()
{