public void TestPropertyAggregations()
        {
            // only Snapshot and Count are supported for properties
            Aggregation.Kinds[] aggrKindsProperties =
            {
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Snapshot
            };

            FieldAggregationConfig fieldAggrConfig = new FieldAggregationConfig(
                new Field("prop", Field.Kind.Property),
                aggrKindsProperties);

            FieldAggregator fieldAggr = new FieldAggregator(fieldAggrConfig);

            for (int i = 0; i < 20; i++)
            {
                fieldAggr.Aggregate(string.Format("property-{0}", i));
            }

            fieldAggr.Aggregate("lastValue");

            Assert.AreEqual("lastValue", fieldAggr.PropertySnapshot);
            Assert.AreEqual(21, fieldAggr.Count);
        }
        public void TestMetricClear()
        {
            // metric aggregation types
            Aggregation.Kinds[] aggrKindsMetric =
            {
                Aggregation.Kinds.Average,
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Maximum,
                Aggregation.Kinds.Minimum,
                Aggregation.Kinds.Snapshot,
                Aggregation.Kinds.Sum,
                Aggregation.Kinds.Variance
            };

            // only Snapshot and Count are supported for properties
            Aggregation.Kinds[] aggrKindsProperties =
            {
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Snapshot
            };

            FieldAggregationConfig fieldAggrConfig = new FieldAggregationConfig(
                new Field("metric", Field.Kind.Metric),
                aggrKindsMetric);

            FieldAggregator fieldAggr = new FieldAggregator(fieldAggrConfig);

            // test - variance
            for (int i = 0; i <= 10; i++)
            {
                double val = -50.0 + i;
                fieldAggr.Aggregate(val);
            }

            // cleaning aggregations
            fieldAggr.Clear();

            Assert.AreEqual(double.NegativeInfinity, fieldAggr.Snapshot);
            Assert.AreEqual(0.0, fieldAggr.Count);
            Assert.AreEqual(double.PositiveInfinity, fieldAggr.Minimum);
            Assert.AreEqual(double.NegativeInfinity, fieldAggr.Maximum);
            Assert.AreEqual(double.NaN, fieldAggr.Average);
            Assert.AreEqual(0.0, fieldAggr.Sum);
            Assert.AreEqual(double.NaN, fieldAggr.Variance);

            // testing whether aggregating again doesn't fail after clearing
            for (int i = 0; i <= 100; i++)
            {
                double val = 10.0;
                fieldAggr.Aggregate(val);
            }

            Assert.AreEqual(10.0, fieldAggr.Snapshot);
            Assert.AreEqual(101.0, fieldAggr.Count);
            Assert.AreEqual(10.0, fieldAggr.Minimum);
            Assert.AreEqual(10.0, fieldAggr.Maximum);
            Assert.AreEqual(10.0, fieldAggr.Average);
            Assert.AreEqual(1010.0, fieldAggr.Sum);
            Assert.AreEqual(0.0, fieldAggr.Variance);
        }
        public void TestPropertyCleanInitialization()
        {
            // metric aggregation types
            Aggregation.Kinds[] aggrKindsProperty =
            {
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Snapshot
            };

            // only Snapshot and Count are supported for properties
            Aggregation.Kinds[] aggrKindsProperties =
            {
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Snapshot
            };

            FieldAggregationConfig fieldAggrConfig = new FieldAggregationConfig(
                new Field("prop", Field.Kind.Metric),
                aggrKindsProperty);

            FieldAggregator fieldAggr = new FieldAggregator(fieldAggrConfig);

            Assert.AreEqual(null, fieldAggr.PropertySnapshot);
            Assert.AreEqual(0.0, fieldAggr.Count);
        }
        public void TestMetricCleanInitialization()
        {
            // metric aggregation types
            Aggregation.Kinds[] aggrKindsMetric =
            {
                Aggregation.Kinds.Average,
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Maximum,
                Aggregation.Kinds.Minimum,
                Aggregation.Kinds.Snapshot,
                Aggregation.Kinds.Sum,
                Aggregation.Kinds.Variance
            };

            // only Snapshot and Count are supported for properties
            Aggregation.Kinds[] aggrKindsProperties =
            {
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Snapshot
            };

            FieldAggregationConfig fieldAggrConfig = new FieldAggregationConfig(
                new Field("metric", Field.Kind.Metric),
                aggrKindsMetric);

            FieldAggregator fieldAggr = new FieldAggregator(fieldAggrConfig);

            Assert.AreEqual(double.NegativeInfinity, fieldAggr.Snapshot);
            Assert.AreEqual(0.0, fieldAggr.Count);
            Assert.AreEqual(double.PositiveInfinity, fieldAggr.Minimum);
            Assert.AreEqual(double.NegativeInfinity, fieldAggr.Maximum);
            Assert.AreEqual(double.NaN, fieldAggr.Average);
            Assert.AreEqual(0.0, fieldAggr.Sum);
            Assert.AreEqual(double.NaN, fieldAggr.Variance);
        }
