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


C# List.Clear方法代码示例

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


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

示例1: TestFeatureGeneration

        public void TestFeatureGeneration() {
            var fg = new PreviousMapFeatureGenerator();

            var sentence = new[] {"a", "b", "c"};

            var features = new List<string>();

            // this should generate the pd=null feature
            fg.CreateFeatures(features, sentence, 0, null);
            Assert.AreEqual(1, features.Count);
            Assert.AreEqual("pd=null", features[0]);

            features.Clear();

            // this should generate the pd=1 feature
            fg.UpdateAdaptiveData(sentence, new[] {"1", "2", "3"});
            fg.CreateFeatures(features, sentence, 0, null);
            Assert.AreEqual(1, features.Count);
            Assert.AreEqual("pd=1", features[0]);

            features.Clear();

            // this should generate the pd=null feature again after
            // the adaptive data was cleared
            fg.ClearAdaptiveData();
            fg.CreateFeatures(features, sentence, 0, null);
            Assert.AreEqual(1, features.Count);
            Assert.AreEqual("pd=null", features[0]);
        }
开发者ID:lovethisgame,项目名称:SharpNL,代码行数:29,代码来源:PreviousMapFeatureGeneratorTest.cs

示例2: findNeigboursForNodeBorderCasesTest

 public void findNeigboursForNodeBorderCasesTest()
 {
     testNetwork.initialize (3, 3);
     map = testNetworkProbe.getField ("networkMap") as NodeController[,];
     List<Vector2> neighbourList = new List<Vector2> ();
     INode testNode = map [0, 0];
     MethodInfo findNeigboursForNode = testNetworkProbe.getMethod ("findNeigboursForNode");
     findNeigboursForNode.Invoke(testNetwork, new object[]{testNode,neighbourList});
     Assert.AreNotEqual(0,neighbourList.Count);
     Assert.AreEqual (3, neighbourList.Count);
     //Mid left
     neighbourList.Clear ();
     testNode = map [0, 1];
     findNeigboursForNode.Invoke(testNetwork, new object[]{testNode,neighbourList});
     Assert.AreEqual (5, neighbourList.Count);
     //Top Mid
     neighbourList.Clear ();
     testNode = map [1, 2];
     findNeigboursForNode.Invoke(testNetwork, new object[]{testNode,neighbourList});
     Assert.AreEqual (5, neighbourList.Count);
     //Top Right
     testNode = map [2, 2];
     findNeigboursForNode.Invoke(testNetwork, new object[]{testNode,neighbourList});
     Assert.AreEqual (3, neighbourList.Count);
 }
开发者ID:Greg-Rus,项目名称:Linker,代码行数:25,代码来源:NodeTest.cs

