Exemplo n.º 1
0
        public void WithCountAsAggregation_GivenOneNullValues_ThenItCanBeExcludedFromCount()
        {
            var protocol = new ProtocolDescriptor {
                Reference = "Aggregation test"
            };
            var section = protocol.Sections.Add("Test");

            section.Values.Add(new ValueDescriptor {
                Reference = "a", PreferredAggregation = AggregationMode.Count
            });

            var dataset1 = new DataSet(protocol);

            dataset1.AddValue("a", 10);

            var dataset2 = new DataSet(protocol);

            dataset2.AddValue("a", null);

            // Null value is included in count
            var aggregator = new DataSetAggregator(protocol);
            var result     = aggregator.Accumulate(dataset1, dataset2).Calculate();

            Assert.Equal(2, result["a"].Value);

            // Null value is excluded from count
            aggregator.Clear();
            aggregator.Options = AggregationOptions.Default | AggregationOptions.ExcludeNullValuesFromCount;
            result             = aggregator.Accumulate(dataset1, dataset2).Calculate();
            Assert.Equal(1, result["a"].Value);
        }
Exemplo n.º 2
0
        public void WithAveragesAggregation_ThenEmptyDatasetsAreZero()
        {
            var protocol = new ProtocolDescriptor {
                Reference = "Aggregation test"
            };
            var section = protocol.Sections.Add("Test");

            section.Values.Add(new ValueDescriptor {
                Reference = "a", PreferredAggregation = AggregationMode.Average
            });

            var aggregator = new DataSetAggregator(protocol);
            var result     = aggregator.Calculate();

            Assert.Equal(null, result["a"].Value);
        }
Exemplo n.º 3
0
        public void WithNoAggregation_ThenCustomAggregationFunctionCanBeUsed()
        {
            var protocol = new ProtocolDescriptor {
                Reference = "Aggregation test"
            };
            var section = protocol.Sections.Add("Test");

            section.Values.Add(new ValueDescriptor
            {
                Reference             = "a",
                PreferredAggregation  = AggregationMode.None,
                AggregationExpression = @"sequence
                                          (
                                            let('mean', average(values)),
                                            let('n', count(values) - 1),
                                            sqrt(sum(values, pow(value - mean, 2)) / n)
                                          )"
            });

            var dataset1 = new DataSet(protocol);

            dataset1.AddValue("a", 10);

            var dataset2 = new DataSet(protocol);

            dataset2.AddValue("a", 20);

            var aggregator = new DataSetAggregator(protocol);
            var result     = aggregator.Accumulate(dataset1, dataset2).Calculate();

            if (result.Issues.HasErrors)
            {
                throw new InvalidOperationException(String.Join("\n", result.Issues.Select(x => x.Message)));
            }

            Assert.Equal(7.07, (double)result["a"].Value, 2);
        }
Exemplo n.º 4
0
        public void WithSumAsAggregation_ThenNullValuesEqualToZero()
        {
            var protocol = new ProtocolDescriptor {
                Reference = "Aggregation test"
            };
            var section = protocol.Sections.Add("Test");

            section.Values.Add(new ValueDescriptor {
                Reference = "a", PreferredAggregation = AggregationMode.Sum
            });

            var dataset1 = new DataSet(protocol);

            dataset1.AddValue("a", 10);

            var dataset2 = new DataSet(protocol);

            dataset2.AddValue("a", null);

            var aggregator = new DataSetAggregator(protocol);
            var result     = aggregator.Accumulate(dataset1, dataset2).Calculate();

            Assert.Equal(10.0, result["a"].Value);
        }
Exemplo n.º 5
0
        public void WithCountAsAggregation_GivenDoubleValues()
        {
            var protocol = new ProtocolDescriptor {
                Reference = "Aggregation test"
            };
            var section = protocol.Sections.Add("Test");

            section.Values.Add(new ValueDescriptor {
                Reference = "a", PreferredAggregation = AggregationMode.Count
            });

            var dataset1 = new DataSet(protocol);

            dataset1.AddValue("a", 10);

            var dataset2 = new DataSet(protocol);

            dataset2.AddValue("a", 5);

            var aggregator = new DataSetAggregator(protocol);
            var result     = aggregator.Accumulate(dataset1, dataset2).Calculate();

            Assert.Equal(2, result["a"].Value);
        }