public void AverageAggregator_Merge() { var avgAggr1 = new AverageAggregator("test"); var avgAggr2 = new AverageAggregator("test"); var avgAggr3 = new AverageAggregator("test"); Func <object, string, object> getVal = (r, f) => { return(r); }; for (int i = 0; i < 10; i++) { avgAggr1.Push(i, getVal); avgAggr2.Push(i, getVal); avgAggr3.Push(i % 2 == 0 ? null : (object)i, getVal); } Assert.Equal(4.5M, Convert.ToDecimal(avgAggr1.Value)); avgAggr1.Merge(avgAggr2); Assert.Equal(4.5M, Convert.ToDecimal(avgAggr1.Value)); Assert.Equal(20, Convert.ToInt32(avgAggr1.Count)); avgAggr1.Merge(avgAggr3); Assert.Equal(4.6M, Convert.ToDecimal(avgAggr1.Value)); Assert.Equal(25, (int)avgAggr1.Count); }
public void AverageAggregator() { var avg = new AverageAggregator("test"); Assert.Equal(0M, Convert.ToDecimal(avg.Value)); Func <object, string, object> getVal = (r, f) => { Assert.Equal("test", f); return(r); }; for (int i = 0; i <= 10; i++) { avg.Push(i, getVal); } Assert.Equal(5M, avg.Value); avg.Push(String.Empty, getVal); Assert.Equal(5M, avg.Value); }