示例3: Constructor_Exceptions

		public void Constructor_Exceptions ()
		{
			HostFileChangeMonitor monitor;
			string relPath = Path.Combine ("relative", "file", "path");
			var paths = new List<string> {
				relPath
			};

			AssertExtensions.Throws<ArgumentException> (() => {
				monitor = new HostFileChangeMonitor (paths);
			}, "#A1");

			paths.Clear ();
			paths.Add (null);
			AssertExtensions.Throws<ArgumentException> (() => {
				monitor = new HostFileChangeMonitor (paths);
			}, "#A2");

			paths.Clear ();
			paths.Add (String.Empty);
			AssertExtensions.Throws<ArgumentException> (() => {
				monitor = new HostFileChangeMonitor (paths);
			}, "#A3");

			AssertExtensions.Throws<ArgumentNullException> (() => {
				monitor = new HostFileChangeMonitor (null);
			}, "#A4");

			paths.Clear ();
			AssertExtensions.Throws<ArgumentException> (() => {
				monitor = new HostFileChangeMonitor (paths);
			}, "#A5");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:33,代码来源:HostFileChangeMonitorTest.cs

示例4: Join_with_multiple_correlationIds

        public void Join_with_multiple_correlationIds()
        {
            var sut = new ManualResetJoin(2);

            var results = new List<List<object>>();
            Action<List<object>> onJoin = results.Add;

            var corrId1 = Guid.NewGuid();
            var corrId2 = Guid.NewGuid();

            sut.Process(0, "a1", corrId1, onJoin);
            sut.Process(0, "x1", corrId2, onJoin);
            sut.Process(1, "b1", corrId1, onJoin);
            Assert.That(new object[] { new object[] { "a1", "b1" } }, Is.EqualTo(results));
            results.Clear();

            sut.Process(1, "y1", corrId2, onJoin);
            Assert.That(new object[] { new object[] { "x1", "y1" } }, Is.EqualTo(results));
            results.Clear();

            sut.Process(1, "b2", corrId1, onJoin);
            Assert.That(new object[] { new object[] { "a1", "b2" } }, Is.EqualTo(results));
            results.Clear();

            sut.Reset(corrId2);
            sut.Process(0, "s1", corrId2, onJoin);
            sut.Process(1, "t1", corrId2, onJoin);
            Assert.That(new object[] { new object[] { "s1", "t1" } }, Is.EqualTo(results));
        }
开发者ID:kennychou0529,项目名称:NPantaRhei,代码行数:29,代码来源:test_ManualResetJoin.cs

示例5: Can_Mock_UploadFile

        public void Can_Mock_UploadFile()
        {
            string tempTextPath = Path.Combine (Path.GetTempPath (), "test.txt");
            using (File.CreateText(tempTextPath)){}

            var fileNamesUploaded = new List<string>();
            using (new HttpResultsFilter
            {
                UploadFileFn = (webReq, stream, fileName) => fileNamesUploaded.Add(fileName)
            })
            {
                ExampleGoogleUrl.PostFileToUrl(new FileInfo(tempTextPath), "text/plain");
                Assert.That(fileNamesUploaded, Is.EquivalentTo(new[] { "test.txt" }));

                fileNamesUploaded.Clear();

                ExampleGoogleUrl.PutFileToUrl(new FileInfo(tempTextPath), "text/plain");
                Assert.That(fileNamesUploaded, Is.EquivalentTo(new[] { "test.txt" }));

                fileNamesUploaded.Clear();

                var webReq = WebRequest.Create(ExampleGoogleUrl);
                webReq.UploadFile(new FileInfo(tempTextPath), "text/plain");
                Assert.That(fileNamesUploaded, Is.EquivalentTo(new[] { "test.txt" }));
            }
        }
开发者ID:GavinHwa,项目名称:ServiceStack.Text,代码行数:26,代码来源:HttpUtilsMockTests.cs

示例6: Find

        public void Find()
        {
            var list = new List<int>();
            list.AddRange(new[] { 3, 4, 76, 34, 50, 23, 45 });

            var visitor = new ComparableFindingVisitor<int>(50);

            list.AcceptVisitor(visitor);
            Assert.IsTrue(visitor.Found);
            Assert.IsTrue(visitor.HasCompleted);

            visitor = new ComparableFindingVisitor<int>(50);
            list.Clear();
            list.AddRange(new[] { 50, 3, 4, 76, 34, 23, 45 });

            list.AcceptVisitor(visitor);
            Assert.IsTrue(visitor.Found);
            Assert.IsTrue(visitor.HasCompleted);

            visitor = new ComparableFindingVisitor<int>(50);
            list.Clear();
            list.AddRange(new[] { 3, 4, 76, 34, 23, 45, 50 });

            list.AcceptVisitor(visitor);
            Assert.IsTrue(visitor.Found);
            Assert.IsTrue(visitor.HasCompleted);

            visitor = new ComparableFindingVisitor<int>(50);
            list.Clear();
            list.AddRange(new[] { 3, 4, 76, 34, 23, 45 });

            list.AcceptVisitor(visitor);
            Assert.IsFalse(visitor.Found);
            Assert.IsFalse(visitor.HasCompleted);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:35,代码来源:Visit.cs

示例7: Customer_data_annotation_test

        public void Customer_data_annotation_test()
        {
            Customer cus = new Customer();
            var context = new ValidationContext(cus, serviceProvider: null, items: null);
            var results = new List<ValidationResult>();
            var isValid = Validator.TryValidateObject(cus, context, results, true);

            Assert.IsTrue(results.Any(x => x.ErrorMessage == "First Name is required"));
            Assert.IsTrue(results.Any(x => x.ErrorMessage == "Email is required"));
            Assert.IsTrue(results.Any(x => x.ErrorMessage == "Address is required"));
            Assert.IsTrue(results.Any(x => x.ErrorMessage == "Last Name is required"));
            Assert.IsTrue(results.Any(x => x.ErrorMessage == "Phone Number is required"));

            cus.FirstName = "Jonas";
            cus.LastName = "Olesen";
            cus.Email = "[email protected]";
            cus.Address = new Address();
            cus.PhoneNumber = "22755692";

            results.Clear();
            isValid = Validator.TryValidateObject(cus, context, results, true);

            Assert.IsEmpty(results);

            results.Clear();

            cus.Email = "asdasd";
            cus.PhoneNumber = "aasdakp";
            isValid = Validator.TryValidateObject(cus, context, results, true);

            Assert.IsTrue(results.Any(x => x.ErrorMessage == "The Phone Number field is not a valid phone number."));
            Assert.IsTrue(results.Any(x => x.ErrorMessage == "The Email field is not a valid e-mail address."));
        }
开发者ID:nordtorp95,项目名称:ExamProject2015,代码行数:33,代码来源:CustomerTest.cs

示例8: Test_TryGetCommonRootDirectory

        public void Test_TryGetCommonRootDirectory()
        {
            DirectoryPathAbsolute commonRootDirectory = null;

             // Test when list is null or empty
             Assert.IsFalse(ListOfPathHelper.TryGetCommonRootDirectory(null, out commonRootDirectory));

             List<DirectoryPathAbsolute> list = new List<DirectoryPathAbsolute>();
             Assert.IsFalse(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));

             // Test when only one dir
             list.Add(new DirectoryPathAbsolute(@"C:\File"));
             Assert.IsTrue(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));
             Assert.IsTrue(commonRootDirectory.Path == @"C:\File");

             // Test when all dir are the same
             list.Add(new DirectoryPathAbsolute(@"C:\File"));
             list.Add(new DirectoryPathAbsolute(@"C:\File"));
             Assert.IsTrue(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));
             Assert.IsTrue(commonRootDirectory.Path == @"C:\File");

             // Test when a dir has a wrong drive
             list.Add(new DirectoryPathAbsolute(@"D:\File"));
             Assert.IsFalse(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));

             // Test when the list contains a null or empty dir
             list.Clear();
             list.Add(new DirectoryPathAbsolute(@"C:\File"));
             list.Add(null);
             Assert.IsFalse(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));

             list.Clear();
             list.Add(new DirectoryPathAbsolute(@"C:\File"));
             list.Add(DirectoryPathAbsolute.Empty);
             Assert.IsFalse(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));

             // Test when the common root dir is in the list
             list.Clear();
             list.Add(new DirectoryPathAbsolute(@"C:\File\Debug"));
             list.Add(new DirectoryPathAbsolute(@"C:\File\Debug\Dir1\Dir2"));
             list.Add(new DirectoryPathAbsolute(@"C:\File\Debug\Dir1\Dir2\Dir3"));
             Assert.IsTrue(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));
             Assert.IsTrue(commonRootDirectory.Path == @"C:\File\Debug");

             list.Add(new DirectoryPathAbsolute(@"C:\File"));
             Assert.IsTrue(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));
             Assert.IsTrue(commonRootDirectory.Path == @"C:\File");

             list.Add(new DirectoryPathAbsolute(@"C:"));
             Assert.IsTrue(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));
             Assert.IsTrue(commonRootDirectory.Path == @"C:");

             // Test when the common root dir is not in the list
             list.Clear();
             list.Add(new DirectoryPathAbsolute(@"C:\File\Debug\Dir4"));
             list.Add(new DirectoryPathAbsolute(@"C:\File\Debug\Dir1\Dir2\Dir3"));
             Assert.IsTrue(ListOfPathHelper.TryGetCommonRootDirectory(list, out commonRootDirectory));
             Assert.IsTrue(commonRootDirectory.Path == @"C:\File\Debug");
        }
