public static decimal AccumulateCompoundInterest <TSource>(this IEnumerable <TSource> source, Func <TSource, decimal> selector) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (selector == null) { throw new ArgumentNullException(nameof(selector)); } decimal cumulativePercentage = 0M; checked { foreach (TSource item in source) { cumulativePercentage = cumulativePercentage.AccumulateCompoundInterest(selector(item)); } } return(cumulativePercentage); }
public void AccumulateCompoundInterest_ScalarToScalar_Decimal_GivenCumulativeInterestAndCurrentInterest_NewCumulativeInterestReturned(decimal currentInterest, decimal cumulativeInterest, decimal resultExpected) { cumulativeInterest.AccumulateCompoundInterest(currentInterest).Should().Be(resultExpected); }