예제 #1
0
        public void DivideOp_2DividedBy8PerCent_Equals25()
        {
            double  expectedD = 25;
            double  expectedM = 25;
            Percent testValue = new Percent(8);

            Assert.AreEqual(expectedD, 2 / testValue, 0.0000000000001);
            Assert.AreEqual(expectedD, 2d / testValue, 0.000001);
            Assert.AreEqual(expectedM, 2m / testValue);
        }
예제 #2
0
        public void Parser()
        {
            CultureInfo culture = CultureInfo.CurrentCulture;
            string      dot     = culture.NumberFormat.PercentDecimalSeparator;

            Assert.AreEqual(new Percent(2.35), Percent.Parse($"2{dot}35%", culture));
            Assert.AreEqual(new Percent(20), Percent.Parse("20%", culture));

            Assert.Throws <FormatException>(() => Percent.Parse($"{dot}5%", culture));
            Assert.Throws <FormatException>(() => Percent.Parse($"7{dot}%", culture));
        }
예제 #3
0
        public static double InterpolateWith(this int start, double end, Percent percent)
        {
            double diff = end - start;

            return(start + diff * percent);
        }
예제 #4
0
 public void FromCoefficient_CoefficientLessThanOne_CreatesNegativePercent()
 {
     Assert.AreEqual(new Percent(-10), Percent.FromCoefficient(.9));
 }
예제 #5
0
 public void FromCoefficient_ConvertsCoefficientToPercentage()
 {
     Assert.AreEqual(new Percent(30), Percent.FromCoefficient(1.3));
 }