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


C# List.Take方法代码示例

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


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

示例1: GetFrom_Max

        public void GetFrom_Max()
        {
            savedIds = savedIds.OrderByDescending(i => i).ToList();

            Assert.That(repos.GetNewFrom(1).Select(p => p.Id), Is.EquivalentTo(savedIds.Take(1)));
            Assert.That(repos.GetNewFrom(2).Select(p => p.Id), Is.EquivalentTo(savedIds.Take(2)));
        }
开发者ID:royra,项目名称:pwipper,代码行数:7,代码来源:PwipReposTests.cs

示例2: MeasureUpdatePerformance

        public void MeasureUpdatePerformance()
        {
            var subscriptions = new List<Subscription>();
            for (var typeIdIndex = 0; typeIdIndex < 20; ++typeIdIndex)
            {
                var typeId = new MessageTypeId("Abc.Foo.Events.FakeEvent" + typeIdIndex);
                for (var routingIndex = 0; routingIndex < 500; ++routingIndex)
                {
                    subscriptions.Add(new Subscription(typeId, new BindingKey(routingIndex.ToString())));
                }
            }

            var subscriptionsByTypeId = subscriptions.GroupBy(x => x.MessageTypeId).ToDictionary(x => x.Key, x => x.Select(s=>s.BindingKey).ToArray());

            _directory = new PeerDirectoryClient(_configurationMock.Object);
            _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false)));

            Console.WriteLine("Snapshot updates (add)");
            using (Measure.Throughput(subscriptions.Count))
            {
                for (var subscriptionCount = 1; subscriptionCount <= subscriptions.Count; ++subscriptionCount)
                {
                    _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount))));
                }
            }
            Console.WriteLine("Snapshot updates (remove)");
            using (Measure.Throughput(subscriptions.Count))
            {
                for (var subscriptionCount = subscriptions.Count; subscriptionCount >= 1; --subscriptionCount)
                {
                    _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount))));
                }
            }

            _directory = new PeerDirectoryClient(_configurationMock.Object);
            _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false)));

            Console.WriteLine("Snapshot updates per message type id (add)");
            using (Measure.Throughput(subscriptions.Count))
            {
                foreach (var subscriptionGroup in subscriptionsByTypeId)
                {
                    _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key, subscriptionGroup.Value));
                }
            }
            Console.WriteLine("Snapshot updates per message type id (remove)");
            using (Measure.Throughput(subscriptions.Count))
            {
                foreach (var subscriptionGroup in subscriptionsByTypeId)
                {
                    _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key));
                }
            }
        }
开发者ID:MarouenK,项目名称:Zebus,代码行数:54,代码来源:PeerDirectoryClientTests.Performance.cs

示例3: Given

        protected override void Given()
        {
            Events = new List<object>
            {
                new {EventId = Guid.NewGuid(), EventType = "event-type", Data = new {A = "1"}},
                new {EventId = Guid.NewGuid(), EventType = "event-type", Data = new {B = "2"}},
                new {EventId = Guid.NewGuid(), EventType = "event-type", Data = new {C = "3"}},
                new {EventId = Guid.NewGuid(), EventType = "event-type", Data = new {D = "4"}}
            };

            var response = MakeArrayEventsPost(
                         TestStream,
                         Events.Take(NumberOfEventsToCreate ?? Events.Count),
                         _admin);
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);

            GroupName = Guid.NewGuid().ToString();
            SubscriptionPath = string.Format("/subscriptions/{0}/{1}", TestStream.Substring(9), GroupName);
            response = MakeJsonPut(SubscriptionPath,
                new
                {
                    ResolveLinkTos = true,
                    MessageTimeoutMilliseconds = 10000,
                },
                _admin);
            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
开发者ID:czcz1024,项目名称:EventStore,代码行数:27,代码来源:getting.cs

