|
using System;
using Xunit;
namespace System.Tests
{
public class MoneyDistributorTests
{
[Fact]
public void UniformDistributionMustBeBetween0And1()
{
var distributor = new MoneyDistributor(1.0M, FractionReceivers.LastToFirst, RoundingPlaces.Two);
Assert.Throws<ArgumentOutOfRangeException>(() => distributor.Distribute(0));
Assert.Throws<ArgumentOutOfRangeException>(() => distributor.Distribute(1.1M));
}
[Fact]
public void DistributeUniformRatioToLastIsCorrect()
{
Money amountToDistribute = 0.05M;
// two decimal places
var distributor = new MoneyDistributor(amountToDistribute, FractionReceivers.LastToFirst, RoundingPlaces.Two);
var distribution = distributor.Distribute(0.3M);
Assert.Equal(3, distribution.Length);
Assert.Equal(new Money(0.01M), distribution[0]);
Assert.Equal(new Money(0.02M), distribution[1]);
Assert.Equal(new Money(0.02M), distribution[2]);
// seven decimal places
distributor = new MoneyDistributor(amountToDistribute,
FractionReceivers.LastToFirst,
RoundingPlaces.Seven);
distribution = distributor.Distribute(0.3M);
Assert.Equal(3, distribution.Length);
Assert.Equal(new Money(0.0166666M), distribution[0]);
Assert.Equal(new Money(0.0166667M), distribution[1]);
Assert.Equal(new Money(0.0166667M), distribution[2]);
}
[Fact(Skip = "Still not implemented")]
public void DistributeNonuniformRatiosToLastIsCorrect()
{
Money amountToDistribute = 0.05M;
var distributor = new MoneyDistributor(amountToDistribute, FractionReceivers.LastToFirst, RoundingPlaces.Two);
var distribution = distributor.Distribute(0.7M, 0.3M);
Assert.Equal(2, distribution.Length);
Assert.Equal(0.03, distribution[0]);
Assert.Equal(0.02, distribution[1]);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a software engineer with 25 years of experience in areas from game and simulation development, enterprise development, systems management, machine learning, real-time and embedded systems development and geospaitial systems development.
You can find more of my work at http://www.codeplex.com and my articles at http://vectordotnet.blogspot.com/ and http://dotnoted.spaces.live.com.