Example #1
0
        /// <inheritdoc />
        public bool ApproximatelyEqual <TValue, TDifference>(TValue left, TValue right, TDifference delta)
        {
            SubtractionFunc <TValue, TDifference> subtractionFunc = GetSubtractionFunc <TValue, TDifference>();
            int         discriminator = Compare(left, right);
            TDifference difference    = discriminator < 0 ? subtractionFunc(right, left) : subtractionFunc(left, right);

            return(Compare(difference, delta) <= 0);
        }
Example #2
0
        public void GetSubtractionFunc_DateTime()
        {
            SubtractionFunc <DateTime, TimeSpan> differencer = comparisonSemantics.GetSubtractionFunc <DateTime, TimeSpan>();

            Assert.AreEqual(new TimeSpan(-1, 0, 0, 0), differencer(new DateTime(2008, 03, 14), new DateTime(2008, 03, 15)));
        }
Example #3
0
        public void GetSubtractionFunc_Double()
        {
            SubtractionFunc <double, double> differencer = comparisonSemantics.GetSubtractionFunc <double, double>();

            Assert.AreEqual(1.5, differencer(3.5, 2.0));
        }
Example #4
0
 private void AddPrimitiveDifferencer <T, D>(SubtractionFunc <T, D> subtractionFunc)
 {
     primitiveSubtractionFuncs.Add(typeof(T), new Pair <Type, Delegate>(typeof(D), subtractionFunc));
 }