private static Allocation allocateRemainderIfNeeded(this Money money, IRemainderAllocator allocator, Allocation allocatedSoFar) { Money remainder = money - allocatedSoFar.TotalAllocated; Allocation beingAllocated = allocatedSoFar; if (remainder >= remainder.MinValue) { beingAllocated = allocator.Allocate(allocatedSoFar); } return(beingAllocated); }
public static Allocation Allocate(this Money money, int numberOfRecipients, IRemainderAllocator allocator) { EvenAllocator.AssertNumberOfRecipients(nameof(numberOfRecipients), numberOfRecipients); if (money.notEnoughToAllocate()) { return(Allocation.Zero(money, numberOfRecipients)); } Allocation allocated = new EvenAllocator(money) .Allocate(numberOfRecipients); allocated = money.allocateRemainderIfNeeded(allocator, allocated); return(allocated); }
public static Allocation Allocate(this Money money, RatioCollection ratios, IRemainderAllocator allocator) { Guard.AgainstNullArgument(nameof(ratios), ratios); if (money.notEnoughToAllocate()) { return(Allocation.Zero(money, ratios.Count)); } Allocation allocated = new ProRataAllocator(money) .Allocate(ratios); allocated = money.allocateRemainderIfNeeded(allocator, allocated); return(allocated); }
public Allocation Allocate(int numberOfRecipients, IRemainderAllocator allocator) { EvenAllocator.AssertNumberOfRecipients(nameof(numberOfRecipients), numberOfRecipients); if (notEnoughToAllocate()) { return(Allocation.Zero(this, numberOfRecipients)); } Allocation allocated = new EvenAllocator(this) .Allocate(numberOfRecipients); allocated = allocateRemainderIfNeeded(allocator, allocated); return(allocated); }
public void Allocate_SingleAllocation_SameQuantity(IRemainderAllocator remainder) { Allocation allocated = 8.3m.Eur().Allocate(1, remainder); Assert.That(allocated, Is.EqualTo(new[] { 8.3m.Eur() })); }
public void Allocate_FairAllocation_EveryoneGetTheSameQuantity(IRemainderAllocator allocator) { Allocation allocated = 8m.Usd().Allocate(4, allocator); Assert.That(allocated, Is.EqualTo(new[] { 2m.Usd(), 2m.Usd(), 2m.Usd(), 2m.Usd() })); }