当前位置: 首页>>代码示例>>C#>>正文


C# List.Count方法代码示例

本文整理汇总了C#中NUnit.Framework.List.Count方法的典型用法代码示例。如果您正苦于以下问题:C# List.Count方法的具体用法?C# List.Count怎么用?C# List.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Calculate_When1DiscountAppliesMoreThanOnceAndThereAreAdditionalDiscountableItems_ReturnsCorrectCost

        public void Calculate_When1DiscountAppliesMoreThanOnceAndThereAreAdditionalDiscountableItems_ReturnsCorrectCost()
        {
            const decimal expected = 1m;
            var products = new List<Product>
            {
                new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
                new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
                new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
                new Product {Id = 1, Name = "Butter", UnitPrice = 0.80m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m},
                new Product {Id = 3, Name = "Bread", UnitPrice = 1.00m}
            };

            _discountOfferRepositoryMock.Setup(m => m.GetDiscountOffers()).Returns(new List<DiscountOffer>
                {
                    new DiscountOffer { ProductBoughtId = 1, NumberToBuy = 2, ProductDiscountedId = 3, PercentageOff = 0.5m }
                });

            var actual = _discountOfferCalculatorService.Calculate(products);

            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(products.Count(p => p.Name == "Bread" && p.Processed) == 2);
            Assert.That(products.Count(p => p.Name == "Bread" && p.Processed == false) == 6);
            Assert.That(products.Where(p => p.Name == "Butter").All(p => p.Processed == false));
        }
开发者ID:SachinKainth,项目名称:Basket,代码行数:31,代码来源:DiscountOfferCalculatorServiceTests.cs

示例2: FiltersDataOutsideRTHWhenSessionSpansMultipleDays

        public void FiltersDataOutsideRTHWhenSessionSpansMultipleDays()
        {
            var sessions = new List<InstrumentSession>
            {
                new InstrumentSession
                { 
                    OpeningDay = DayOfTheWeek.Monday ,
                    ClosingDay = DayOfTheWeek.Tuesday,
                    OpeningTime = new TimeSpan(8, 0, 0),
                    ClosingTime = new TimeSpan(16, 0, 0),
                    IsSessionEnd = true
                }
            };

            var data = GetDataBetween(new DateTime(2014, 1, 13, 0, 0, 0), new DateTime(2014, 1, 14, 23, 0, 0));
            var unfilteredData = new List<OHLCBar>(data);

            RTHFilter.Filter(data, sessions);

            var startCutoff = new DateTime(2014, 1, 13, 8, 0, 0);
            var endingCutoff = new DateTime(2014, 1, 14, 16, 0, 0);

            Assert.AreEqual(0, data.Count(x => x.DT < startCutoff));
            Assert.AreEqual(0, data.Count(x => x.DT > endingCutoff));
            Assert.AreEqual(
                unfilteredData.Count 
                - unfilteredData.Count(x => x.DT <= startCutoff) 
                - unfilteredData.Count(x => x.DT > endingCutoff), 
                data.Count);
        }
开发者ID:leo90skk,项目名称:qdms,代码行数:30,代码来源:RTHFilterTest.cs

