using System; using System.Collections.Generic; using Paca.Mobile.Core; using Xunit; namespace Paca.Tests.Core; public class StorageQuotaEvictionPlannerGateTests { [Fact] public void Gate437_StorageQuotaEvictionPlanner_CalculatesRequiredSpace_Correctly() { // 5GB free, 8GB requested, 1GB headroom -> 4GB deficit long deficit = StorageQuotaEvictionPlanner.CalculateDeficit( freeSpaceBytes: 5L * 1024 * 1024 * 1024, requestedBytes: 8L * 1024 * 1024 * 1024, headroomBytes: 1L * 1024 * 1024 * 1024 ); Assert.Equal(4L * 1024 * 1024 * 1024, deficit); // 10GB free, 8GB requested, 1GB headroom -> 0 deficit long noDeficit = StorageQuotaEvictionPlanner.CalculateDeficit( freeSpaceBytes: 10L * 1024 * 1024 * 1024, requestedBytes: 8L * 1024 * 1024 * 1024, headroomBytes: 1L * 1024 * 1024 * 1024 ); Assert.Equal(0, noDeficit); } [Fact] public void Gate438_StorageQuotaEvictionPlanner_EvictsByLru_WhilePreservingPinned() { var now = DateTime.UtcNow; var candidates = new List { new("file1.mp4", 1000, now.AddDays(-10), IsPinned: true), // pinned! new("file2.mp4", 1000, now.AddDays(-5), IsPinned: false), new("file3.mp4", 1000, now.AddDays(-20), IsPinned: false), // oldest unpinned! new("file4.mp4", 1000, now.AddDays(-1), IsPinned: false) }; var plan = StorageQuotaEvictionPlanner.PlanEviction(candidates, deficitBytes: 1500, EvictionStrategy.LRU); Assert.True(plan.IsSatisfiable); Assert.Equal(2, plan.FilesToEvict.Count); Assert.Equal("file3.mp4", plan.FilesToEvict[0].FilePath); // oldest Assert.Equal("file2.mp4", plan.FilesToEvict[1].FilePath); // second oldest Assert.DoesNotContain(plan.FilesToEvict, f => f.FilePath == "file1.mp4"); // preserved! } [Fact] public void Gate439_StorageQuotaEvictionPlanner_EvictsByLargestFirst() { var now = DateTime.UtcNow; var candidates = new List { new("small.mp4", 500, now, false), new("huge.mp4", 3000, now, false), new("medium.mp4", 1000, now, false) }; var plan = StorageQuotaEvictionPlanner.PlanEviction(candidates, deficitBytes: 2500, EvictionStrategy.LargestFirst); Assert.True(plan.IsSatisfiable); Assert.Single(plan.FilesToEvict); Assert.Equal("huge.mp4", plan.FilesToEvict[0].FilePath); Assert.Equal(3000, plan.TotalFreedBytes); } [Fact] public void Gate440_StorageQuotaEvictionPlanner_DeterminesFeasibility() { var now = DateTime.UtcNow; var candidates = new List { new("file1.mp4", 1000, now, false) }; var plan = StorageQuotaEvictionPlanner.PlanEviction(candidates, deficitBytes: 5000, EvictionStrategy.LRU); Assert.False(plan.IsSatisfiable); Assert.Equal(1000, plan.TotalFreedBytes); } }