public void FromFraction_SetsValueAndFraction() { DecimalPercentage sixtyPercent = DecimalPercentage.FromFraction(.6m); Assert.That(sixtyPercent.Value, Is.EqualTo(60m)); Assert.That(sixtyPercent.Fraction, Is.EqualTo(.6m)); }
public void Ctor_SetsValueAndFraction() { var sixtyPercent = new DecimalPercentage(60m); Assert.That(sixtyPercent.Value, Is.EqualTo(60m)); Assert.That(sixtyPercent.Fraction, Is.EqualTo(.6m)); }
public void Apply_AppliesThePercentageToTheAmountGiven() { var fiftyPercent = new DecimalPercentage(50); Assert.That(fiftyPercent.Apply(100L), Is.EqualTo(50m)); Assert.That(fiftyPercent.Apply(100m), Is.EqualTo(50m)); }
public void FromDifference_TotalSmaller_NegativePercentage() { DecimalPercentage twiceAsSmall = DecimalPercentage.FromDifference(10L, 20L); Assert.That(twiceAsSmall.Value, Is.EqualTo(-100m)); twiceAsSmall = DecimalPercentage.FromDifference(10m, 20m); Assert.That(twiceAsSmall.Value, Is.EqualTo(-100d)); }
public void FromDifference_TotalBigger_PositivePercentage() { DecimalPercentage fiftyPercentBigger = DecimalPercentage.FromDifference(20L, 10L); Assert.That(fiftyPercentBigger.Value, Is.EqualTo(50m)); fiftyPercentBigger = DecimalPercentage.FromDifference(20m, 10m); Assert.That(fiftyPercentBigger.Value, Is.EqualTo(50d)); }
public void FromDifference_ZeroTotal_HundredPercent() { DecimalPercentage hundredPercentMore = DecimalPercentage.FromDifference(15, 0); Assert.That(hundredPercentMore.Value, Is.EqualTo(100m)); Assert.That(hundredPercentMore.Fraction, Is.EqualTo(1m)); hundredPercentMore = DecimalPercentage.FromDifference(long.MaxValue, 0); Assert.That(hundredPercentMore.Value, Is.EqualTo(100d)); Assert.That(hundredPercentMore.Fraction, Is.EqualTo(1d)); }
public void ExtensionMethods_LikeConstructionCounterParts() { DecimalPercentage sixtyPercent = 60m.Percent(); Assert.That(sixtyPercent.Value, Is.EqualTo(60m)); Assert.That(sixtyPercent.Fraction, Is.EqualTo(.6m)); DecimalPercentage tenPercent = 10m.AsPercentOf(100m); Assert.That(tenPercent.Value, Is.EqualTo(10m)); Assert.That(tenPercent.Fraction, Is.EqualTo(0.1m)); }
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); }