public void IntegerAverageOnTwoTuple()
 {
     var sut = new Tuple<int, int>(1, 2);
       double expected = sut.AsEnumerable().Cast<int>().Average();
       double actual = sut.Average(x => (int) x);
       Assert.AreEqual(expected, actual);
 }
 public void DoubleAverageOnTwoTuple()
 {
     var sut = new Tuple<double, double>(1, 2);
       double expected = sut.AsEnumerable().Cast<double>().Average();
       double actual = sut.Average(x => (double) x);
       Assert.AreEqual(expected, actual);
 }
 public void ShortAverageOnTwoTuple()
 {
     var sut = new Tuple<short, short>(1, 2);
       double expected = sut.AsEnumerable().Cast<short>().Average();
       double actual = sut.Average(x => (short) x);
       Assert.AreEqual(expected, actual);
 }
 public void DecimalAverageOnTwoTuple()
 {
     var sut = new Tuple<decimal, decimal>(1, 2);
       decimal expected = sut.AsEnumerable().Cast<decimal>().Average();
       decimal actual = sut.Average(x => (decimal) x);
       Assert.AreEqual(expected, actual);
 }
 public void LongAverageOnTwoTuple()
 {
     var sut = new Tuple<long, long>(1, 2);
       double expected = sut.AsEnumerable().Cast<long>().Average();
       double actual = sut.Average(x => (long) x);
       Assert.AreEqual(expected, actual);
 }
Example #6
0
        public static double Avg(Tuple<double, double>[] weightedValues)
        {
            if (weightedValues == null || weightedValues.Length == 0)
            {
                return 0;
            }

            double totalWeight = weightedValues.Sum(o => o.Item2);
            if (Math1D.IsNearZero(totalWeight))
            {
                return weightedValues.Average(o => o.Item1);
            }

            double sum = weightedValues.Sum(o => o.Item1 * o.Item2);

            return sum / totalWeight;
        }