コード例 #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);
                }
                    );
            }
        }
コード例 #2
0
        public void TestNoBoundaries()
        {
            List <Double>       buckets      = new List <double>();
            MutableDistribution noBoundaries = MutableDistribution.Create(BucketBoundaries.Create(buckets));

            Assert.Single(noBoundaries.BucketCounts);
            Assert.Equal(0, noBoundaries.BucketCounts[0]);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #5
0
 private static void VerifyMutableDistribution(
     MutableDistribution mutableDistribution,
     double mean,
     long count,
     double min,
     double max,
     double sumOfSquaredDeviations,
     long[] bucketCounts,
     double tolerance)
 {
     Assert.InRange(mutableDistribution.Mean, mean - tolerance, mean + tolerance);
     Assert.Equal(count, mutableDistribution.Count);
     Assert.InRange(mutableDistribution.Min, min - tolerance, min + tolerance);
     Assert.InRange(mutableDistribution.Max, max - tolerance, max + tolerance);
     Assert.InRange(mutableDistribution.SumOfSquaredDeviations, sumOfSquaredDeviations - tolerance, sumOfSquaredDeviations + tolerance);
     Assert.Equal(bucketCounts, mutableDistribution.BucketCounts);
 }
コード例 #6
0
        public void TestCombine_Distribution()
        {
            // combine() for Mutable Distribution will ignore fractional stats
            MutableDistribution distribution1 = MutableDistribution.Create(BUCKET_BOUNDARIES);
            MutableDistribution distribution2 = MutableDistribution.Create(BUCKET_BOUNDARIES);
            MutableDistribution distribution3 = MutableDistribution.Create(BUCKET_BOUNDARIES);

            foreach (double val in new List <double>()
            {
                5.0, -5.0
            })
            {
                distribution1.Add(val);
            }

            foreach (double val in new List <double>()
            {
                10.0, 20.0
            })
            {
                distribution2.Add(val);
            }

            foreach (double val in new List <double>()
            {
                -10.0, 15.0, -15.0, -20.0
            })
            {
                distribution3.Add(val);
            }

            MutableDistribution combined = MutableDistribution.Create(BUCKET_BOUNDARIES);

            combined.Combine(distribution1, 1.0); // distribution1 will be combined
            combined.Combine(distribution2, 0.6); // distribution2 will be ignored
            VerifyMutableDistribution(combined, 0, 2, -5, 5, 50.0, new long[] { 0, 1, 1, 0 }, TOLERANCE);

            combined.Combine(distribution2, 1.0); // distribution2 will be combined
            VerifyMutableDistribution(combined, 7.5, 4, -5, 20, 325.0, new long[] { 0, 1, 1, 2 }, TOLERANCE);

            combined.Combine(distribution3, 1.0); // distribution3 will be combined
            VerifyMutableDistribution(combined, 0, 8, -20, 20, 1500.0, new long[] { 2, 2, 1, 3 }, TOLERANCE);
        }
コード例 #7
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);
        }
コード例 #8
0
        public void CreateMutableAggregation()
        {
            IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>()
            {
                -1.0, 0.0, 1.0
            });

            Assert.InRange(((MutableSum)MutableViewData.CreateMutableAggregation(Sum.Create())).Sum, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.Equal(0, ((MutableCount)MutableViewData.CreateMutableAggregation(Count.Create())).Count);
            Assert.InRange(((MutableMean)MutableViewData.CreateMutableAggregation(Mean.Create())).Mean, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.True(Double.IsNaN(((MutableLastValue)MutableViewData.CreateMutableAggregation(LastValue.Create())).LastValue));

            MutableDistribution mutableDistribution =
                (MutableDistribution)MutableViewData.CreateMutableAggregation(Distribution.Create(bucketBoundaries));

            Assert.Equal(double.PositiveInfinity, mutableDistribution.Min);
            Assert.Equal(double.NegativeInfinity, mutableDistribution.Max);
            Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0.0 - EPSILON, 0.0 + EPSILON);
            Assert.Equal(new long[4], mutableDistribution.BucketCounts);
        }
コード例 #9
0
 public void TestNullBucketBoundaries()
 {
     Assert.Throws <ArgumentNullException>(() => MutableDistribution.Create(null));
 }