开发者ID:curasystems,项目名称:externals,代码行数:59,代码来源:PathHelper.cs

示例9: GenerateTestData

        public static void GenerateTestData()
        {
            foreach (var name in _loader.AssetNames)
            {
                var pset = _loader.GetAsset(name).Polygons;

                var lines = new List<string>();
                var indices = new List<int>();

                foreach (WindingRule winding in Enum.GetValues(typeof(WindingRule)))
                {
                    var tess = new Tess();
                    PolyConvert.ToTess(pset, tess);
                    tess.Tessellate(winding, ElementType.Polygons, 3);

                    lines.Add(string.Format("{0} {1}", winding, 3));
                    for (int i = 0; i < tess.ElementCount; i++)
                    {
                        indices.Clear();
                        for (int j = 0; j < 3; j++)
                        {
                            int index = tess.Elements[i * 3 + j];
                            indices.Add(index);
                        }
                        lines.Add(string.Join(" ", indices));
                    }
                    lines.Add("");
                }

                File.WriteAllLines(Path.Combine(TestDataPath, name + ".testdat"), lines);
            }
        }
开发者ID:speps,项目名称:LibTessDotNet,代码行数:32,代码来源:UnitTests.cs

示例10: TestAllPossibleFourOfAKindHands

        public void TestAllPossibleFourOfAKindHands()
        {
            IList<ICard> fourOfAKindCollection = new List<ICard>();
            byte countOfAllValues = 13;
            byte countOfAllKinds = 4;
            Hand playerHand;
            List<bool> results = new List<bool>();
            int faceOfAdditionalCard;

            for (int i = 0; i < countOfAllValues; i++)
            {
                faceOfAdditionalCard = i;

                for (int j = 1; j <= countOfAllKinds; j++)
                {
                    fourOfAKindCollection.Add(new Card((CardFace)i + 2, (CardSuit)j));
                }

                if (faceOfAdditionalCard + 3 > 14)
                {
                    faceOfAdditionalCard = 2;
                }

                fourOfAKindCollection.Add(new Card((CardFace)faceOfAdditionalCard + 3, CardSuit.Hearts));
                playerHand = new Hand(fourOfAKindCollection);

                results.Add(this.checker.IsFourOfAKind(playerHand));

                fourOfAKindCollection.Clear();
            }

            byte countOfAllTrueResults = (byte)results.Count(res => res == true);

            Assert.AreEqual(results.Count, countOfAllTrueResults);
        }