Example #5
0
        public virtual void Dispose()
        {
            for (int i = 0; i < grippers.Length; i++)
            {
                grippers[i].Dispose();
            }

            FieldAggregator aggProps = parent.FieldAggregator;

            aggProps.UnbindElement(this);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (grippers != null)
                {
                    for (int i = 0; i < grippers.Length; i++)
                    {
                        if (grippers[i] != null)
                        {
                            grippers[i].Dispose();
                            grippers[i] = null;
                        }
                    }
                    grippers = null;
                }

                FieldAggregator aggProps = parent.FieldAggregator;
                aggProps.UnbindElement(this);
            }
        }
        public void Test()
        {
            FieldType t = FieldType.LINE_THICKNESS;

            Surface         s  = new Surface();
            FieldAggregator ep = new FieldAggregator();
            //ep.SetFieldValue(t,598);

            RectangleContainer rc = new RectangleContainer(s);

            rc.SetFieldValue(t, 597);
            //Assert.AreNotEqual(ep.GetField(t), rc.GetField(t));
            ep.BindElement(rc);
            Assert.AreEqual(597, ep.GetField(t).Value);
            Assert.AreEqual(597, rc.GetField(t).Value);

            RectangleContainer rc2 = new RectangleContainer(s);

            Assert.AreEqual(597, ep.GetField(t).Value);
            rc2.SetFieldValue(t, 595);
            Assert.AreEqual(595, rc2.GetField(t).Value);
            ep.BindElement(rc2);
            Assert.AreEqual(595, ep.GetField(t).Value);
            Assert.AreEqual(597, rc.GetField(t).Value);

            RectangleContainer rc3 = new RectangleContainer(s);

            rc3.SetFieldValue(t, 600);
            ep.BindElement(rc3);

            //Assert.AreEqual(600, ep.GetField(t).Value);
            Assert.AreEqual(600, rc3.GetField(t).Value);
            Assert.AreEqual(597, rc.GetField(t).Value);

            ep.SetFieldValue(t, 599);
            Assert.AreEqual(599, ep.GetField(t).Value);
            Assert.AreEqual(599, rc.GetField(t).Value);
            Assert.AreEqual(599, rc2.GetField(t).Value);
            Assert.AreEqual(599, rc3.GetField(t).Value);
        }
        public void TestPropertyClear()
        {
            // only Snapshot and Count are supported for properties
            Aggregation.Kinds[] aggrKindsProperties =
            {
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Snapshot
            };

            FieldAggregationConfig fieldAggrConfig = new FieldAggregationConfig(
                new Field("prop", Field.Kind.Property),
                aggrKindsProperties);

            FieldAggregator fieldAggr = new FieldAggregator(fieldAggrConfig);

            for (int i = 0; i < 20; i++)
            {
                fieldAggr.Aggregate(string.Format("property-{0}", i));
            }

            // Cleaning aggregations
            fieldAggr.Clear();

            Assert.AreEqual(null, fieldAggr.PropertySnapshot);
            Assert.AreEqual(0.0, fieldAggr.Count);

            // testing whether aggregating again doesn't fail after clearing
            for (int i = 0; i < 5; i++)
            {
                fieldAggr.Aggregate(string.Format("property-{0}", i));
            }

            fieldAggr.Aggregate("lastValue");

            Assert.AreEqual("lastValue", fieldAggr.PropertySnapshot);
            Assert.AreEqual(6, fieldAggr.Count);
        }
Example #9
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }
            if (_grippers != null)
            {
                for (int i = 0; i < _grippers.Length; i++)
                {
                    if (_grippers[i] == null)
                    {
                        continue;
                    }
                    _grippers[i].Dispose();
                    _grippers[i] = null;
                }
                _grippers = null;
            }

            FieldAggregator aggProps = _parent.FieldAggregator;

            aggProps.UnbindElement(this);
        }
        public void TestMetricAggregations()
        {
            // metric aggregation types
            Aggregation.Kinds[] aggrKindsMetrics =
            {
                Aggregation.Kinds.Average,
                Aggregation.Kinds.Count,
                Aggregation.Kinds.Maximum,
                Aggregation.Kinds.Minimum,
                Aggregation.Kinds.Snapshot,
                Aggregation.Kinds.Sum,
                Aggregation.Kinds.Variance
            };

            FieldAggregationConfig fieldAggrConfig = new FieldAggregationConfig(
                new Field("metric", Field.Kind.Metric),
                aggrKindsMetrics);

            FieldAggregator fieldAggr = new FieldAggregator(fieldAggrConfig);

            // test single element
            fieldAggr.Aggregate(1234.0);

            Assert.AreEqual(1234.0, fieldAggr.Snapshot);
            Assert.AreEqual(1.0, fieldAggr.Count);
            Assert.AreEqual(1234.0, fieldAggr.Minimum);
            Assert.AreEqual(1234.0, fieldAggr.Maximum);
            Assert.AreEqual(1234.0, fieldAggr.Average);
            Assert.AreEqual(1234.0, fieldAggr.Sum);
            Assert.AreEqual(0.0, fieldAggr.Variance);

            // cleaning
            fieldAggr.Clear();

            // test - with more values
            for (int i = 0; i <= 100; i++)
            {
                double val = -50.0 + i;
                fieldAggr.Aggregate(val);
            }

            Assert.AreEqual(50.0, fieldAggr.Snapshot);
            Assert.AreEqual(101.0, fieldAggr.Count);
            Assert.AreEqual(-50.0, fieldAggr.Minimum);
            Assert.AreEqual(50.0, fieldAggr.Maximum);
            Assert.AreEqual(0.0, fieldAggr.Average);
            Assert.AreEqual(0.0, fieldAggr.Sum);
            Assert.AreEqual(858.5, fieldAggr.Variance);

            // test a 0 variance
            fieldAggr.Clear();
            for (int i = 0; i <= 100; i++)
            {
                double val = 10.0;
                fieldAggr.Aggregate(val);
            }

            Assert.AreEqual(10.0, fieldAggr.Snapshot);
            Assert.AreEqual(101.0, fieldAggr.Count);
            Assert.AreEqual(10.0, fieldAggr.Minimum);
            Assert.AreEqual(10.0, fieldAggr.Maximum);
            Assert.AreEqual(10.0, fieldAggr.Average);
            Assert.AreEqual(1010.0, fieldAggr.Sum);
            Assert.AreEqual(0.0, fieldAggr.Variance);
        }