示例4: UsingFiltersIsThreadSafe

		public void UsingFiltersIsThreadSafe()
		{
			var errors = new List<Exception>();
			var threads = new List<Thread>();
			for (int i = 0; i < 50; i++)
			{
				var thread = new Thread(() =>
				{
					try
					{
						ScenarioRunningWithMultiThreading();
					}
					catch (Exception ex)
					{
						lock (errors)
							errors.Add(ex);
					}
				});
				thread.Start();
				threads.Add(thread);
			}

			foreach (var thread in threads)
			{
				thread.Join();
			}

			Console.WriteLine("Detected {0} errors in threads. Displaying the first three (if any):", errors.Count);
			foreach (var exception in errors.Take(3))
				Console.WriteLine(exception);

			Assert.AreEqual(0, errors.Count, "number of threads with exceptions");
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:33,代码来源:Fixture.cs

示例5: be_able_to_read_all_one_by_one_and_return_empty_slice_at_last

        public void be_able_to_read_all_one_by_one_and_return_empty_slice_at_last()
        {
            const string stream = "read_all_events_backward_should_be_able_to_read_all_one_by_one_and_return_empty_slice_at_last";
            using (var store = EventStoreConnection.Create())
            {
                store.Connect(Node.TcpEndPoint);
                var create = store.CreateStreamAsync(stream, false, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var testEvents = Enumerable.Range(0, 5).Select(x => new TestEvent((x + 1).ToString())).ToArray();

                var write = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, testEvents);
                Assert.DoesNotThrow(write.Wait);

                var all = new List<RecordedEvent>();
                var position = Position.End;
                AllEventsSlice slice;

                while ((slice = store.ReadAllEventsBackward(position, 1)).Events.Any())
                {
                    all.Add(slice.Events.Single());
                    position = slice.Position;
                }

                Assert.That(TestEventsComparer.Equal(testEvents.Reverse().ToArray(), all.Take(testEvents.Length).ToArray()));
            }
        }
开发者ID:robashton,项目名称:EventStore,代码行数:27,代码来源:read_all_events_backward_should.cs

示例6: IsValidHandShouldThrowAnExceptionIfCountOfTheCardsInTheHandIsNotExactly5

        public void IsValidHandShouldThrowAnExceptionIfCountOfTheCardsInTheHandIsNotExactly5(int count)
        {
            var cards = new List<ICard>() { new Card(CardFace.King, CardSuit.Spades), new Card(CardFace.Three, CardSuit.Clubs), new Card(CardFace.Two, CardSuit.Clubs), new Card(CardFace.Queen, CardSuit.Spades), new Card(CardFace.King, CardSuit.Diamonds), new Card(CardFace.King, CardSuit.Spades), new Card(CardFace.Three, CardSuit.Clubs), new Card(CardFace.Two, CardSuit.Clubs), new Card(CardFace.Queen, CardSuit.Spades), new Card(CardFace.King, CardSuit.Diamonds) };
            var hand = new Hand(cards.Take(count).ToList());
            var checker = new PokerHandsChecker();

            checker.IsValidHand(hand);
        }
开发者ID:AYankova,项目名称:HQC,代码行数:8,代码来源:PokerHandsCheckerIsValidHandTests.cs

示例7: GetFrom_StartId

        public void GetFrom_StartId()
        {
            savedIds = savedIds.OrderByDescending(i => i).ToList();

            var firstTwo = repos.GetNewFrom(2).Select(p => p.Id);
            Assert.That(firstTwo, Is.EquivalentTo(savedIds.Take(2)));
            var nextTwo = repos.GetNewFrom(2, firstTwo.Min()).Select(p => p.Id);
            Assert.That(nextTwo, Is.EquivalentTo(savedIds.Skip(2).Take(2)));
        }
开发者ID:royra,项目名称:pwipper,代码行数:9,代码来源:PwipReposTests.cs

示例8: FindTop10VideoFriends_EmptyFieldVideo

 public void FindTop10VideoFriends_EmptyFieldVideo()
 {
     List<Video> listVideo = new List<Video>();
     listVideo = FillingListVideo(listVideo);
     listVideo.Add(new Video { Vid = 0, OwnerId = 0, Views = 0 });
     List<Video> listVideoResult = new List<Video>();
     listVideoResult = listVideo.Take(10).ToList();
     Assert.AreEqual(listVideoResult, control.FindTop10Video(listVideo));
 }
开发者ID:KiraTanaka,项目名称:VK,代码行数:9,代码来源:ControlTests.cs

示例9: FindTop10VideoFriends_VideoIsNull

 public void FindTop10VideoFriends_VideoIsNull()
 {
     List<Video> listVideo = new List<Video>();
     listVideo = FillingListVideo(listVideo);
     listVideo.Add(null);
     listVideo.Add(new Video { Vid = 82474, OwnerId = 924898, Views = 987654 });
     List<Video> listVideoResult = new List<Video>();
     listVideoResult.Add(listVideo[11]);
     listVideoResult.AddRange(listVideo.Take(9).ToList());
     Assert.AreEqual(listVideoResult, control.FindTop10Video(listVideo));
 }
开发者ID:KiraTanaka,项目名称:VK,代码行数:11,代码来源:ControlTests.cs

示例10: TestFixtureSetUp

		public void TestFixtureSetUp()
		{
			var jsonPages = File.ReadAllText("~/AppData/Pages.json".MapProjectPath());
	
			Pages = JsonSerializer.DeserializeFromString<List<Page>>(jsonPages);

			SearchResponse = new SearchResponse {
				Query = "OrmLite",
				Results = Pages.Take(5).ToList(),
			};
		}
开发者ID:grammarware,项目名称:fodder,代码行数:11,代码来源:tests_ServiceStack_ServiceHost_Tests_Formats_UseCaseTests.cs

示例11: TestXorEvolution

        public void TestXorEvolution()
        {
            Func<BitArray,double> fitness = (chromosome) =>
            {
                Wiring wiring = new Wiring(2,1,4, chromosome);

                FPGA xorGate = new FPGA(wiring);

                double total = 0.0;
                if(!xorGate.Output(CreateInput(false,false))[0]) total += 1.0;
                if(!xorGate.Output(CreateInput(true,true))[0])	total += 1.0;
                if(xorGate.Output(CreateInput(true,false))[0]) total += 1.0;
                if(xorGate.Output(CreateInput(false,true))[0]) total += 1.0;
                if(total == 0.0) return 0.0;

                return 4.0 / total;
            };

            Random rnd = new Random();

            Func<BitArray> init = () =>
            {
                BitArray result = new BitArray(Wiring.CalcLength(2,1,4));
                for(int i=0; i<result.Length; i++)
                {
                    if(rnd.NextDouble()<0.5)
                        result[i]=true;
                }
                return result;
            };

            Evolution evo = new Evolution(fitness,0.001, new int[]{
                0,2,4,6,8,10,12,14,
                16,19,22,25,
                28,30,32, 34,36, 38});

            int n = 100;
            IList<BitArray> population = new List<BitArray>(n);
            for(int i=0; i<n; i++)
                population.Add(init());

            population = evo.Run(population, (generation,error) => {
                return
                    (generation > 1000); // || (error > 0.99);
            });

            foreach(BitArray wiring in population.Take(10))
            {
                Wiring temp = new Wiring(2,1,4,wiring);
                Console.WriteLine (temp.ToString());
                Console.WriteLine (fitness(wiring));
            }
        }
开发者ID:stefc,项目名称:evogate,代码行数:53,代码来源:TestEvolution.cs

示例12: TestSkip

        public void TestSkip()
        {
            var s = new List<string> { "one", "two", "three" };

            var list = s.Take(3).Take(5).ToList();

            var query = _collection.AsQueryable<C>().Skip(5);

            var selectQuery = (SelectQuery)MongoQueryTranslator.Translate(query);
            Assert.AreEqual(5, selectQuery.Skip);
            Assert.IsNull(selectQuery.Take);
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:12,代码来源:SkipAndTakeTests.cs

示例13: be_able_to_read_all_one_by_one_until_end_of_stream

        public void be_able_to_read_all_one_by_one_until_end_of_stream()
        {
            var all = new List<RecordedEvent>();
            var position = Position.End;
            AllEventsSlice slice;

            while (!(slice = _conn.ReadAllEventsBackwardAsync(position, 1, false).Result).IsEndOfStream)
            {
                all.Add(slice.Events.Single().Event);
                position = slice.NextPosition;
            }

            Assert.That(EventDataComparer.Equal(_testEvents.Reverse().ToArray(), all.Take(_testEvents.Length).ToArray()));
        }
开发者ID:MariuszTrybus,项目名称:EventStore,代码行数:14,代码来源:read_all_events_backward_should.cs

示例14: be_able_to_read_events_slice_at_time

        public void be_able_to_read_events_slice_at_time()
        {
            var all = new List<RecordedEvent>();
            var position = Position.End;
            AllEventsSlice slice;

            while (!(slice = _conn.ReadAllEventsBackwardAsync(position, 5, false).Result).IsEndOfStream)
            {
                all.AddRange(slice.Events.Select(x => x.Event));
                position = slice.NextPosition;
            }

            Assert.That(EventDataComparer.Equal(_testEvents.Reverse().ToArray(), all.Take(_testEvents.Length).ToArray()));
        }
开发者ID:MariuszTrybus,项目名称:EventStore,代码行数:14,代码来源:read_all_events_backward_should.cs

示例15: Delete_Should_Remove_Multiple_Items

        public void Delete_Should_Remove_Multiple_Items(ICompoundKeyRepository<User, string, int> repository)
        {
            IList<User> users = new List<User>
                                        {
                                            new User { Username = "Test User", Age = 11, FullName = "Test User - 11" },
                                            new User { Username = "Test User", Age = 21, FullName = "Test User - 21" },
                                            new User { Username = "Test User 2", Age = 11, FullName = "Test User  2- 11" },
                                        };

            repository.Add(users);
            var items = repository.GetAll().ToList();
            items.Count().ShouldEqual(3);

            repository.Delete(users.Take(2));
            items = repository.GetAll().ToList();
            items.Count().ShouldEqual(1);
            items.First().Username.ShouldEqual("Test User 2");
        }
开发者ID:mgmccarthy,项目名称:SharpRepository,代码行数:18,代码来源:CompoundKeyRepositoryDeleteTests.cs


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