public void TestSimpleAddition() { Money five = Money.Dollar(5); IMoneyExpression sum = five.Plus(five); Bank bank = new Bank(); Money reduced = bank.Reduce(sum, "USD"); Assert.Equal(Money.Dollar(10), reduced); }
public void TestPlusReturnsSum() { Money five = Money.Dollar(5); IMoneyExpression result = five.Plus(five); Sum sum = (Sum)result; Assert.Equal(five, sum.Augend); Assert.Equal(five, sum.Addend); }
public void TestMixedAddition() { IMoneyExpression fiveBucks = Money.Dollar(5); IMoneyExpression tenFrancs = Money.Franc(10); Bank bank = new Bank(); bank.AddRate("CHF", "USD", 2); Money result = bank.Reduce(fiveBucks.Plus(tenFrancs), "USD"); Assert.Equal(Money.Dollar(10), result); }
public void sum_of_two_franc_with_one_dollar__equals_to_two_dollar() // 2 CHF + 1 USD = 2 USD { IMoneyExpression franc = Money.Franc(2); IMoneyExpression dollar = Money.Dollar(1); var bank = new Bank(); bank.AddRate("USD", "CHF", 2); bank.AddRate("CHF", "USD", 0.5m); var reducedAmount = bank.Reduce(dollar.Plus(franc), "USD"); var expected = Money.Dollar(2); reducedAmount.Should().Be(expected); }
public void TestSumPlusMoney() { IMoneyExpression fiveBucks = Money.Dollar(5); IMoneyExpression tenFrancs = Money.Franc(10); Bank bank = new Bank(); bank.AddRate("CHF", "USD", 2); IMoneyExpression sum = new Sum(fiveBucks, tenFrancs).Plus(fiveBucks); Money result = bank.Reduce(sum, "USD"); Assert.Equal(Money.Dollar(15), result); }
public Money Reduce(IMoneyExpression expression, string toCurrency) { return(expression.Reduce(toCurrency, this)); }
private static Money Evaluate(IMoneyExpression moneyExpression, Func <Money, Money> round, Func <IMoneyExpression, Money> total) => round(total(moneyExpression));
public static IMoneyExpression Subtract(this IMoneyExpression minuend, IMoneyExpression subtrahend) => new MoneySum(minuend, new MoneyProduct(subtrahend, -1));
public IMoneyExpression Plus(IMoneyExpression addend) { return(new Sum(this, addend)); }
public static Money Evaluate(this IMoneyExpression moneyExpression, Option <MoneyEvaluationContext> context = default) => Evaluate(moneyExpression, Round(context), CalculateTotal(context));
public IMoneyExpression Plus(IMoneyExpression moneyExpression) { return(new Sum(this, moneyExpression)); }
public static IMoneyExpression Add(this IMoneyExpression augend, IMoneyExpression addend) => new MoneySum(augend, addend);
public static IEnumerable <IMoneyExpression> Distribute(this IMoneyExpression moneyExpression, int numberOfSlices, Option <decimal> precision = default) => moneyExpression.Distribute(Enumerable.Repeat(element: 1, count: numberOfSlices), precision);
public static IEnumerable <IMoneyExpression> Distribute(this IMoneyExpression moneyExpression, IEnumerable <int> factors, Option <decimal> precision = default) => new MoneyDistribution(moneyExpression, factors, precision);
public static IMoneyExpression Multiply(this IMoneyExpression multiplicand, decimal multiplier) => new MoneyProduct(multiplicand, multiplier);
public static IMoneyExpression Divide(this IMoneyExpression dividend, decimal divisor) => new MoneyProduct(dividend, 1.0m / divisor);
public static string ToHumanReadable(this IMoneyExpression moneyExpression) => moneyExpression.Accept(ToHumanReadableVisitor.Instance);
public Sum(IMoneyExpression augEnd, IMoneyExpression addEnd) { AugEnd = augEnd; AddEnd = addEnd; }
public Money Reduce(IMoneyExpression source, String to) { return(source.Reduce(this, to)); }