校历优化

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()
{
@@ -0,0 +1,48 @@
using Jiaowu.Api.Infrastructure.AcademicCalendar;
namespace Jiaowu.Api.Tests;
public sealed class HolidayCnRangesTests
{
[Fact]
public void Group_merges_only_consecutive_days_with_the_same_name_and_status()
{
var ranges = HolidayCnRanges.Group(
[
new HolidayCnDay("国庆节", new DateOnly(2026, 10, 1), true),
new HolidayCnDay("国庆节", new DateOnly(2026, 10, 2), true),
new HolidayCnDay("国庆节", new DateOnly(2026, 10, 3), true),
new HolidayCnDay("国庆节", new DateOnly(2026, 10, 4), false),
new HolidayCnDay("国庆节", new DateOnly(2026, 10, 5), true),
new HolidayCnDay("国庆节", new DateOnly(2026, 10, 7), true)
]);
Assert.Collection(
ranges,
range =>
{
Assert.Equal("国庆节", range.Name);
Assert.Equal(new DateOnly(2026, 10, 1), range.StartsOn);
Assert.Equal(new DateOnly(2026, 10, 3), range.EndsOn);
Assert.True(range.IsOffDay);
},
range =>
{
Assert.Equal(new DateOnly(2026, 10, 4), range.StartsOn);
Assert.Equal(range.StartsOn, range.EndsOn);
Assert.False(range.IsOffDay);
},
range =>
{
Assert.Equal(new DateOnly(2026, 10, 5), range.StartsOn);
Assert.Equal(range.StartsOn, range.EndsOn);
Assert.True(range.IsOffDay);
},
range =>
{
Assert.Equal(new DateOnly(2026, 10, 7), range.StartsOn);
Assert.Equal(range.StartsOn, range.EndsOn);
Assert.True(range.IsOffDay);
});
}
}