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


C# List.IndexOf方法代码示例

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


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

示例1: TestIndexOfElement

        public void TestIndexOfElement()
        {
            // Arrange.
            IEnumerable<int> list = new List<int> { 1, 2, 3 };

            // Assert.
            Assert.AreEqual(0, list.IndexOf(1));
            Assert.AreEqual(2, list.IndexOf(3));
            Assert.AreEqual(-1, list.IndexOf(5));
        }
开发者ID:ComanGames,项目名称:unity-query,代码行数:10,代码来源:CollectionsTests.cs

示例2: Sorting_Strings_WorksCorrectly

        public void Sorting_Strings_WorksCorrectly()
        {
            var first = new ComparableSemanticType<string>("A");
            var second = new ComparableSemanticType<string>("B");
            var third = new ComparableSemanticType<string>("C");

            var list = new List<ComparableSemanticType<string>>()
            {
                second, third, first
            };
            list.Sort();

            Assert.That(list.IndexOf(first) == 0);
            Assert.That(list.IndexOf(second) == 1);
            Assert.That(list.IndexOf(third) == 2);
        }
开发者ID:JessieArr,项目名称:SimpleSemanticTypes,代码行数:16,代码来源:ComparableSemanticTypeTests.cs

示例3: Sorting_Ints_WorksCorrectly

        public void Sorting_Ints_WorksCorrectly()
        {
            var first = new ComparableSemanticType<int>(0);
            var second = new ComparableSemanticType<int>(1);
            var third = new ComparableSemanticType<int>(2);

            var list = new List<ComparableSemanticType<int>>()
            {
                second, third, first
            };
            list.Sort();

            Assert.That(list.IndexOf(first) == 0);
            Assert.That(list.IndexOf(second) == 1);
            Assert.That(list.IndexOf(third) == 2);
        }
开发者ID:JessieArr,项目名称:SimpleSemanticTypes,代码行数:16,代码来源:ComparableSemanticTypeTests.cs

示例4: Init

        public void Init()
        {
            var taskList = new List<AttemptChainTaskHandler<int>>();

            for (var i = 0; i < _taskCount; i++)
            {
                var newTask = new AttemptChainTaskHandler<int>(new DemoAttemptChainTask() { Index = i });
                taskList.Add(newTask);
            }

            foreach (var task in taskList.Where(task => taskList.IndexOf(task) != taskList.IndexOf(taskList.Last())))
            {
                task.RegisterNext(taskList[taskList.IndexOf(task) + 1]);
            }

            _tasks = taskList;
        }
开发者ID:Xamarui,项目名称:Merchello,代码行数:17,代码来源:ConceptPipelineTests.cs

示例5: TestIndexOfPredicate

        public void TestIndexOfPredicate()
        {
            // Arrange.
            IEnumerable<int> list = new List<int> { 1, 2, 3 };

            // Assert.
            Assert.AreEqual(2, list.IndexOf(i => i > 2));
        }
开发者ID:ComanGames,项目名称:unity-query,代码行数:8,代码来源:CollectionsTests.cs