示例3: TestRandomSelectLessThanNumberOfSelections

        public void TestRandomSelectLessThanNumberOfSelections()
        {
            IEnumerable<object> enumerable = new List<object> { new object(), new object() };
            Assert.AreEqual(enumerable, enumerable.RandomSelect(enumerable.Count() + 1));

            IList<object> selectedItems = new List<object>();
            enumerable.RandomSelect(enumerable.Count() + 1, selectedItems.Add);
            Assert.IsTrue(CollectionUtils.SequenceEqual(enumerable, selectedItems));
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:9,代码来源:EnumerableExtensionMethodsTest.cs

示例4: RandomShufflerHandleNullAbleList

        public void RandomShufflerHandleNullAbleList()
        {
            const int expectedNumOfNull = 3;
            const int expectedNumOfOne = 1;

            var list = new List<int?>() { null, null, 1, null};
            ListRandomShuffler.InPlaceShuffle(list);

            var numOfNull = list.Count(i => i == null);
            var numOfOne = list.Count(i => i == 1);
            Assert.AreEqual(numOfNull, expectedNumOfNull);
            Assert.AreEqual(numOfOne, expectedNumOfOne);
        }
开发者ID:7FeiW,项目名称:PandellListRandomShuffler,代码行数:13,代码来源:ListRandomShufflerTests.cs

示例5: RandomShufflerHandleNullAbleRefferenceTypeList

        public void RandomShufflerHandleNullAbleRefferenceTypeList()
        {
            const int expectedNumOfNull = 3;
            const int expectedNumOfStr = 1;
            const string str = "This is not null";

            var list = new List<string>() { null, null, str, null };
            ListRandomShuffler.InPlaceShuffle(list);

            var numOfNull = list.Count(i => i == null);
            var numOfStr = list.Count(i => i == str);
            Assert.AreEqual(numOfNull, expectedNumOfNull);
            Assert.AreEqual(numOfStr, expectedNumOfStr);
        }
开发者ID:7FeiW,项目名称:PandellListRandomShuffler,代码行数:14,代码来源:ListRandomShufflerTests.cs

示例6: InspectObject_With_CircularReference

        public void InspectObject_With_CircularReference()
        {
            var parent = new ClassWithCircularReference_Parent();
            parent.Child = new ClassWithCircularReference_Child();
            parent.Child.Parent = parent;
            var itensFounded = new List<object>();

            _objectInspector.InspectObject(parent, value =>
            {
                itensFounded.Add(value);
            });

            Assert.AreEqual(1, itensFounded.Count(p => p.Equals(parent)), "Deveria ter achado o objeto parent apenas uma vez");
            Assert.AreEqual(1, itensFounded.Count(p => p.Equals(parent.Child)), "Deveria ter achado o objeto parent.Child apenas uma vez");
        }
开发者ID:jamir-araujo,项目名称:GraphCache,代码行数:15,代码来源:ObjectInspectorTests.cs

示例7: Buffer_CursorTop_Test

        public void Buffer_CursorTop_Test()
        {
            var process = new Process { StartInfo = { FileName = "cmd.exe" } };
            process.Start();

            AttachConsole(process.Id);
            var buffer = JConsole.GetActiveScreenBuffer();

            Assert.That(buffer.CursorTop, Is.EqualTo(3));
            Assert.That(buffer.CursorLeft, Is.GreaterThan(0));

            var events = new List<EventArgs>();
            events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'd' });
            events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'd' });
            events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'i' });
            events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'i' });
            events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = 'r' });
            events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = 'r' });
            events.Add(new ConsoleKeyEventArgs { KeyDown = true, RepeatCount = 1, KeyChar = (char)13 });
            events.Add(new ConsoleKeyEventArgs { KeyDown = false, RepeatCount = 1, KeyChar = (char)13 });

            var inputBuffer = JConsole.GetInputBuffer();
            inputBuffer.WindowInput = true;
            inputBuffer.WriteEvents(events, events.Count());

            buffer.WriteLine(buffer.OutputMode.ToString());
        }
开发者ID:andrewchaa,项目名称:ConsolePlus,代码行数:27,代码来源:TestConsoleApi.cs

示例8: PrintEmailsGroupedByDomain

 public void PrintEmailsGroupedByDomain()
 {
     List<string> emails = new List<string> { "[email protected]", "[email protected]", "[email protected]" };
     Dictionary<string, List<string>> groups = new Dictionary<string, List<string>>();
     for (int i = 0; i < emails.Count(); i++)
     {
         Match split = Regex.Matches(emails[i], @"[^@]*@(.*)")[0];
         string domain = split.Groups[1].Value;
         if (!groups.ContainsKey(domain))
         {
             groups.Add(domain, new List<string> { emails[i] });
         }
         else
         {
             groups[domain].Add(emails[i]);
         }
     }
     foreach (var key in groups.Keys)
     {
         Console.WriteLine("Emails for domain: " + key);
         for (int i = 0; i < groups[key].Count; i++)
         {
             Console.WriteLine(groups[key][i]);
         }
         Console.WriteLine();
     }
 }
开发者ID:g0t4,项目名称:Presentations,代码行数:27,代码来源:Patience.cs

示例9: Given_EmptyList_When_RandomX_ReturnEmptyList

 public void Given_EmptyList_When_RandomX_ReturnEmptyList()
 {
     var l = new List<string>();
     IEnumerable<string> rand = new List<string>();
     Assert.DoesNotThrow(() => rand = l.GetRandomX(4));
     Assert.AreEqual(0, rand.Count());
 }
开发者ID:Zaeran,项目名称:DarkerSmileCore,代码行数:7,代码来源:EnumerableExtensionsTests.cs

示例10: D_visit_complete_tree_depthFirst_on_VisitDescendants

        public void D_visit_complete_tree_depthFirst_on_VisitDescendants()
        {
            // ACT

            var result = new List<Tuple<List<string>, string>>();
            "rootNode".VisitDescendants(this.GetChildNodes, (b, n) => result.Add(Tuple.Create(b.ToList(), n)), depthFirst: true);

            // ASSERT

            Assert.AreEqual(5, result.Count());
            CollectionAssert.AreEqual(new[] {
                "leftNode",
                "leftLeaf",
                "rightNode",
                "leftRightLeaf",
                "rightRightLeaf"
            }, result.Select(i => i.Item2));

            CollectionAssert.AreEqual(new[] { "leftNode", "leftLeaf", "rightNode", "leftRightLeaf", "rightRightLeaf" }, result.Select(i => i.Item2));
            CollectionAssert.AreEqual(new[] { "rootNode" }, result.ElementAt(0).Item1);
            CollectionAssert.AreEqual(new[] { "rootNode", "leftNode" }, result.ElementAt(1).Item1);
            CollectionAssert.AreEqual(new[] { "rootNode" }, result.ElementAt(2).Item1);
            CollectionAssert.AreEqual(new[] { "rootNode", "rightNode" }, result.ElementAt(3).Item1);
            CollectionAssert.AreEqual(new[] { "rootNode", "rightNode" }, result.ElementAt(4).Item1);
        }
