本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# List.IndexOf方法的具体用法?C# List.IndexOf怎么用?C# List.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.IndexOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SwapTest
public void SwapTest()
{
// Arrange
TileService service = new TileService();
ITile tile3 = new Model.Fakes.StubITile { NumberGet = () => 3 };
ITile tile7 = new Model.Fakes.StubITile { NumberGet = () => 7 };
List<ITile> tiles = new List<ITile> {
new Model.Fakes.StubITile { NumberGet =() => 1 },
new Model.Fakes.StubITile { NumberGet =() => 2 },
tile3,
new Model.Fakes.StubITile { NumberGet =() => 4 },
new Model.Fakes.StubITile { NumberGet =() => 5 },
new Model.Fakes.StubITile { NumberGet =() => 6 },
tile7,
new Model.Fakes.StubITile { NumberGet =() => 8 },
new Model.Fakes.StubITile { NumberGet =() => 9 },
};
int tile3Pos = tiles.IndexOf(tile3);
int tile7Pos = tiles.IndexOf(tile7);
// Act
service.Swap(tiles, tile3, tile7);
// Assert
Assert.IsTrue(tiles[tile7Pos] == tile3);
Assert.IsTrue(tiles[tile3Pos] == tile7);
}
示例2: If_I_Try_To_Swap_Only_Two_Letters
public void If_I_Try_To_Swap_Only_Two_Letters()
{
IList<char> letters = new List<char> { 'z', 'h', };
letters.Swap<char>(0, 1);
Assert.IsTrue(letters.IndexOf('z') == 1);
Assert.IsTrue(letters.IndexOf('h') == 0);
}
示例3: TestStringValueAttributeGetAll
public void TestStringValueAttributeGetAll()
{
TestClass2 item = new TestClass2(7, "test", 0);
string[] values = StringValueAttribute.GetAll(() => item.Id);
Assert.IsNotNull(values);
List<string> list = new List<string>(values);
Assert.IsTrue(list.IndexOf("IdTest1") >= 0);
Assert.IsTrue(list.IndexOf("IdTest2") >= 0);
Assert.IsTrue(list.IndexOf("IdTest3") >= 0);
}
示例4: TestAttributeUtilGetAllAsString
public void TestAttributeUtilGetAllAsString()
{
TestClass2 item = new TestClass2(7, "test", 0);
string[] values = AttributeUtil.GetAllAsString(() => item.Id, typeof(StringValueAttribute), "Value");
Assert.IsNotNull(values);
Assert.AreEqual(3, values.Length);
List<string> list = new List<string>(values);
Assert.IsTrue(list.IndexOf("IdTest1") >= 0);
Assert.IsTrue(list.IndexOf("IdTest2") >= 0);
Assert.IsTrue(list.IndexOf("IdTest3") >= 0);
}
示例5: TestAttributeUtilGetAll
public void TestAttributeUtilGetAll()
{
TestClass2 item = new TestClass2(7, "test", 0);
object[] objvalues = AttributeUtil.GetAll(() => item.Id, typeof(StringValueAttribute), "Value");
Assert.IsNotNull(objvalues);
List<string> values = new List<string>();
foreach (object obj in objvalues)
{
values.Add((string)obj);
}
Assert.IsTrue(values.IndexOf("IdTest1") >= 0);
Assert.IsTrue(values.IndexOf("IdTest2") >= 0);
Assert.IsTrue(values.IndexOf("IdTest3") >= 0);
}
示例6: PrintPath
// for debug
public string PrintPath(int[,] grid, List<Point> path)
{
var sb = new StringBuilder();
for (int y = 0; y < grid.GetLength(1); y++)
{
for (int x = 0; x < grid.GetLength(0); x++)
{
if (path.Contains(new Point(x, y)))
{
var symbol = (path.IndexOf(new Point(x, y)) + 1) % 10;
sb.Append(symbol);
}
else if (grid[x, y] != 0)
{
sb.Append('#');
}
else
{
sb.Append('-');
}
}
sb.AppendLine();
}
return sb.ToString();
}
示例7: DoubleListTest
public void DoubleListTest()
{
var list = new List<double>();
list.Add(10.1213131);
list.Add(-4315.41412);
Assert.IsFalse(list.Contains(10));
Assert.AreEqual(10.1213131, list.GetElement(1));
Assert.AreEqual(0, list.IndexOf(-4315.41412));
}
示例8: NeutralLossListTest
public void NeutralLossListTest()
{
TestSmallMolecules = false; // No concept of neutral loss for small molecules
var phosphoLossMod = new StaticMod("Phospho Loss", "S, T, Y", null, false, "HPO3",
LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), });
SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangePeptideModifications(mods =>
mods.ChangeStaticModifications(new List<StaticMod>(mods.StaticModifications) { phosphoLossMod })));
IdentityPath path = IdentityPath.ROOT;
SrmDocument docFasta = document.ImportFasta(new StringReader(TEXT_FASTA_YEAST_7), false, path, out path);
Assert.AreEqual(0, GetLossCount(docFasta, 1));
// Insert losses into the first transition group
var pathPeptide = docFasta.GetPathTo((int) SrmDocument.Level.Molecules, 0);
var nodePep = (PeptideDocNode) docFasta.FindNode(pathPeptide);
var nodeGroup = (TransitionGroupDocNode) nodePep.Children[0];
var listChildren = new List<DocNode>(nodeGroup.Children);
foreach (var nodeTran in nodeGroup.GetTransitions(docFasta.Settings,
nodePep.ExplicitMods, nodeGroup.PrecursorMz, null, null, null, false))
{
if (!nodeTran.HasLoss)
continue;
var tran = nodeTran.Transition;
int matchIndex = listChildren.IndexOf(node =>
Equals(tran, ((TransitionDocNode)node).Transition));
if (matchIndex == -1)
continue;
while (matchIndex < listChildren.Count &&
Equals(tran, ((TransitionDocNode)listChildren[matchIndex]).Transition))
{
matchIndex++;
}
listChildren.Insert(matchIndex, nodeTran);
}
var docLosses = (SrmDocument) docFasta.ReplaceChild(pathPeptide,
nodeGroup.ChangeChildren(listChildren));
int lossCount = GetLossCount(docLosses, 1);
Assert.IsTrue(lossCount > 0);
var docRoundTripped = AssertEx.RoundTripTransitionList(new ThermoMassListExporter(docLosses));
Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1));
docRoundTripped = AssertEx.RoundTripTransitionList(new AgilentMassListExporter(docLosses));
Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1));
}
示例9: Sort_TwoDescription_ActualProperties
public void Sort_TwoDescription_ActualProperties ()
{
List<Rectangle> rects = new List<Rectangle> {
new Rectangle { Width = 10, Height = 10 },
new Rectangle { Width = 10, Height = 20 },
new Rectangle { Width = 20, Height = 10 },
new Rectangle { Width = 20, Height = 20 }
};
using (Source.DeferRefresh ()) {
Source.Source = rects;
Source.GroupDescriptions.Add (new ConcretePropertyGroupDescription {
GroupNameFromItemFunc = (item, level, culture) => rects.IndexOf ((Rectangle)item) < 2 ? "A" : "B"
});
Source.SortDescriptions.Add (new SortDescription ("Width", ListSortDirection.Descending));
Source.SortDescriptions.Add (new SortDescription ("Height", ListSortDirection.Ascending));
}
// Check the first group
var group = (CollectionViewGroup) Source.View.Groups [0];
Assert.AreSame (rects [2], group.Items [0], "#1");
Assert.AreSame (rects [3], group.Items [1], "#2");
// Check the second group
group = (CollectionViewGroup) Source.View.Groups [1];
Assert.AreSame (rects [0], group.Items [0], "#3");
Assert.AreSame (rects [1], group.Items [1], "#4");
}
示例10: Group_IndexOf
public void Group_IndexOf()
{
List<Rectangle> rects = new List<Rectangle> {
new Rectangle { Width = 10, Height = 10 },
new Rectangle { Width = 10, Height = 20 },
new Rectangle { Width = 20, Height = 10 },
new Rectangle { Width = 20, Height = 20 }
};
SetSource(rects);
using (Source.DeferRefresh ()) {
Source.GroupDescriptions.Add (new ConcretePropertyGroupDescription {
GroupNameFromItemFunc = (item, level, culture) => rects.IndexOf ((Rectangle)item) < 2 ? "A" : "B"
});
Source.SortDescriptions.Add (new SortDescription ("Width", ListSortDirection.Descending));
Source.SortDescriptions.Add (new SortDescription ("Height", ListSortDirection.Ascending));
}
Assert.AreSame (rects [2], View.Cast<object>().ElementAt(0), "#1");
Assert.AreSame(rects[3], View.Cast<object>().ElementAt(1), "#2");
Assert.AreSame(rects[0], View.Cast<object>().ElementAt(2), "#3");
Assert.AreSame(rects[1], View.Cast<object>().ElementAt(3), "#4");
}
示例11: IndexOf
public void IndexOf()
{
List<int> stuff = new List<int>();
stuff.AddRange(5, 6, 7, 8);
int index = stuff.IndexOf((n) => n > 6);
Assert.AreEqual(2, index);
index = stuff.IndexOf((n) => n > 100);
Assert.AreEqual(-1, index);
}
示例12: IndexOf_IndexOfElementNotIncludedInCollection_IsProperlyObtained
public void IndexOf_IndexOfElementNotIncludedInCollection_IsProperlyObtained()
{
var list = new List<int>();
for (var i = 0; i < 10; i++)
list.Add(i);
Assert.AreEqual(-1, list.IndexOf(34));
}
示例13: IndexOf_ElementIsProperlyObtainedByIndex
public void IndexOf_ElementIsProperlyObtainedByIndex()
{
var list = new List<int>();
for (var i = 0; i < 10; i++)
list.Add(i);
Assert.AreEqual(5, list.IndexOf(5));
}
示例14: CompareHookLists
private bool CompareHookLists(List<Hook> expected, List<Hook> actual)
{
return
expected == actual ||
(expected.Count == actual.Count &&
expected.TrueForAll(e => CompareHooks(e, actual[expected.IndexOf(e)])));
}
示例15: AssertTopologicallySorted
private void AssertTopologicallySorted(
Dictionary<string, List<string>> graph,
List<string> sortedNodes)
{
foreach (var node in graph)
{
foreach (var childNode in node.Value)
{
int nodeIndex = sortedNodes.IndexOf(node.Key);
int childIndex = sortedNodes.IndexOf(childNode);
Assert.IsTrue(
nodeIndex != -1,
"Node " + node.Key + " not found.");
Assert.IsTrue(
childIndex != -1,
"Node " + childNode + " not found.");
Assert.IsTrue(
nodeIndex < childIndex,
"Node " + node.Key + " should come before " + childNode);
}
}
}