本文整理汇总了C#中Deque.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Deque.Contains方法的具体用法?C# Deque.Contains怎么用?C# Deque.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Deque
的用法示例。
在下文中一共展示了Deque.Contains方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Simple
public void Simple()
{
var test = new Deque<int>();
Assert.IsFalse(test.Contains(5));
test.EnqueueHead(5);
test.EnqueueHead(6);
Assert.IsTrue(test.Contains(5));
Assert.IsTrue(test.Contains(6));
}
示例2: ContainsPUT
public void ContainsPUT([PexAssumeUnderTest]IList<int> values, int val)
{
PexAssume.IsTrue(values.Contains(val));
Deque<int> actual = new Deque<int> (values);
Assert.AreEqual(true, actual.Contains(val));
}
示例3: ClearExample
public void ClearExample()
{
var deque = new Deque<string>();
deque.EnqueueHead("cat");
deque.EnqueueHead("dog");
deque.EnqueueHead("canary");
// There should be 3 items in the deque.
Assert.AreEqual(3, deque.Count);
// Clear the deque
deque.Clear();
// The deque should be empty.
Assert.AreEqual(0, deque.Count);
// No cat here..
Assert.IsFalse(deque.Contains("cat"));
}
示例4: Main
internal static void Main()
{
Deque<string> deque = new Deque<string>();
string peterName = "Peter";
deque.PushFirst(peterName);
deque.PushLast("Last element");
deque.PushFirst("Before Peter");
deque.PushLast("After last element");
//This will return 4
Console.WriteLine("Number of elements: {0}", deque.Count);
//This will return true, because "Peter" is in the deque
Console.WriteLine("If deque contains: {0}, -> {1}", peterName, deque.Contains(peterName));
//This will return first element without removing it.
Console.WriteLine(deque.PeekFirst());
//This will return last element and remove it.
Console.WriteLine(deque.PopLast());
}
示例5: ContainsExample
public void ContainsExample()
{
var deque = new Deque<string>();
deque.EnqueueHead("cat");
deque.EnqueueHead("dog");
deque.EnqueueHead("canary");
// deque does contain cat, dog and canary
Assert.IsTrue(deque.Contains("cat"));
Assert.IsTrue(deque.Contains("dog"));
Assert.IsTrue(deque.Contains("canary"));
// but not frog
Assert.IsFalse(deque.Contains("frog"));
}
示例6: TestContains
private static void TestContains(Deque deque)
{
deque.Clear();
PopulateDequePushBack(deque);
for(int i = 0; i < deque.Count; i++)
{
System.Diagnostics.Debug.Assert(deque.Contains(i));
}
System.Diagnostics.Debug.Assert(!deque.Contains(ElementCount));
}
示例7: TestContains
private static void TestContains(Deque<int> deque)
{
deque.Clear();
PopulateDequePushBack(deque);
for(int i = 0; i < deque.Count; i++)
{
Debug.Assert(deque.Contains(i));
}
Debug.Assert(!deque.Contains(ElementCount));
}
示例8: ContainsTest
public void ContainsTest()
{
Deque<int> actual = new Deque<int> { 12, 4325, 89 };
Assert.AreEqual(true, actual.Contains(4325));
}
示例9: TestAdd
public void TestAdd()
{
Deque<int> deque = new Deque<int>();
Assert.IsTrue(deque.IsEmpty);
int item = 1;
Assert.IsFalse(deque.Contains(item));
deque.Add(item);
int actualBack;
actualBack = deque[0];
Assert.IsTrue(deque.Contains(item));
Assert.AreEqual(item, actualBack);
int itemNewBack = 2;
Assert.IsFalse(deque.Contains(itemNewBack));
deque.AddBack(itemNewBack);
Assert.IsTrue(deque.Contains(itemNewBack));
actualBack = deque[1];
Assert.AreEqual(itemNewBack, actualBack);
actualBack = deque.RemoveBack();
Assert.AreEqual(itemNewBack, actualBack);
int itemNewFront = -1;
Assert.IsFalse(deque.Contains(itemNewFront));
deque.AddFront(itemNewFront);
int actualFront;
Assert.IsTrue(deque.Contains(itemNewFront));
actualFront = deque[0];
Assert.AreEqual(itemNewFront, actualFront);
actualFront = deque.RemoveFront();
Assert.AreEqual(itemNewFront, actualFront);
int[] itemRange = new[] { 3, 4, 5, 6 };
int offset = deque.Count;
deque.AddRange(itemRange);
foreach (var itm in itemRange)
{
Assert.AreEqual(itm, deque[offset]);
offset++;
}
int[] itemBackRange = new[] { 7, 8, 9, 10 };
offset = deque.Count;
deque.AddBackRange(itemBackRange);
foreach (var itm in itemBackRange)
{
Assert.AreEqual(itm, deque[offset]);
offset++;
}
int[] itemFrontRange = new[] { 3, 4, 5, 6 };
deque.AddFrontRange(itemFrontRange);
for (int i = 0; i < itemFrontRange.Length; i++)
{
var itm = itemFrontRange[i];
Assert.AreEqual(itm, deque[i]);
}
}
示例10: TestRemove
public void TestRemove()
{
int[] items = new[] { 0, 1, 2, 3 };
Deque<int> deque = new Deque<int>(items);
Assert.IsTrue(deque.Contains(0));
Assert.IsTrue(deque.Remove(0));
Assert.IsFalse(deque.Contains(0));
Assert.AreEqual(1, deque.RemoveFront());
Assert.AreEqual(3, deque.RemoveBack());
deque.Clear();
deque.AddRange(items);
Assert.IsTrue(deque.Contains(2));
deque.RemoveAt(2);
Assert.IsFalse(deque.Contains(2));
deque.Clear();
deque.AddRange(items);
foreach (var item in items)
{
Assert.IsTrue(deque.Contains(item));
}
deque.RemoveRange(1, 2);
Assert.IsTrue(deque.Contains(0));
Assert.IsFalse(deque.Contains(1));
Assert.IsFalse(deque.Contains(2));
Assert.IsTrue(deque.Contains(3));
}
示例11: TestConstructor
public void TestConstructor()
{
Deque<int> deque;
deque = new Deque<int>();
Assert.AreEqual(16, deque.Capacity);
deque = new Deque<int>(8);
Assert.AreEqual(8, deque.Capacity);
int[] arr = new [] {0,1,2,3,4,5,6,7};
deque = new Deque<int>(arr);
Assert.AreEqual(arr.Length, deque.Capacity);
foreach (int item in arr)
{
Assert.IsTrue(deque.Contains(item));
}
}