本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# List.RemoveAt方法的具体用法?C# List.RemoveAt怎么用?C# List.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAdd
public void TestAdd()
{
const int SampleSize = 1000000;
Random Generator = new Random();
SortedList<int> Tested = new SortedList<int>();
List<int> Original = new List<int>();
for (int x = 0; x < SampleSize; x++)
{
Original.Add(x);
}
List<int> OriginalClone = new List<int>(Original.ToArray());
while (OriginalClone.Count > 0)
{
int Position = Generator.Next(0, OriginalClone.Count);
Tested.Add(OriginalClone[Position]);
OriginalClone.RemoveAt(Position);
}
if (Tested.Count != Original.Count)
{
throw new Exception("Count mismatch.");
}
for (int x = 0; x < Tested.Count; x++)
{
if (Tested[x] != Original[x])
{
throw new Exception("Order mismatch.");
}
}
}
示例2: TestAdjacent
public void TestAdjacent()
{
IMatrix<string> matrix = new Matrix<string>(3, 3);
List<string> items = new List<string>(9);
for (int i = 0; i < items.Capacity; i++)
{
items.Add(string.Format("{0}", i));
}
var index = 0;
for (int y = 0; y < matrix.Rows; y++)
{
int x;
for (x = 0; x < matrix.Columns; x++)
{
matrix[x, y] = items[index++];
}
}
var middleCell = matrix[1, 1];
int middleIndex = matrix.IndexOf(middleCell);
items.RemoveAt(middleIndex);
var adjacentCells = matrix.GetAdjacentCells(middleCell);
Assert.IsTrue(items.SequenceEqual(adjacentCells));
}
示例3: TestPartialSortAdd_GrabTopValues
public void TestPartialSortAdd_GrabTopValues()
{
Random random = new Random();
// build a list
var list = new List<int>(100);
Sublist.Generate(100, i => random.Next(100)).AddTo(list.ToSublist());
// create a list to hold the top three
const int numberOfItems = 10;
var destination = new List<int>(numberOfItems);
// store the top three results
Func<int, int, int> comparison = (x, y) => Comparer<int>.Default.Compare(y, x);
list.ToSublist().PartialSort(numberOfItems, comparison).AddTo(destination.ToSublist());
// grab the three largest values from largest to smallest
var expected = new List<int>(numberOfItems);
for (int round = 0; round != numberOfItems; ++round)
{
int maxIndex = list.ToSublist().Maximum();
expected.Add(list[maxIndex]);
list.RemoveAt(maxIndex);
}
Assert.IsTrue(expected.ToSublist().IsEqualTo(destination.ToSublist()), "The top values weren't grabbed.");
}
示例4: TestBinarySearch
public void TestBinarySearch()
{
List<string> animalsUnordered = new List<string>(
new[] { "Cat", "Dog", "Elephant", "Eagle", "Eel", "Zebra", "Yak", "Monkey", "Meerkat" });
WordList words;
while (animalsUnordered.Count > 0)
{
words = new WordList(animalsUnordered);
Assert.AreEqual(-1, words.BinarySearch("Unicorn", false, false), "Wrong index for: Unicorn");
string[] animalsOrdered = animalsUnordered.OrderBy(a => a).ToArray();
Assert.AreEqual(-1, words.BinarySearch("Dragon", false, false), "Wrong index for: Dragon");
for (int expectedIndex = 0; expectedIndex < animalsOrdered.Length; expectedIndex++)
{
string word = animalsOrdered[expectedIndex];
Assert.AreEqual(expectedIndex, words.BinarySearch(word, false, false), "Wrong index for: " + word);
}
animalsUnordered.RemoveAt(0);
}
words = new WordList(new[] { "Heaven", "Hell", "Hello", "Zebra", "ZOO" });
Assert.AreEqual(0, words.BinarySearch("H", false, true), "Wrong index for: H");
Assert.AreEqual(1, words.BinarySearch("HELL", false, true), "Wrong index for: H");
Assert.AreEqual(3, words.BinarySearch("M", true, false), "Wrong index for: M");
Assert.AreEqual(-1, words.BinarySearch("M", false, false), "Wrong index for: M");
}
示例5: CompareTo_ValidateSortingForAllPerms_Passes
public void CompareTo_ValidateSortingForAllPerms_Passes()
{
List<StartingHandCombo> copy = new List<StartingHandCombo>();
List<StartingHandCombo> sorted = new List<StartingHandCombo>();
List<StartingHandCombo> shuffled = new List<StartingHandCombo>();
foreach (StartingHandCombo h in _startingHandPermutations.Values)
{
copy.Add(h);
sorted.Add(h);
}
Random iRand = new Random();
do{
int i = iRand.Next(copy.Count - 1);
shuffled.Add(copy[i]);
copy.RemoveAt(i);
}while(copy.Count > 0);
Assert.IsFalse(EqualLists(sorted, shuffled));
shuffled.Sort();
sorted.Sort();
Assert.IsTrue(EqualLists(sorted, shuffled));
}
示例6: TestHeap_PriorityQueue
public void TestHeap_PriorityQueue()
{
Random random = new Random();
// build a random list
var list = new List<int>(100);
Sublist.Generate(100, i => random.Next(100)).AddTo(list.ToSublist());
// make a heap
list.ToSublist().MakeHeap().InPlace();
Assert.IsTrue(list.ToSublist().IsHeap(), "The list is not a heap."); // confirm we have a heap
// let's push a value onto the heap and make it the highest priority
list.Add(100);
list.ToSublist().HeapAdd();
Assert.AreEqual(100, list[0], "The value was not moved to the top of the heap.");
Assert.IsTrue(list.ToSublist().IsHeap(), "The list is not a heap.");
// now let's remove it
list.ToSublist().HeapRemove();
Assert.AreEqual(100, list[list.Count - 1], "The value not moved to the bottom of the heap.");
Assert.AreEqual(list.Count - 1, list.ToSublist().IsHeap(), "Could not find the end of the heap.");
list.RemoveAt(list.Count - 1);
Assert.IsTrue(list.ToSublist().IsHeap(), "The list is not a heap.");
// we can sort a heap
list.ToSublist().HeapSort();
Assert.IsTrue(list.ToSublist().IsSorted(), "The list was not sorted.");
}
示例7: FailedCallbackFires
public void FailedCallbackFires()
{
List<int> order = new List<int> { 1, 2, 3, 4, 5 };
List<int> errors = new List<int>();
ThrottledProcessor<int> queue = new ThrottledProcessor<int>(
100,
(int value) => { throw new InvalidOperationException("This is the message"); },
(int value) => Assert.Fail("The success path should never be called"),
(int value, Exception ex) =>
{
Assert.AreEqual("This is the message", ex.Message);
errors.Add(value);
});
foreach (int i in order)
{
queue.Add(i);
}
while (queue.Length > 0)
{
Thread.Sleep(100);
}
foreach (int expected in order)
{
int actual = errors.First();
errors.RemoveAt(0);
Assert.AreEqual(expected, actual, "The items were failed in the wrong order");
}
}
示例8: ToArray
private static int[] ToArray(int[] x, int[] y)
{
if(x.Length == 0 || y.Length == 0)
return new int[] { };
bool negative = (x[0] > 0) ^ (y[0] > 0);
x[0] = Math.Abs(x[0]);
y[0] = Math.Abs(y[0]);
List<int> result = new List<int>(new int[x.Length + y.Length]);
for(int i = x.Length - 1; i >= 0; i--)
{
for(int j = y.Length - 1; j >= 0; j--)
{
result[i + j + 1] += x[i] * y[j];
result[i + j] += result[i + j + 1] / 10;
result[i + j + 1] %= 10;
}
}
while (result.Count > 0 && result[0] == 0)
result.RemoveAt(0);
if (negative && result.Count > 0)
result[0] *= -1;
return result.ToArray();
}
示例9: PokerHandsChecker_HandWithLessThanFiveCardsShouldBeInvalid_False
public void PokerHandsChecker_HandWithLessThanFiveCardsShouldBeInvalid_False()
{
IList<ICard> currentCards = new List<ICard>(this.cards);
currentCards.RemoveAt(0);
var currentHand = new Hand(currentCards);
Assert.IsFalse(this.checker.IsValidHand(currentHand));
}
示例10: PokerHandsChecker_HandWithRepeatCardShouldBeInvalid_False
public void PokerHandsChecker_HandWithRepeatCardShouldBeInvalid_False()
{
IList<ICard> currentCards = new List<ICard>(this.cards);
currentCards.RemoveAt(0);
currentCards.Add(new Card(currentCards[0].Face, currentCards[0].Suit));
var currentHand = new Hand(currentCards);
Assert.IsFalse(this.checker.IsValidHand(currentHand));
}
示例11: SetMazeConfigurationsTest
public void SetMazeConfigurationsTest()
{
// Setup constant parameters
const int maxTimesteps = 300;
const int minSuccessDistance = 5;
// Create some dummy structures/walls
IList<MazeStructure> mazeStructures = new List<MazeStructure>
{
new MazeStructure(300, 300, 1)
{
Walls = {new MazeStructureWall(5, 5, 10, 10), new MazeStructureWall(6, 6, 11, 11)}
},
new MazeStructure(300, 300, 1)
{
Walls = {new MazeStructureWall(7, 7, 12, 12), new MazeStructureWall(8, 8, 13, 13)}
},
new MazeStructure(300, 300, 1)
{
Walls = {new MazeStructureWall(9, 9, 14, 14), new MazeStructureWall(10, 10, 15, 15)}
},
new MazeStructure(300, 300, 1)
{
Walls = {new MazeStructureWall(11, 11, 16, 16), new MazeStructureWall(12, 12, 17, 17)}
},
new MazeStructure(300, 300, 1)
{
Walls = {new MazeStructureWall(13, 13, 18, 18), new MazeStructureWall(14, 14, 19, 19)}
}
};
// Create the factory
MultiMazeNavigationWorldFactory<BehaviorInfo> factory =
new MultiMazeNavigationWorldFactory<BehaviorInfo>(maxTimesteps, minSuccessDistance);
// Attempt setting the configurations
factory.SetMazeConfigurations(mazeStructures);
// Ensure number of mazes is 2
Debug.Assert(factory.NumMazes == 5);
// Remove one of the dummy structures
mazeStructures.RemoveAt(0);
// Call again with one of the mazes removed
factory.SetMazeConfigurations(mazeStructures);
// Ensure that no longer extant maze was removed
Debug.Assert(factory.NumMazes == 4);
}
示例12: Get6Clock
// private int[] Get6Clock(int i)
// {
// return Permutation(i).
// }
private int[] Get6Clock(int n)
{
int[] dividors = { 720, 120, 24, 6, 2, 1, 1 };
List<int> numbers = new List<int>(new int[] {1,2,3,4,5,6});
int[] result = new int[5];
int index;
for (int i = 0; i < 5; i++)
{
index = (n%dividors[i])/dividors[i+1];
result[i] = numbers[index];
numbers.RemoveAt(index);
}
return result;
}
示例13: getTask
public string getTask(string[] list, int n)
{
List<string> tasks = new List<string>();
foreach (string task in list)
tasks.Add(task);
int index = 0;
while(tasks.Count > 1)
{
index = (index + n - 1) % (tasks.Count);
tasks.RemoveAt(index);
}
return tasks[0];
}
示例14: MakeRandomInsertList
public static IEnumerable<int> MakeRandomInsertList(int count)
{
List<int> ret = new List<int>(count);
List<int> sorted = new List<int>(count);
var rng = new Random();
for (int i = 0; i < count; i++)
{
sorted.Add(i);
}
while (sorted.Count > 0)
{
var sampleIx = rng.Next(sorted.Count);
ret.Add(sorted[sampleIx]);
sorted.RemoveAt(sampleIx);
}
return ret;
}
示例15: GenerateAnswer
private void GenerateAnswer(bool[,] dp, List<string[]> result, int start, List<string> cur, string input)
{
for (int end = start; end < input.Length; end++)
{
if (dp[start, end])
{
cur.Add(input.Substring(start, end - start + 1));
if (end == input.Length - 1)
{
result.Add(cur.ToArray());
}
else
{
GenerateAnswer(dp, result, end + 1, cur, input);
}
cur.RemoveAt(cur.Count - 1);
}
}
}