开发者ID:viktorD1m1trov,项目名称:T-Academy,代码行数:35,代码来源:PokerHandsCheckerTest.cs

示例11: AssertSequencePattern

        public void AssertSequencePattern()
        {
            var dummy = new DummySequencer();
            var goalDistance = 3;
            var lastTrainingDistance = 2;
            var lastRestituteDistance = 0;
            var repeat = 1;
            var e = new SimpleGoaledSequencer<int>(goalDistance, lastTrainingDistance, lastRestituteDistance, repeat, Comparer<int>.Default, dummy);
            var distances = new List<int>();
            while (e.MoveNext())
            {
                var next = e.Current;
                distances.Add(next);
            }

            var expected = "1,2,3";
            var actual = string.Join(",", distances.ConvertAll(x => x.ToString()).ToArray());
            Assert.AreEqual(expected, actual);

            goalDistance = 5;
            repeat = 3;
            lastTrainingDistance = 4;
            expected = "1,2,3,4,4,4,5";
            distances.Clear();
            e = new SimpleGoaledSequencer<int>(goalDistance, lastTrainingDistance, lastRestituteDistance, repeat, Comparer<int>.Default, dummy);
            while (e.MoveNext())
            {
                var next = Convert.ToInt32(e.Current);
                distances.Add(next);
            }
            actual = string.Join(",", distances.ConvertAll(x => x.ToString()).ToArray());
            Assert.AreEqual(expected, actual);
        }
开发者ID:1pindsvin,项目名称:yagni,代码行数:33,代码来源:SimpleGoaledSequenceTester.cs

