public void FromAmounts_CalculatesPercentage() { DecimalPercentage eightyPercent = DecimalPercentage.FromAmounts(60L, 75L); Assert.That(eightyPercent.Value, Is.EqualTo(80m)); Assert.That(eightyPercent.Fraction, Is.EqualTo(0.8m)); DecimalPercentage tenPercent = DecimalPercentage.FromAmounts(10m, 100m); Assert.That(tenPercent.Value, Is.EqualTo(10m)); Assert.That(tenPercent.Fraction, Is.EqualTo(0.1m)); DecimalPercentage thousandPercent = DecimalPercentage.FromAmounts(100m, 10m); Assert.That(thousandPercent.Value, Is.EqualTo(1000m)); Assert.That(thousandPercent.Fraction, Is.EqualTo(10m)); }
public static DecimalPercentage AsPercentOf(this decimal given, decimal total) { return(DecimalPercentage.FromAmounts(given, total)); }
public void FromAmount_ZeroTotal_Exception() { Assert.That(() => DecimalPercentage.FromAmounts(10, 0), Throws.ArgumentException); }