Beispiel #1
0
        public void NestedGroups()
        {
            var data = new[] {
                new Group {
                    items = new[] {
                        new Group {
                            items = new object[] { 1, 5 }
                        }
                    }
                }
            };

            var calculator = new AggregateCalculator <int>(data, new DefaultAccessor <int>(), null, new[] {
                new SummaryInfo {
                    Selector = "this", SummaryType = "sum"
                }
            });

            var totals = calculator.Run();

            Assert.Null(totals);

            Assert.Equal(6M, data[0].summary[0]);
            Assert.Equal(6M, (data[0].items[0] as Group).summary[0]);
        }
        public void TimeSpanType()
        {
            var data = new[] {
                TimeSpan.FromMinutes(1),
                TimeSpan.FromMinutes(3)
            };

            var calculator = new AggregateCalculator <TimeSpan>(data, new DefaultAccessor <TimeSpan>(),
                                                                new[] {
                new SummaryInfo {
                    Selector = "this", SummaryType = "min"
                },
                new SummaryInfo {
                    Selector = "this", SummaryType = "max"
                },
                new SummaryInfo {
                    Selector = "this", SummaryType = "sum"
                },
                new SummaryInfo {
                    Selector = "this", SummaryType = "avg"
                }
            },
                                                                null
                                                                );

            Assert.Equal(
                new object[] {
                TimeSpan.FromMinutes(1),
                TimeSpan.FromMinutes(3),
                TimeSpan.FromMinutes(4),
                TimeSpan.FromMinutes(2)
            },
                calculator.Run()
                );
        }
Beispiel #3
0
        public void Minimal()
        {
            var data = new[] {
                new Group {
                    items = new object[] { 1, 5 }
                },
                new Group {
                    items = new object[] { 7 }
                }
            };

            var calculator = new AggregateCalculator <int>(data, new DefaultAccessor <int>(),
                                                           new[] { new SummaryInfo {
                                                                       Selector = "this", SummaryType = "sum"
                                                                   } },
                                                           new[] { new SummaryInfo {
                                                                       Selector = "this", SummaryType = "sum"
                                                                   } }
                                                           );

            var totals = calculator.Run();

            Assert.Equal(13M, totals[0]);
            Assert.Equal(6M, data[0].summary[0]);
            Assert.Equal(7M, data[1].summary[0]);
        }
Beispiel #4
0
        public void CustomAggregator()
        {
            CustomAggregatorsBarrier.Run(delegate {
                CustomAggregators.RegisterAggregator("comma", typeof(CommaAggregator <>));

                var data = new[] {
                    new Group {
                        items = new Tuple <int>[] { Tuple.Create(1), Tuple.Create(5) }
                    },
                    new Group {
                        items = new Tuple <int>[] { Tuple.Create(7) }
                    },
                    new Group {
                        items = new Tuple <int>[] { }
                    }
                };

                var calculator = new AggregateCalculator <Tuple <int> >(data, new DefaultAccessor <Tuple <int> >(),
                                                                        new[] { new SummaryInfo {
                                                                                    Selector = "Item1", SummaryType = "comma"
                                                                                } },
                                                                        new[] { new SummaryInfo {
                                                                                    Selector = "Item1", SummaryType = "comma"
                                                                                } }
                                                                        );

                var totals = calculator.Run();

                Assert.Equal("1,5,7", totals[0]);
                Assert.Equal("1,5", data[0].summary[0]);
                Assert.Equal("7", data[1].summary[0]);
                Assert.Equal(string.Empty, data[2].summary[0]);
            });
        }
Beispiel #5
0
        public void IgnoreGroupSummaryIfNoGroups()
        {
            var data = new object[] { 1 };

            var calculator = new AggregateCalculator <int>(data, new DefaultAccessor <int>(), null, new[] {
                new SummaryInfo {
                    Selector = "ignore me", SummaryType = "ignore me"
                }
            });

            calculator.Run();
        }
Beispiel #6
0
        public void Issue147()
        {
            var data = Enumerable.Repeat(Double.MaxValue / 3, 2);

            var calculator = new AggregateCalculator <double>(data, new DefaultAccessor <double>(),
                                                              new[] { new SummaryInfo {
                                                                          Selector = "this", SummaryType = "sum"
                                                                      } },
                                                              null
                                                              );

            Assert.Equal(data.Sum(), calculator.Run()[0]);
        }
        public void CustomAggregator()
        {
            try {
                CustomAggregators.RegisterAggregator("totalSales", typeof(TotalSalesAggregator <>));

                var data = new[] {
                    new Group {
                        items = new[] {
                            new CustomAggregatorDataItem {
                                UnitPrice = 4.04M, Quantity = 5, Discount = 0.10M
                            },
                            new CustomAggregatorDataItem {
                                UnitPrice = 10.10M, Quantity = 2, Discount = 0.20M
                            }
                        }
                    },
                    new Group {
                        items = new[] {
                            new CustomAggregatorDataItem {
                                UnitPrice = 15.15M, Quantity = 4, Discount = 0.30M
                            }
                        }
                    },
                    new Group {
                        items = new CustomAggregatorDataItem[] { }
                    }
                };

                var calculator = new AggregateCalculator <CustomAggregatorDataItem>(data, new DefaultAccessor <CustomAggregatorDataItem>(),
                                                                                    new[] { new SummaryInfo {
                                                                                                Selector = "this", SummaryType = "totalSales"
                                                                                            } },
                                                                                    new[] { new SummaryInfo {
                                                                                                Selector = "this", SummaryType = "totalSales"
                                                                                            } }
                                                                                    );

                var totals = calculator.Run();

                Assert.Equal(76.76M, totals[0]);
                Assert.Equal(34.34M, data[0].summary[0]);
                Assert.Equal(42.42M, data[1].summary[0]);
                Assert.Equal(0M, data[2].summary[0]);
            } finally {
                CustomAggregators.Clear();
            }
        }
        public void Minimal() {
            var data = new[] {
                new Group {
                    items = new object[] { 1, 5 }
                },
                new Group {
                    items = new object[] { 7 }
                }
            };

            var calculator = new AggregateCalculator<int>(data, new DefaultAccessor<int>(),
                new[] { new SummaryInfo { Selector = "this", SummaryType = "sum" } },
                new[] { new SummaryInfo { Selector = "this", SummaryType = "sum" } }
            );

            var totals = calculator.Run();

            Assert.Equal(13M, totals[0]);
            Assert.Equal(6M, data[0].summary[0]);
            Assert.Equal(7M, data[1].summary[0]);
        }
        public void IgnoreGroupSummaryIfNoGroups() {
            var data = new object[] { 1 };

            var calculator = new AggregateCalculator<int>(data, new DefaultAccessor<int>(), null, new[] {
                new SummaryInfo { Selector = "ignore me", SummaryType = "ignore me" }
            });

            calculator.Run();
        }
        public void NestedGroups() {
            var data = new[] {
                new Group {
                    items = new[] {
                        new Group {
                            items = new object[] { 1, 5 }
                        }
                    }
                }
            };

            var calculator = new AggregateCalculator<int>(data, new DefaultAccessor<int>(), null, new[] {
                new SummaryInfo { Selector = "this", SummaryType = "sum" }
            });

            var totals = calculator.Run();
            Assert.Null(totals);

            Assert.Equal(6M, data[0].summary[0]);
            Assert.Equal(6M, (data[0].items[0] as Group).summary[0]);
        }