本文整理汇总了C#中Microsoft.VisualStudio.TestTools.UnitTesting.List.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# List.Insert方法的具体用法?C# List.Insert怎么用?C# List.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.VisualStudio.TestTools.UnitTesting.List
的用法示例。
在下文中一共展示了List.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IncrementIntegerTest
public void IncrementIntegerTest()
{
Action<List<int>>[] actions = new Action<List<int>>[]
{
IncrementInteger.Convert,
IncrementInteger.SinglePass
};
int digits = 0;
for (int i = 0; i <= 1000; i++)
{
if (i % 10 == 0)
digits++;
for(int j = 0; j < actions.Length; j++)
{
List<int> list = new List<int>();
for (int k = 0; k < digits; k++)
list.Insert(0, 0);
IncrementInteger.ToList(i, list);
actions[j](list);
Assert.AreEqual(IncrementInteger.ToInt(list), i + 1);
}
}
}
示例2: Constructor
public void Constructor()
{
TestAssemblyResults testAssemblyResults = new TestAssemblyResults(null, TimeSpan.FromSeconds(42));
Assert.IsNotNull(testAssemblyResults.TestClassResults);
Assert.IsFalse(testAssemblyResults.TestClassResults.Any());
Assert.AreEqual(42, testAssemblyResults.ExecutionTime.TotalSeconds);
Assert.AreEqual(TestResultStatus.Passed, testAssemblyResults.Status);
//////////////////////////////
List<TestClassResults> testClassResults = new List<TestClassResults>()
{
new TestClassResults("SomeClassName", null, new TimeSpan()) { Status = TestResultStatus.Passed }
};
testAssemblyResults = new TestAssemblyResults(testClassResults, new TimeSpan());
Assert.IsNotNull(testAssemblyResults.TestClassResults);
Assert.AreEqual(1, testAssemblyResults.TestClassResults.Count());
Assert.AreEqual("SomeClassName", testAssemblyResults.TestClassResults.Single().ClassName);
Assert.AreEqual(TestResultStatus.Passed, testAssemblyResults.Status);
//////////////////////////////
testClassResults.Insert(0, new TestClassResults("SomeClassName2", null, new TimeSpan()) { Status = TestResultStatus.Inconclusive });
testAssemblyResults = new TestAssemblyResults(testClassResults, new TimeSpan());
Assert.AreEqual(TestResultStatus.Inconclusive, testAssemblyResults.Status);
//////////////////////////////
testClassResults.Insert(1, new TestClassResults("SomeClassName3", null, new TimeSpan()) { Status = TestResultStatus.Failed });
testAssemblyResults = new TestAssemblyResults(testClassResults, new TimeSpan());
Assert.AreEqual(TestResultStatus.Failed, testAssemblyResults.Status);
}
示例3: changeDaySatusTest
public void changeDaySatusTest()
{
int _howmanydays = 500; // TODO: Initialize to an appropriate value
int _hq_x = 700; // TODO: Initialize to an appropriate value
int _hq_y = 1000; // TODO: Initialize to an appropriate value
Mission target = new Mission(_howmanydays, _hq_x, _hq_y); // TODO: Initialize to an appropriate value
target.BeginningDateEarth = new DateTime(2015, 11, 20);
target.startMission();
int nbJour = target.convertEarthDateInMissionDay()[0];
List<Day> expected = new List<Day>();
int i;
for (i = 0; i < nbJour; i++) { expected.Insert(i,new Past(i,target.map_Hq)); }
expected.Insert(nbJour, new Present(nbJour, target.map_Hq));
for (i = nbJour+1; i < _howmanydays; i++) { expected.Insert(i, new Future(i, target.map_Hq)); }
bool same = true;
int j=0;
while (same && (j < _howmanydays))
{
if (!(target.L_day[j].GetType().Equals(expected[j].GetType()))) { same = false; }
j++;
}
Assert.IsTrue(same);
}
示例4: EntryInit
void EntryInit()
{
rev = new List<int>();
sorted = new List<int>();
i = 0;
while (i < 10)
{
rev.Insert(0, i);
sorted.Add(i);
i = i + 1;
}
this.Assert(rev.Count == 10);
// Assert that simply reversing the list produces a sorted list
sorted = Reverse(rev);
this.Assert(sorted.Count == 10);
b = IsSorted(sorted);
this.Assert(b);
b = IsSorted(rev);
this.Assert(!b);
// Assert that BubbleSort returns the sorted list
sorted = BubbleSort(rev);
this.Assert(sorted.Count == 10);
b = IsSorted(sorted);
this.Assert(b);
b = IsSorted(rev);
this.Assert(!b);
}
示例5: TestUpperBound_BuildSet
public void TestUpperBound_BuildSet()
{
Random random = new Random();
// build a list
var list = new List<int>(100);
Sublist.Generate(100, i => random.Next(100)).AddTo(list.ToSublist());
// only add unique items in sorted order
var set = new List<int>();
foreach (int value in list)
{
int index = set.ToSublist().UpperBound(value);
if (index == 0 || set[index - 1] != value)
{
set.Insert(index, value);
}
}
// check that all items are present, sorted and unique
list.ToSublist().Sort().InPlace();
Assert.IsTrue(set.ToSublist().IsSorted(), "The set is not sorted.");
bool hasValues = set.ToSublist().IsSubset(list.ToSublist());
Assert.IsTrue(hasValues, "Not all of the values were copied.");
Assert.IsFalse(set.ToSublist().FindDuplicates(), "A duplicate was found.");
}
示例6: TestChar
public void TestChar()
{
var list = new List<char>();
list.Insert('v', 0);
list.Insert('c', 1);
list.Insert('d', 2);
var arr = new char[3];
int i = 0;
foreach (char x in list)
{
arr[i] = x;
++i;
}
Assert.AreEqual('v', arr[0]);
Assert.AreEqual('c', arr[1]);
Assert.AreEqual('d', arr[2]);
}
示例7: TestItemAtInPlace_Find3rdPlace
public void TestItemAtInPlace_Find3rdPlace()
{
Random random = new Random();
// build a list, leaving space for zero, one and two
var list = new List<int>(97);
Sublist.Generate(97, i => random.Next(3, 100)).AddTo(list.ToSublist());
// insert 0-2 at random positions in the list
list.Insert(random.Next(0, list.Count + 1), 0);
list.Insert(random.Next(0, list.Count + 1), 1);
list.Insert(random.Next(0, list.Count + 1), 2);
// now find what item belongs in the second position, as if the list was sorted
list.ToSublist().ItemAt(2).InPlace();
int actual = list[2];
Assert.AreEqual(2, actual, "The 2 was not moved to the second position.");
}
示例8: QuickPulseDataAccumulatorManagerLocksInSampleCorrectlyMultithreaded
public void QuickPulseDataAccumulatorManagerLocksInSampleCorrectlyMultithreaded()
{
// ARRANGE
var accumulatorManager = new QuickPulseDataAccumulatorManager();
int taskCount = 100;
var writeTasks = new List<Task>(taskCount);
var pause = TimeSpan.FromMilliseconds(10);
for (int i = 0; i < taskCount; i++)
{
var task = new Task(() =>
{
Interlocked.Increment(ref accumulatorManager.CurrentDataAccumulator.AIRequestSuccessCount);
// sleep to increase the probability of sample completion happening right now
Thread.Sleep(pause);
Interlocked.Increment(ref accumulatorManager.CurrentDataAccumulator.AIDependencyCallSuccessCount);
});
writeTasks.Add(task);
}
var completionTask = new Task(() =>
{
// sleep to increase the probability of more write tasks being between the two writes
Thread.Sleep(TimeSpan.FromTicks(pause.Ticks / 2));
accumulatorManager.CompleteCurrentDataAccumulator();
});
// shuffle the completion task into the middle of the pile to have it fire roughly halfway through
writeTasks.Insert(writeTasks.Count / 2, completionTask);
// ACT
var sample1 = accumulatorManager.CurrentDataAccumulator;
var result = Parallel.For(0, writeTasks.Count, new ParallelOptions() { MaxDegreeOfParallelism = taskCount }, i => writeTasks[i].RunSynchronously());
while (!result.IsCompleted)
{
}
var sample2 = accumulatorManager.CurrentDataAccumulator;
// ASSERT
// we expect some "telemetry items" to get "sprayed" over the two neighboring samples
Assert.IsTrue(sample1.AIRequestSuccessCount > sample1.AIDependencyCallSuccessCount);
Assert.IsTrue(sample2.AIRequestSuccessCount < sample2.AIDependencyCallSuccessCount);
// overall numbers should match exactly
Assert.AreEqual(taskCount, sample1.AIRequestSuccessCount + sample2.AIRequestSuccessCount);
Assert.AreEqual(taskCount, sample1.AIDependencyCallSuccessCount + sample2.AIDependencyCallSuccessCount);
}
开发者ID:Microsoft,项目名称:ApplicationInsights-dotnet-server,代码行数:54,代码来源:QuickPulseDataAccumulatorManagerTests.cs
示例9: AddDCEStuffing
/// <summary>
/// Adds DCE stuffing to the list of bytes passed across.
/// </summary>
/// <param name="bytes"></param>
private List<byte> AddDCEStuffing(List<byte> bytes)
{
for(var i = 0;i < bytes.Count;++i) {
if(bytes[i] == 0x010) {
bytes.Insert(i, 0x10);
++i;
}
}
return bytes;
}
示例10: ToArray
private static int[] ToArray(int x)
{
bool negative = x < 0;
x = Math.Abs(x);
List<int> list = new List<int>();
while(x > 0)
{
list.Insert(0, x % 10);
x /= 10;
}
if (negative)
list[0] *= -1;
return list.ToArray();
}
示例11: CountSolutions
public void CountSolutions()
{
for (int iter=0; iter< Iterations; iter++)
{
var work = Factory.Solution(rnd);
List<Location> order = new List<Location>();
for (int i = 0; i < 81; i++)
order.Insert(rnd.Next(order.Count), i);
for (int i = 0; i < 40; i++)
work[order[i]] = 0;
givens[0].Add(work.CountSolutions());
}
WriteStatistics("Solutions found after cutting 40 singles:", givens[0]);
}
示例12: SinglePass
private static void SinglePass(List<int> number)
{
int i = number.Count - 1;
number[i]++;
while(i > 0 && number[i] == 10)
{
number[i] = 0;
i--;
number[i]++;
}
if(number[0] == 10)
{
number[0] = 0;
number.Insert(0, 1);
}
}
示例13: EntryInit
void EntryInit()
{
l = new List<int>();
l.Insert(0, 12);
l.Insert(0, 23);
l.Insert(0, 12);
l.Insert(0, 23);
l.Insert(0, 12);
l.Insert(0, 23);
mac = this.CreateMachine(typeof(Tester));
this.Send(mac, new Config(l, 1));
this.Send(mac, new SeqPayload(l));
}
示例14: TestFindAny_FindSpecialCharacters
public void TestFindAny_FindSpecialCharacters()
{
Random random = new Random();
// build a random string representing a password
var password = new List<char>();
Sublist.Generate(100, i => (char)random.Next(32, 127)).AddTo(password.ToSublist());
password.Insert(50, '>'); // insert an invalid character
// have a list of characters that aren't allowed
char[] exclusions = { '<', '>', '[', ']', '{', '}', '(', ')' };
// see if the password contains an invalid character
var result = password.ToSublist().FindAny(exclusions.ToSublist());
Assert.IsTrue(result.Exists, "No special characters were found.");
char actual = password[result.Index];
Assert.IsTrue(exclusions.ToSublist().Find(actual), "The character found was not in the exclusions list.");
}
示例15: ConfirmSetTest
public void ConfirmSetTest()
{
SET.Processing isSet = new Processing();
List<Cards> cardList = new List<Cards>();
SET.Cards card1 = new Cards();
SET.Cards card2 = new Cards();
SET.Cards card3 = new Cards();
card1.Color = "red";
card1.Number = 1;
card1.Shade = "solid";
card1.Shape = "oval";
card2.Color = "green";
card2.Number = 2;
card2.Shade = "solid";
card2.Shape = "oval";
card3.Color = "blue";
card3.Number = 3;
card3.Shade = "solid";
card3.Shape = "oval";
cardList.Insert(0, card1);
cardList.Insert(1, card2);
cardList.Insert(2, card3);
Assert.IsTrue(isSet.ConfirmSet(cardList) > 0);
card1.Color = "red";
card1.Number = 1;
card1.Shade = "solid";
card1.Shape = "oval";
card2.Color = "green";
card2.Number = 2;
card2.Shade = "solid";
card2.Shape = "oval";
card3.Color = "blue";
card3.Number = 2;
card3.Shade = "solid";
card3.Shape = "oval";
cardList.Clear();
cardList.Insert(0, card1);
cardList.Insert(1, card2);
cardList.Insert(2, card3);
Assert.IsFalse(isSet.ConfirmSet(cardList) > 0);
}