public static void FirstOrDefault(Labeled <ParallelQuery <int> > labeled, int count, int position)
        {
            // For unordered collections, which element is chosen isn't actually guaranteed, but an effect of the implementation.
            // If this test starts failing it should be split, and possibly mentioned in release notes.
            ParallelQuery <int> query = labeled.Item;

            Assert.Equal(0, query.FirstOrDefault());
            Assert.Equal(position, query.FirstOrDefault(x => x >= position));
        }
예제 #2
0
        public Hero GetAllyHero(ParallelQuery <Hero> allies)
        {
            switch (Type)
            {
            case GetHeroType.ModifierSource:
                return(allies.FirstOrDefault(x => x.Equals(Source)));

            case GetHeroType.LowestHealthPct:
                return
                    (allies.Where(x => x.HasModifier(Modifier.Name))
                     .OrderByDescending(x => x.Equals(Hero))
                     .ThenBy(x => x.Health / x.MaximumHealth)
                     .FirstOrDefault());

            case GetHeroType.LowestHealth:
                return
                    (allies.Where(x => x.HasModifier(Modifier.Name))
                     .OrderByDescending(x => x.Equals(Hero))
                     .ThenBy(x => x.Health)
                     .FirstOrDefault());

            case GetHeroType.ClosestToSource:
                return
                    (allies.Where(x => x.Distance2D(Source) <= MaximumDistanceToSource)
                     .OrderBy(x => x.Distance2D(Source))
                     .FirstOrDefault());
            }

            return(null);
        }
        public static void FirstOrDefault_NoMatch(Labeled <ParallelQuery <int> > labeled, int count, int position)
        {
            ParallelQuery <int> query = labeled.Item;
            IntegerRangeSet     seen  = new IntegerRangeSet(0, count);

            Assert.Equal(default(int), query.FirstOrDefault(x => !seen.Add(x)));
            seen.AssertComplete();
        }
        public static void FirstOrDefault_Empty(Labeled <ParallelQuery <int> > labeled, int count, int position)
        {
            _ = count;
            _ = position;
            ParallelQuery <int> query = labeled.Item;

            Assert.Equal(default(int), query.FirstOrDefault());
        }
예제 #5
0
        public static void Range_FirstOrDefault(int start, int count)
        {
            ParallelQuery <int> query = ParallelEnumerable.Range(start, count);

            Assert.Equal(count == 0 ? 0 : start, query.FirstOrDefault());
        }
예제 #6
0
 public Hero GetModifierHero(ParallelQuery <Hero> allies)
 {
     return(allies.FirstOrDefault(x => x.Equals(modifierSource)));
 }