开发者ID:wgross,项目名称:Elementary.Hierarchy,代码行数:25,代码来源:GenericNodeVisitDescendantsTest.cs

示例11: TestBolsterAllies

        public void TestBolsterAllies()
        {
            Start game = new Start();
            game.beginGame();
            Legacy legacy = new Legacy();

            List<int> firstList = new List<int>();
            foreach (Hero hero in GameEngine.getHeroes())
            {
                firstList.Add(hero.hand.Count());
            }

            Card bolster = new Card("Images\\Hero\\Legacy\\BolsterAllies.png");
            legacy.BolsterAllies(bolster);

            List<int> secondList = new List<int>();
            foreach (Hero hero in GameEngine.getHeroes())
            {
                secondList.Add(hero.hand.Count());
            }

            for(int i = 0; i < secondList.Count(); i++)
            {
                Assert.AreEqual(secondList[i], firstList[i] + 1);
            }
        }
开发者ID:vattercw,项目名称:SentinelsOfTheMultiverse,代码行数:26,代码来源:LegacyTest.cs

示例12: UsingWebRequest

        public void UsingWebRequest()
        {
            var count = 0;
            var requestUri = new Uri("http://google.com");

            var sp = Stopwatch.StartNew();
            var tasks = new List<Task>();
            for (var i = 0; i < 10; i++)
            {
                var t = Task.Run(() =>
                {
                    var webRequest = WebRequest.Create(requestUri);
                    webRequest.GetResponse().Close();
                    Interlocked.Increment(ref count);
                });
                tasks.Add(t);
            }
            var whenAll = Task.WhenAll(tasks);
            while (whenAll.IsCompleted == false && whenAll.IsFaulted  == false)
            {
                Thread.Sleep(1000);
                Console.WriteLine("{0} - {1}, {2}", sp.Elapsed, count, tasks.Count(x=> x.IsCompleted == false));
            }
            Console.WriteLine(sp.Elapsed);
        }
开发者ID:EamonNerbonne,项目名称:FunTools,代码行数:25,代码来源:AsyncSampleFromAyendeBlog.cs

示例13: TestSmaSimple

        public void TestSmaSimple()
        {
            int period = 5;

            List<double> data = new List<double>(new double[]{
                3,
                3,
                3,
                3,
                3
            });

            var result =  TechnicalAnalisysMethods.SimpleMovingAverage(data);

            int zeroCnt = result.Where(x => x == 0.0).Count();
            int valueCnt = result.Length - zeroCnt;

            Assert.That(result.Length == data.Count());

            Assert.That(zeroCnt == 4);

            double sma = result.Where(x => x != 0.0).First();

            Assert.That(sma == 3.0);
        }
开发者ID:ciasteczko-i-mleczko,项目名称:magisterka,代码行数:25,代码来源:TechnicalAnalisysMethodsTest.cs

示例14: PrintEmailsGroupedByDomain_ExtractLocalVariablesResharper

 public void PrintEmailsGroupedByDomain_ExtractLocalVariablesResharper()
 {
     var emails = new List<string> { "[email protected]", "[email protected]", "[email protected]" };
     var groups = new Dictionary<string, List<string>>();
     for (var i = 0; i < emails.Count(); i++)
     {
         var email = emails[i];
         var split = Regex.Matches(email, @"[^@]*@(.*)")[0];
         var domain = split.Groups[1].Value;
         if (!groups.ContainsKey(domain))
         {
             groups.Add(domain, new List<string> { email });
         }
         else
         {
             groups[domain].Add(email);
         }
     }
     foreach (var key in groups.Keys)
     {
         Console.WriteLine("Emails for domain: " + key);
         var emailsInDomain = groups[key];
         for (var i = 0; i < emailsInDomain.Count; i++)
         {
             Console.WriteLine(emailsInDomain[i]);
         }
         Console.WriteLine();
     }
 }
开发者ID:g0t4,项目名称:Presentations,代码行数:29,代码来源:Patience.cs

示例15: AreEqual

 public static void AreEqual(List<TimeScope> timescopes, List<TIM> tims)
 {
     for (var i = 0; i < timescopes.Count(); i++)
     {
         AreEqual(timescopes[i], tims[i]);
     }
 }
开发者ID:ADAPT,项目名称:ISOv4Plugin,代码行数:7,代码来源:TimAssert.cs


注:本文中的NUnit.Framework.List.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。