Ejemplo n.º 1
0
        public void TestAdd()
        {
            List <MutableAggregation> aggregations =
                new List <MutableAggregation>()
            {
                MutableSum.Create(),
                                      MutableCount.Create(),
                                      MutableMean.Create(),
                                      MutableDistribution.Create(BUCKET_BOUNDARIES),
                MutableLastValue.Create(),
            };

            List <double> values = new List <double>()
            {
                -1.0, 1.0, -5.0, 20.0, 5.0
            };

            foreach (double value in values)
            {
                foreach (MutableAggregation aggregation in aggregations)
                {
                    aggregation.Add(value);
                }
            }

            foreach (MutableAggregation aggregation in aggregations)
            {
                aggregation.Match <object>(
                    (arg) =>
                {
                    Assert.InRange(arg.Sum, 20.0 - TOLERANCE, 20.0 + TOLERANCE);
                    return(null);
                },
                    (arg) =>

                {
                    Assert.Equal(5, arg.Count);
                    return(null);
                },
                    (arg) =>

                {
                    Assert.InRange(arg.Mean, 4.0 - TOLERANCE, 4.0 + TOLERANCE);
                    Assert.InRange(arg.Max, 20.0 - TOLERANCE, 20 + TOLERANCE);
                    Assert.InRange(arg.Min, -5.0 - TOLERANCE, -5.0 + TOLERANCE);
                    return(null);
                },
                    (arg) =>
                {
                    Assert.Equal(new long[] { 0, 2, 2, 1 }, arg.BucketCounts);
                    return(null);
                },
                    (arg) =>
                {
                    Assert.InRange(arg.LastValue, 5.0 - TOLERANCE, 5.0 + TOLERANCE);
                    return(null);
                }
                    );
            }
        }
Ejemplo n.º 2
0
        public void TestCombine_SumCountMean()
        {
            // combine() for Mutable Sum, Count and Mean will pick up fractional stats
            List <MutableAggregation> aggregations1 =
                new List <MutableAggregation>()
            {
                MutableSum.Create(), MutableCount.Create(), MutableMean.Create()
            };
            List <MutableAggregation> aggregations2 =
                new List <MutableAggregation>()
            {
                MutableSum.Create(), MutableCount.Create(), MutableMean.Create()
            };

            foreach (double val in new List <double>()
            {
                -1.0, -5.0
            })
            {
                foreach (MutableAggregation aggregation in aggregations1)
                {
                    aggregation.Add(val);
                }
            }

            foreach (double val in new List <double>()
            {
                10.0, 50.0
            })
            {
                foreach (MutableAggregation aggregation in aggregations2)
                {
                    aggregation.Add(val);
                }
            }

            List <MutableAggregation> combined =
                new List <MutableAggregation>()
            {
                MutableSum.Create(), MutableCount.Create(), MutableMean.Create()
            };
            double fraction1 = 1.0;
            double fraction2 = 0.6;

            for (int i = 0; i < combined.Count; i++)
            {
                combined[i].Combine(aggregations1[i], fraction1);
                combined[i].Combine(aggregations2[i], fraction2);
            }

            Assert.InRange(((MutableSum)combined[0]).Sum, 30 - TOLERANCE, 30 + TOLERANCE);
            Assert.Equal(3, ((MutableCount)combined[1]).Count);
            Assert.InRange(((MutableMean)combined[2]).Mean, 10 - TOLERANCE, 10 + TOLERANCE);
        }
Ejemplo n.º 3
0
        public void TestMatch()
        {
            List <MutableAggregation> aggregations =
                new List <MutableAggregation>()
            {
                MutableSum.Create(),
                                      MutableCount.Create(),
                                      MutableMean.Create(),
                                      MutableDistribution.Create(BUCKET_BOUNDARIES),
                MutableLastValue.Create(),
            };

            List <String> actual = new List <String>();

            foreach (MutableAggregation aggregation in aggregations)
            {
                actual.Add(
                    aggregation.Match(
                        (arg) =>
                {
                    return("SUM");
                },
                        (arg) =>

                {
                    return("COUNT");
                },
                        (arg) =>
                {
                    return("MEAN");
                },
                        (arg) =>
                {
                    return("DISTRIBUTION");
                },
                        (arg) =>
                {
                    return("LASTVALUE");
                }
                        )
                    );
            }

            Assert.Equal(new List <string>()
            {
                "SUM", "COUNT", "MEAN", "DISTRIBUTION", "LASTVALUE"
            }, actual);
        }
Ejemplo n.º 4
0
        public void CreateAggregationData()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 0.0, 1.0
            });
            List <MutableAggregation> mutableAggregations =
                new List <MutableAggregation>()
            {
                MutableCount.Create(),
                                      MutableMean.Create(),
                                      MutableDistribution.Create(bucketBoundaries)
            };
            List <IAggregationData> aggregates = new List <IAggregationData>
            {
                MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_DOUBLE),
                MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_LONG),
                MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_DOUBLE),
                MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_LONG)
            };

            foreach (MutableAggregation mutableAggregation in mutableAggregations)
            {
                aggregates.Add(MutableViewData.CreateAggregationData(mutableAggregation, MEASURE_DOUBLE));
            }

            List <IAggregationData> expected = new List <IAggregationData>()
            {
                SumDataDouble.Create(0),
                SumDataLong.Create(0),
                LastValueDataDouble.Create(double.NaN),
                LastValueDataLong.Create(0),
                CountData.Create(0),
                MeanData.Create(0, 0, double.MaxValue, double.MinValue),
                DistributionData.Create(
                    0,
                    0,
                    double.PositiveInfinity,
                    double.NegativeInfinity,
                    0,
                    new List <long>()
                {
                    0L, 0L, 0L, 0L
                })
            };

            Assert.Equal(expected, aggregates);
        }
Ejemplo n.º 5
0
        public void TestCreateEmpty()
        {
            Assert.InRange(MutableSum.Create().Sum, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.Equal(0, MutableCount.Create().Count);
            Assert.InRange(MutableMean.Create().Mean, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.True(Double.IsNaN(MutableLastValue.Create().LastValue));

            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                0.1, 2.2, 33.3
            });
            MutableDistribution mutableDistribution = MutableDistribution.Create(bucketBoundaries);

            Assert.InRange(mutableDistribution.Mean, 0, TOLERANCE);
            Assert.Equal(0, mutableDistribution.Count);
            Assert.Equal(double.PositiveInfinity, mutableDistribution.Min);
            Assert.Equal(double.NegativeInfinity, mutableDistribution.Max);
            Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0 - TOLERANCE, 0 + TOLERANCE);
            Assert.Equal(new long[4], mutableDistribution.BucketCounts);
        }