示例12: UserInfo_add_remove_resources

 public void UserInfo_add_remove_resources() {
     UserInfo userInfo = new UserInfo(1, "wicked");
     int resourcesChanged = 0;
     userInfo.ResourcesChanged += delegate { resourcesChanged++; };
     userInfo.AddResource(1, "0");
     Assert.AreEqual(1, resourcesChanged);
     Assert.AreEqual(1, userInfo.Resources.Length);
     Assert.AreEqual(1, userInfo.Resources[0].Item1);
     userInfo.AddResource(2, "0");
     userInfo.AddResource(3, "0");
     userInfo.AddResource(4, "0");
     Assert.AreEqual(4, resourcesChanged);
     Assert.AreEqual(4, userInfo.Resources.Length);
     List<uint> resources = new List<uint>();
     foreach(Tuplet<uint, string> tuple in userInfo.Resources) {
         resources.Add(tuple.Item1);
     }
     Assert.IsTrue(resources.Contains(2));
     userInfo.RemoveResource(2);
     Assert.AreEqual(5, resourcesChanged);
     Assert.AreEqual(3, userInfo.Resources.Length);
     resources.Clear();
     foreach(Tuplet<uint, string> tuple in userInfo.Resources) {
         resources.Add(tuple.Item1);
     }
     Assert.IsFalse(resources.Contains(2));
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:27,代码来源:UserInfoTests.cs

示例13: SetUp

        public void SetUp()
        {
            _scheduler = new ManualTaskScheduler();
            _entries = new List<LogLine>();
            _logFile = new Mock<ILogFile>();
            _logFile.Setup(x => x.GetSection(It.IsAny<LogFileSection>(), It.IsAny<LogLine[]>()))
                    .Callback(
                        (LogFileSection section, LogLine[] entries) =>
                        _entries.CopyTo((int)section.Index, entries, 0, section.Count));
            _logFile.Setup(x => x.AddListener(It.IsAny<ILogFileListener>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
                    .Callback((ILogFileListener listener, TimeSpan unused, int max) =>
                        {
                            for (int i = 0; i < _entries.Count/max+1; ++i)
                            {
                                int from = i*max;
                                int to = Math.Min((i + 1)*max, _entries.Count);
                                listener.OnLogFileModified(_logFile.Object, new LogFileSection(from, to - from));
                            }
                        });
            _logFile.Setup(x => x.GetLine(It.IsAny<int>())).Returns((int index) => _entries[index]);
            _logFile.Setup(x => x.Count).Returns(() => _entries.Count);
            _logFile.Setup(x => x.EndOfSourceReached).Returns(true);

            _matches = new List<LogMatch>();
            _listener = new Mock<ILogFileSearchListener>();
            _listener.Setup(x => x.OnSearchModified(It.IsAny<ILogFileSearch>(), It.IsAny<List<LogMatch>>()))
                     .Callback((ILogFileSearch sender, IEnumerable<LogMatch> matches) =>
                         {
                             _matches.Clear();
                             _matches.AddRange(matches);
                         });
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:32,代码来源:LogFileSearchTest.cs

示例14: TestDuplicateUnbinding

        public void TestDuplicateUnbinding()
        {
            Binder binder = new Binder();

            binder.Bind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));
            binder.Bind(new SampleEvent1 { Foo = 2 }, new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1));

            binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));
            binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));

            List<Handler> handlerChain = new List<Handler>();

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, handlerChain));
            Assert.AreEqual(1, binder.BuildHandlerChain(new SampleEvent1 { Foo = 2 }, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);

            // with EventSink

            var sink = new SampleEventSink();
            sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);

            sink.Unbind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);
            sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);

            handlerChain.Clear();
            Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, handlerChain));
            Assert.AreEqual(1, binder.BuildHandlerChain(new SampleEvent1 { Foo = 2 }, handlerChain));
            Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);
        }
开发者ID:nice1378,项目名称:x2clr,代码行数:30,代码来源:BinderTests.cs

示例15: Should_allow_multiple_connections

        public void Should_allow_multiple_connections()
        {
            var clients = new List<TcpClient>();

            int expected = 100;
            for (int i = 0; i < expected - 1; i++)
            {
                var client = new TcpClient();
                clients.Add(client);

                client.Connect("localhost", 8008);
            }

            Thread.Sleep(50);

            _server.ConnectionCount.ShouldEqual(expected);

            clients.ForEach(client =>
                {
                    using (client)
                        client.Close();
                });

            clients.Clear();
        }
开发者ID:rickj33,项目名称:Stact,代码行数:25,代码来源:SocketServer_Specs.cs


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