releases/tests/Paca.Tests/Core/AdaptiveBufferScalerGateTests.cs

55 lines
1.8 KiB
C#

using System;
using Paca.Mobile.Core;
using Xunit;
namespace Paca.Tests.Core;
public class AdaptiveBufferScalerGateTests
{
[Fact]
public void Gate393_AdaptiveBufferScaler_SelectsGigabitUltra_ForHighThroughput()
{
// 80 MB/s
var speed = 80.0 * 1024 * 1024;
var profile = AdaptiveBufferScaler.GetAdaptationProfile(speed);
Assert.Equal(BufferScalingTier.GigabitUltra, profile.CurrentTier);
Assert.Equal(512 * 1024, profile.BufferSizeBytes);
Assert.Equal(20 * 1024 * 1024L, profile.RecommendedChunkSizeBytes);
}
[Fact]
public void Gate394_AdaptiveBufferScaler_SelectsMedium_ForModerateSpeed()
{
// 5 MB/s
var speed = 5.0 * 1024 * 1024;
var profile = AdaptiveBufferScaler.GetAdaptationProfile(speed);
Assert.Equal(BufferScalingTier.MediumBandwidth, profile.CurrentTier);
Assert.Equal(32 * 1024, profile.BufferSizeBytes);
Assert.Equal(5 * 1024 * 1024L, profile.RecommendedChunkSizeBytes);
}
[Fact]
public void Gate395_AdaptiveBufferScaler_SelectsLow_ForSlowConnections()
{
// 500 KB/s
var speed = 500.0 * 1024;
var profile = AdaptiveBufferScaler.GetAdaptationProfile(speed);
Assert.Equal(BufferScalingTier.LowBandwidth, profile.CurrentTier);
Assert.Equal(8 * 1024, profile.BufferSizeBytes);
Assert.Equal(1 * 1024 * 1024L, profile.RecommendedChunkSizeBytes);
}
[Fact]
public void Gate396_AdaptiveBufferScaler_SmoothsSpeed_WithExponentialMovingAverage()
{
var prevAvg = 10.0;
var newSample = 20.0;
// With alpha 0.3: 0.3 * 20 + 0.7 * 10 = 6 + 7 = 13.0
var smoothed = AdaptiveBufferScaler.SmoothSpeedEma(prevAvg, newSample, alpha: 0.3);
Assert.Equal(13.0, smoothed, 2);
}
}