public void TestAdd() { var aggregations = new List <MutableAggregation>() { MutableSum.Create(), MutableCount.Create(), MutableMean.Create(), MutableDistribution.Create(BUCKET_BOUNDARIES), MutableLastValue.Create(), }; var values = new List <double>() { -1.0, 1.0, -5.0, 20.0, 5.0 }; foreach (var value in values) { foreach (var aggregation in aggregations) { aggregation.Add(value); } } foreach (var 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); } ); } }
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]); }
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); }
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); }
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); }
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); }
public void TestNullBucketBoundaries() { Assert.Throws <ArgumentNullException>(() => MutableDistribution.Create(null)); }