示例#1
0
        public static async Task <Accumulate <TAccumulate1, TAccumulate2> > AggregateAsync <TAccumulate1, TAccumulate2, TItem>(this IEnumerableAsync <TItem> enumerable,
                                                                                                                               TAccumulate1 seed1, TAccumulate2 seed2,
                                                                                                                               Func <TAccumulate1, TAccumulate2,
                                                                                                                                     TItem,
                                                                                                                                     Func <TAccumulate1, TAccumulate2, Accumulate <TAccumulate1, TAccumulate2> >,
                                                                                                                                     Accumulate <TAccumulate1, TAccumulate2> > funcAsync)
        {
            var accumulation = new Accumulate <TAccumulate1, TAccumulate2>
            {
                accumulation1 = seed1,
                accumulation2 = seed2,
            };
            var enumeratorAsync = enumerable.GetEnumerator();

            while (await enumeratorAsync.MoveNextAsync())
            {
                var current = enumeratorAsync.Current;
                accumulation = funcAsync(accumulation.accumulation1, accumulation.accumulation2,
                                         current,
                                         (acc1, acc2) => new Accumulate <TAccumulate1, TAccumulate2>
                {
                    accumulation1 = acc1,
                    accumulation2 = acc2,
                });
            }
            return(accumulation);
        }
 public static void Launch()
 {
     StringReverse.StringReverseTest();     //wywołuję metodę statyczną testującą klasę .cs
     LeapYear.LeapYearTest();
     SumOfMultiples.SumOfMultiplesTest();
     Raindrops.RaindropsTest();
     NucleotideCount.NucleotideCountTest();
     Accumulate.AccumulateTest();
 }
示例#3
0
 // Methods
 internal Animate(string prefix, string localname, string ns, SvgDocument doc)
     : base(prefix, localname, ns, doc)
 {
     this.values = new ArrayList();
     this.keyTimes = new ArrayList();
     this.realdur = 0f;
     this.Additive = Additive.replace;
     this.Accumulate = Accumulate.none;
     this.Speed = 10;
 }
            public void Should_increase_global_accumulator_with_parameter_value(int parameter)
            {
                var cpu = new CPU();
                var acc = new Accumulate
                {
                    Arguments = new[] { parameter }
                };

                acc.Execute(cpu);

                Assert.Equal(parameter, cpu.Accumulator);
            }
            public void Should_increase_program_counter_by_one(int pc)
            {
                var cpu = new CPU
                {
                    ProgramCounter = pc
                };
                var acc = new Accumulate
                {
                    Arguments = new[] { 0 }
                };

                acc.Execute(cpu);

                Assert.Equal(pc + 1, cpu.ProgramCounter);
            }
示例#6
0
 public void AccumlTest()
 {
     Assert.AreEqual("A-Bb-Ccc-Dddd-Eeeee", Accumulate.Accum("abcde"));
     Assert.AreEqual("Z-Pp-Ggg-Llll-Nnnnn-Rrrrrr-Xxxxxxx-Qqqqqqqq-Eeeeeeeee-Nnnnnnnnnn-Uuuuuuuuuuu",
                     Accumulate.Accum("ZpglnRxqenU"));
 }
示例#7
0
        public async Task <IEnumerable <AgeGenderDistribution> > GetAgeGenderDistributionAsync(Accumulate type)
        {
            var builder = new SqlBuilder();
            //note the 'where' in-line comment is required, it is a replacement token
            var query = @"
                select 
                    agegroup, 
                    sex, 
                    count(*) as value
                from 
                    covidtracker.cases
                /**where**/
                group by 
                    agegroup, sex
                order by 
                    sex;
           ";

            var    selector = builder.AddTemplate(query);
            string condition;

            switch (type)
            {
            case Accumulate.Admitted:
                condition = "admitted and dateremoved is null";
                break;

            case Accumulate.Died:
                condition = "removaltype = 'Died'";
                break;

            case Accumulate.Recovered:
                condition = "removaltype = 'Recovered'";
                break;

            default:
            case Accumulate.Total:
                condition = "true";
                break;
            }
            builder.Where(condition);
            using (var con = _connectionFactory())
            {
                return(await con.QueryAsync <AgeGenderDistribution>(selector.RawSql));
            }
        }
示例#8
0
        public async Task <IEnumerable <Accumulation <DateTime, int> > > GetAccumulationAsync(Accumulate type)
        {
            var builder = new SqlBuilder();
            //note the 'where' in-line comment is required, it is a replacement token
            var query = @"
                with data as (
                    select
                        /**select**/
                    from covidtracker.cases
                        /**where**/
                    group by 1
                    order by 1 asc nulls last
                )
                select 
                    date as accumulator,
                    sum(count) over (
                        order by 
                            date asc 
                        rows between unbounded 
                            preceding and 
                            current row
                    ) as value
                from data
                order by date desc
           ";

            var    selector = builder.AddTemplate(query);
            string condition;

            switch (type)
            {
            case Accumulate.Admitted:
                condition = "admitted and dateremoved is null";
                builder.Select("date_trunc('day', dateconfirmed) as date");
                break;

            case Accumulate.Died:
                condition = "removaltype = 'Died'";
                builder.Select("date_trunc('day', dateremoved) as date");
                break;

            case Accumulate.Recovered:
                condition = "removaltype = 'Recovered'";
                builder.Select("date_trunc('day', dateremoved) as date");
                break;

            default:
            case Accumulate.Total:
                builder.Select("date_trunc('day', dateconfirmed) as date");
                condition = "true";
                break;
            }
            builder.Select("count(*)");
            builder.Where(condition);
            using (var con = _connectionFactory())
            {
                return(await con.QueryAsync <Accumulation <DateTime, int> >(selector.RawSql));
            }
        }