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]); }
void AssertCalculation(object[] data, object expectedSum, object expectedMin, object expectedMax, object expectedAvg, object expectedCount) { /* SQL script to validate drop table if exists t1; #create table t1 (a int); #insert into t1 (a) values (1), (3), (5); #create table t1 (a varchar(32)); #insert into t1 (a) values ('a'), ('z'); #insert into t1 (a) values (null); select concat( " sum=", coalesce(sum(a), 'N'), " min=", coalesce(min(a), 'N'), " max=", coalesce(max(a), 'N'), " avg=", coalesce(avg(a), 'N'), " count=", coalesce(count(*), 'N') ) from t1; */ var summaries = new[] { new SummaryInfo { Selector = "this", SummaryType = "sum" }, new SummaryInfo { Selector = "this", SummaryType = "min" }, new SummaryInfo { Selector = "this", SummaryType = "max" }, new SummaryInfo { Selector = "this", SummaryType = "avg" }, new SummaryInfo { SummaryType = "count" }, }; var totals = new AggregateCalculator<object>(data, new DefaultAccessor<object>(), summaries, null).Run(); Assert.Equal(expectedSum, totals[0]); Assert.Equal(expectedMin, totals[1]); Assert.Equal(expectedMax, totals[2]); Assert.Equal(expectedAvg, totals[3]); Assert.Equal(expectedCount, totals[4]); }
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]); }