示例6: TestIndexOf

		public void TestIndexOf ()
		{
			List<int> l = new List<int>();

			l.Add (100);
			l.Add (200);

			Assert ("Could not find value", l.IndexOf (200) == 1);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:9,代码来源:ListTest.cs

示例7: list_test

        public void list_test()
        {
            List<int> list = new List<int>();
            list.Add(100);
            list.Add(101);
            list.Add(102);

            int i = list.IndexOf(101);
            Assert.AreEqual(1, i);
        }
开发者ID:sttema,项目名称:Battle_City,代码行数:10,代码来源:Map_UnitTest.cs

示例8: TestSortPluginNames

 public void TestSortPluginNames()
 {
     List<string> orderBy = new List<string> { "A", "B", "C" };
     List<string> pluginNames = new List<string> { "C", "X", "B", "A" };
     Func<string, int> keyFunc = x => orderBy.IndexOf(x);
     PluginLoader.SortPluginNames(pluginNames, keyFunc);
     Assert.AreEqual("A", pluginNames[0]);
     Assert.AreEqual("B", pluginNames[1]);
     Assert.AreEqual("C", pluginNames[2]);
     Assert.AreEqual("X", pluginNames[3]);
 }
开发者ID:CoastalResilienceNetwork,项目名称:GeositeFramework,代码行数:11,代码来源:PluginLoaderTests.cs

示例9: TestSortPluginNamesWithStripPluginModule

 public void TestSortPluginNamesWithStripPluginModule()
 {
     List<string> orderBy = new List<string> { "A", "B", "C" };
     List<string> pluginNames = new List<string> { "plugin/C", "plugin/X", "sample_plugin/B", "plugin/A" };
     Func<string, int> keyFunc = x => orderBy.IndexOf(PluginLoader.StripPluginModule(x));
     PluginLoader.SortPluginNames(pluginNames, keyFunc);
     Assert.AreEqual("plugin/A", pluginNames[0]);
     Assert.AreEqual("sample_plugin/B", pluginNames[1]);
     Assert.AreEqual("plugin/C", pluginNames[2]);
     Assert.AreEqual("plugin/X", pluginNames[3]);
 }
开发者ID:CoastalResilienceNetwork,项目名称:GeositeFramework,代码行数:11,代码来源:PluginLoaderTests.cs

示例10: TestOutOfRange

		public void TestOutOfRange ()
		{
			List<int> l = new List<int> (4);

			bool errorThrown = false;
			try {
				l.IndexOf (0, 0, 4);
			} catch (ArgumentOutOfRangeException){
				errorThrown = true;
			}
			Assert ("Out of range count exception not thrown", errorThrown);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:12,代码来源:ListTest.cs

示例11: AllNodesAreCoveredDuringIteration

        public void AllNodesAreCoveredDuringIteration()
        {
            var nodeArray = new List<Node>();
            for (var i = 0; i < 5; ++i)
            {
                var node = new MockNode();
                nodeArray.Add(node);
                _nodes.Add(node);
            }

            for (var node = _nodes.Head; node != null; node = node.Next)
            {
                var index = nodeArray.IndexOf(node);
                nodeArray.RemoveAt(index);
            }
            Assert.AreEqual(0, nodeArray.Count);
        }
开发者ID:kinlam,项目名称:RUN-SHOOT,代码行数:17,代码来源:NodeListTests.cs

示例12: TestListOperation

        public void TestListOperation()
        {
            List<IPEndPoint> endpointList = new List<IPEndPoint>();
            IPEndPoint endpoint1 = CreateEndPoint("192.10.10.98", 1);
            IPEndPoint endpoint2 = CreateEndPoint("192.10.10.99", 2);
            IPEndPoint endpoint3 = CreateEndPoint("192.10.10.100", 3);
            endpointList.Add(endpoint1);
            endpointList.Add(endpoint2);
            endpointList.Add(endpoint3);

            IPEndPoint wanted = CreateEndPoint("192.10.10.99", 2);
            int position = endpointList.IndexOf(wanted);
            Assert.AreEqual(1, position);
            Assert.AreNotSame(wanted, endpointList[position]);
            Assert.IsTrue(endpointList[position].Equals(wanted));

            endpointList.Remove(wanted);
            CollectionAssert.AreEqual(new[] { endpoint1, endpoint3 }, endpointList);
        }
开发者ID:stasi009,项目名称:TestDrivenLearn,代码行数:19,代码来源:NetworkTest.cs

示例13: NodeListContainsAllMatchingEntities

        public void NodeListContainsAllMatchingEntities()
        {
            var entities = new List<EntityBase>();
            for (var i = 0; i < 5; ++i)
            {
                var entity = new EntityBase();
                entity.Add(new Vector2());
                entities.Add(entity);
                _family.NewEntity(entity);
                _family.NewEntity(new EntityBase());
            }

            var nodes = _family.NodeList;
            for (var node = nodes.Head; node != null; node = node.Next)
            {
                entities.RemoveAt(entities.IndexOf(node.Entity));
            }
            Assert.AreEqual(0, entities.Count);
        }
开发者ID:kinlam,项目名称:RUN-SHOOT,代码行数:19,代码来源:ComponentMatchingFamilyTests.cs

示例14: CombinesDataBlocks

        public void CombinesDataBlocks(
            [Values(100, 500, 1000, 5000)] double blockMilliseconds,
            [Values(5000, 10000)] double sampleRateHz,
            [Values(1, 4)] int numStim
            )
        {
            var parameters = new Dictionary<string, object>();
            var sampleRate = new Measurement((decimal)sampleRateHz, "Hz");

            var data = new List<IOutputData>();
            var stimuli = new List<IStimulus>();
            for (int i = 0; i < numStim; i++)
            {
                IOutputData d = new OutputData(Enumerable.Range(0, (int)TimeSpan.FromSeconds(3).Samples(new Measurement((decimal)sampleRateHz, "Hz")))
                    .Select(j => new Measurement(j, "units")).ToList(),
                    sampleRate,
                    false);
                data.Add(d);
                stimuli.Add(new RenderedStimulus((string)"RenderedStimulus" + i, (IDictionary<string, object>)parameters, d));
            }

            var combined = new CombinedStimulus("CombinedStimulus", new Dictionary<string, object>(),  stimuli, CombinedStimulus.Add);

            var blockSpan = TimeSpan.FromMilliseconds(blockMilliseconds);
            IEnumerator<IOutputData> iter = combined.DataBlocks(blockSpan).GetEnumerator();
            while (iter.MoveNext())
            {
                IOutputData expectedData = null;
                foreach (var d in data.ToList())
                {
                    var cons = d.SplitData(blockSpan);
                    data[data.IndexOf(d)] = cons.Rest;

                    expectedData = expectedData == null
                        ? cons.Head
                        : expectedData.Zip(cons.Head, (m1, m2) => new Measurement(m1.QuantityInBaseUnits + m2.QuantityInBaseUnits, 0, m1.BaseUnits));
                }

                Assert.That(iter.Current.Duration, Is.EqualTo(expectedData.Duration));
                Assert.That(iter.Current.Data, Is.EqualTo(expectedData.Data));
            }
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:42,代码来源:StimulusTests.cs

示例15: RemovingCurrentNodeDuringIterationIsValid

        public void RemovingCurrentNodeDuringIterationIsValid()
        {
            var nodeArray = new List<Node>();
            for (var i = 0; i < 5; ++i)
            {
                var node = new MockNode();
                nodeArray.Add(node);
                _nodes.Add(node);
            }
			
            var count = 0;
            for (var node = _nodes.Head; node != null; node = node.Next)
            {
                var index = nodeArray.IndexOf(node);
                nodeArray.RemoveAt(index);
                if (++count == 2)
                {
                    _nodes.Remove(node);
                }
            }
            Assert.AreEqual(0, nodeArray.Count);
        }
开发者ID:Aranda,项目名称:Ash.NET,代码行数:22,代码来源:NodeListTests.cs


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