Beispiel #1
0
        public void DecimalArithmetics()
        {
            var theAdd      = Arithmetics.CreateAddOperation <decimal>();
            var theSubtract = Arithmetics.CreateSubtractOperation <decimal>();
            var theMultiply = Arithmetics.CreateMultiplyOperation <decimal>();
            var theDivide   = Arithmetics.CreateDivideOperation <decimal>();
            var theNegate   = Arithmetics.CreateNegateOperation <decimal>();
            var theRound    = Arithmetics.CreateRoundOperation <decimal>();

            Assert.That(Arithmetics.GetZeroValue <decimal>(), Is.EqualTo(0.0m));
            Assert.That(Arithmetics.GetOneValue <decimal>(), Is.EqualTo(1.0m));
            Assert.That(Arithmetics.GetMinValue <decimal>(), Is.EqualTo(decimal.MinValue));
            Assert.That(Arithmetics.GetMaxValue <decimal>(), Is.EqualTo(decimal.MaxValue));
            Assert.That(theAdd(0.3m, 0.8m), Is.EqualTo(1.1m));
            Assert.That(theAdd(9.378m, 1.765m), Is.EqualTo(11.143m));
            Assert.That(theSubtract(11.143m, 9.378m), Is.EqualTo(1.765m));
            Assert.That(theSubtract(1.1m, 0.8m), Is.EqualTo(0.3m));
            Assert.That(theMultiply(5.0m, 0.25m), Is.EqualTo(1.25m));
            Assert.That(theMultiply(3.33m, 3.0m), Is.EqualTo(9.99m));
            Assert.That(theDivide(9.99m, 3.0m), Is.EqualTo(3.33m));
            Assert.That(theDivide(1.25m, 0.25m), Is.EqualTo(5.0m));
            Assert.That(theNegate(3.456m), Is.EqualTo(-3.456m));
            Assert.That(theNegate(-0.08m), Is.EqualTo(0.08m));
            Assert.That(theRound(2.3456m, 2, MidpointRounding.AwayFromZero), Is.EqualTo(2.35m));

            decimal?theNullableDecimal = 9.876m;
            var     theNullableRound   = Arithmetics.CreateRoundOperation <decimal?>();

            Assert.That(theNullableRound(theNullableDecimal, 2, MidpointRounding.AwayFromZero), Is.EqualTo(9.88m));
            Assert.That(theNullableRound(null, 2, MidpointRounding.AwayFromZero), Is.EqualTo(null));
        }
Beispiel #2
0
 public void Exceptions()
 {
     Assert.Throws <InvalidOperationException>(() => Arithmetics.GetMinValue <string>());
     Assert.Throws <InvalidOperationException>(() => Arithmetics.GetMaxValue <string>());
 }