public void AddFiveItemsAndVerify() { int linkedListQueueLast = 0; int arrayQueueLast = 0; for (int i = 1; i <= 5; i++) { linkedListQueue.Enqueue(i); arrayQueue.Enqueue(i); } Assert.AreEqual(linkedListQueue.Peek(), 1, "invalid top element"); Assert.AreEqual(linkedListQueue.Count, 5, "invalid count"); Assert.AreEqual(arrayQueue.Peek(), 1, "invalid top element"); Assert.AreEqual(arrayQueue.Count, 5, "invalid count"); while (linkedListQueue.Count > 0) { linkedListQueueLast = linkedListQueue.Dequeue(); arrayQueueLast = arrayQueue.Dequeue(); } Assert.AreEqual(linkedListQueueLast, 5, "invalid last element"); Assert.AreEqual(arrayQueueLast, 5, "invalid last element"); }
static void Main(string[] args) { var arrayQueue = new ArrayQueue <string>(); arrayQueue.Enqueue("1"); arrayQueue.Enqueue("2"); arrayQueue.Enqueue("3"); arrayQueue.Enqueue("4"); arrayQueue.Enqueue("5"); arrayQueue.Dequeue(); arrayQueue.Dequeue(); arrayQueue.Dequeue(); arrayQueue.Dequeue(); var linkedListQueue = new LinkedListQueue <string>(); linkedListQueue.Enqueue("1"); linkedListQueue.Enqueue("2"); linkedListQueue.Enqueue("3"); linkedListQueue.Enqueue("4"); linkedListQueue.Enqueue("5"); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); linkedListQueue.Dequeue(); }
public void TestLinkedListQueuePeek() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); // check that after peek we have the correct value but the item // is not deleted Assert.AreEqual(1, queue.Peek()); Assert.AreEqual(5, queue.Count); queue.Dequeue(); Assert.AreEqual(2, queue.Peek()); Assert.AreEqual(4, queue.Count); queue.Dequeue(); Assert.AreEqual(3, queue.Peek()); Assert.AreEqual(3, queue.Count); queue.Dequeue(); Assert.AreEqual(4, queue.Peek()); Assert.AreEqual(2, queue.Count); queue.Dequeue(); Assert.AreEqual(5, queue.Peek()); Assert.AreEqual(1, queue.Count); queue.Dequeue(); }
public void TestLinkedListQueuePeek() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); // check that after peek we have the correct value but the item // is not deleted Assert.AreEqual(1, queue.Peek()); Assert.AreEqual(5, queue.Count); queue.Dequeue(); Assert.AreEqual(2, queue.Peek()); Assert.AreEqual(4, queue.Count); queue.Dequeue(); Assert.AreEqual(3, queue.Peek()); Assert.AreEqual(3, queue.Count); queue.Dequeue(); Assert.AreEqual(4, queue.Peek()); Assert.AreEqual(2, queue.Count); queue.Dequeue(); Assert.AreEqual(5, queue.Peek()); Assert.AreEqual(1, queue.Count); queue.Dequeue(); }
public void Enqueue_Adds_To_Count() { IQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); Assert.Equal(3, queue.Count); }
public void QueueIsEnptyWhenAllElementsAreRemoved() { var sut = new LinkedListQueue <int>(); sut.Enqueue(1); sut.Enqueue(2); Assert.Equal(1, sut.Dequeue()); Assert.Equal(2, sut.Dequeue()); Assert.True(sut.IsEmpty); }
public void Enqueue_And_Dequeue_Single_Item() { IQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); var item = queue.Peek(); Assert.Equal(1, item); }
public void Dequeue_Subtracts_To_Count() { IQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Dequeue(); queue.Dequeue(); Assert.Equal(1, queue.Count); }
public void NonEmptyQueueReadsNotEmptyTest() { LinkedListQueue target = new LinkedListQueue(); target.Enqueue(0); for (int i = 0; i < 1000000; i++) { target.Enqueue(i); Assert.IsFalse(target.IsEmpty, string.Format("LinkedListQueue reads as empty after adding {0} objects and never removing any", i + 1)); } }
public void CircularQueueRemovesOldElementsToEnqueueNewOnes1() { var sut = new LinkedListQueue <int>(); sut.Enqueue(1); sut.Enqueue(2); Assert.Equal(1, sut.Dequeue()); Assert.Equal(2, sut.Dequeue()); sut.Enqueue(4); Assert.Equal(4, sut.Dequeue()); Assert.True(sut.IsEmpty); }
public void TestLinkedListQueueContains() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.IsTrue(queue.Contains(5)); }
public void TestLinkedListQueueToString() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual("1, 2, 3, 4, 5", queue.ToString()); }
public void TestLinkedListQueueClear() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Clear(); Assert.AreEqual(0, queue.Count); }
public void QueueWorksInFifoOrderWhenIntermittentEnqueuesAccure() { var sut = new LinkedListQueue <int>(); sut.Enqueue(1); sut.Enqueue(2); sut.Enqueue(3); Assert.Equal(1, sut.Dequeue()); sut.Enqueue(4); sut.Enqueue(5); Assert.Equal(2, sut.Dequeue()); Assert.Equal(3, sut.Dequeue()); Assert.Equal(4, sut.Dequeue()); Assert.Equal(5, sut.Dequeue()); }
public void QueueTest() { var q = new LinkedListQueue <int>(); q.Enqueue(1); q.Enqueue(2); Assert.IsTrue(q.Count == 2); int i = q.Dequeue(); Assert.IsTrue(i == 1); Assert.IsTrue(q.Count == 1); i = q.Dequeue(); Assert.IsTrue(i == 2); Assert.IsTrue(q.Count == 0); }
public void TestLinkedListQueueEnqueue() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); // enqueue some items to test and check that the items are inserted correctly queue.Enqueue(1); Assert.AreEqual(1, queue.Count); queue.Enqueue(2); Assert.AreEqual(2, queue.Count); queue.Enqueue(3); Assert.AreEqual(3, queue.Count); queue.Enqueue(4); Assert.AreEqual(4, queue.Count); queue.Enqueue(5); Assert.AreEqual(5, queue.Count); }
public void TestLinkedListQueueEnqueue() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); // enqueue some items to test and check that the items are inserted correctly queue.Enqueue(1); Assert.AreEqual(1, queue.Count); queue.Enqueue(2); Assert.AreEqual(2, queue.Count); queue.Enqueue(3); Assert.AreEqual(3, queue.Count); queue.Enqueue(4); Assert.AreEqual(4, queue.Count); queue.Enqueue(5); Assert.AreEqual(5, queue.Count); }
public void TestLinkedListQueueDequeue_ThrowsException() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); }
public void Can_enqueue_data() { var linkedListQueue = new LinkedListQueue <int>(); linkedListQueue.Enqueue(1); linkedListQueue.Enqueue(2); linkedListQueue.Enqueue(3); linkedListQueue.Enqueue(4); Assert.Equal(4, linkedListQueue.Length); var head = linkedListQueue.Head; Assert.Equal(1, head.Data); Assert.Equal(2, head.Next.Data); Assert.Equal(3, head.Next.Next.Data); Assert.Equal(4, head.Next.Next.Next.Data); }
public void LinkedListQueue() { var queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual(1, queue.Dequeue()); Assert.AreEqual(2, queue.Dequeue()); Assert.AreEqual(3, queue.Dequeue()); Assert.AreEqual(4, queue.Dequeue()); Assert.AreEqual(5, queue.Dequeue()); Assert.AreEqual(true, queue.IsEmpty()); }
public void Enqueue_And_Dequeue_Multiple_Items() { IQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); var item = queue.Peek(); Assert.Equal(5, item); }
private void GeneratePopulatedExample() { PopulatedLinkedListQueue = new LinkedListQueue <string>(); foreach (var item in Items) { PopulatedLinkedListQueue.Enqueue(item); } }
public void TestLinkedListQueueDequeue_ThrowsException() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); }
public void TestLinkedListQueuePeek_ThrowsException() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Peek(); }
public void SimpleTest() { var queue = new LinkedListQueue(); Assert.True(queue.IsEmpty); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); Assert.Equal(1, queue.Front); Assert.Equal(4, queue.Rear); Assert.Equal(1, queue.Dequeue()); Assert.Equal(2, queue.Dequeue()); Assert.Equal(3, queue.Dequeue()); Assert.Equal(4, queue.Dequeue()); }
public void CountTest() { LinkedListQueue target = new LinkedListQueue(); for (int i = 0; i < 1000000; i++) { Assert.AreEqual <int>(target.Count, i, string.Format("After adding {0} entries to LinkedListQueue, Count returns {1}", i, target.Count)); target.Enqueue(i); } }
public void LinkedListQueueEnqueueTest() { var queue = new LinkedListQueue <int>(); for (var i = 0; i < Elements; i++) { queue.Enqueue(i * 10); } Assert.AreEqual(0, queue.Peek()); }
public void TestLinkedListQueueDequeue() { LinkedListQueue <int> queue = new LinkedListQueue <int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual(1, queue.Dequeue()); Assert.AreEqual(4, queue.Count); Assert.AreEqual(2, queue.Dequeue()); Assert.AreEqual(3, queue.Count); Assert.AreEqual(3, queue.Dequeue()); Assert.AreEqual(2, queue.Count); Assert.AreEqual(4, queue.Dequeue()); Assert.AreEqual(1, queue.Count); Assert.AreEqual(5, queue.Dequeue()); Assert.AreEqual(0, queue.Count); }
public void TestLinkedListQueueDequeue() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual(1, queue.Dequeue()); Assert.AreEqual(4, queue.Count); Assert.AreEqual(2, queue.Dequeue()); Assert.AreEqual(3, queue.Count); Assert.AreEqual(3, queue.Dequeue()); Assert.AreEqual(2, queue.Count); Assert.AreEqual(4, queue.Dequeue()); Assert.AreEqual(1, queue.Count); Assert.AreEqual(5, queue.Dequeue()); Assert.AreEqual(0, queue.Count); }
public override void Init() { _linkedListQueue = new LinkedListQueue <int>(); _arrayQueue = new ArrayQueue <int>(Elements); for (var i = 0; i < Elements; i++) { _linkedListQueue.Enqueue(i * 10); _arrayQueue.Enqueue(i * 10); } base.Init(); }
public void BreadthFirstSearch(Action <K, T> action) { var queue = new LinkedListQueue <Node <K, T> >().Enqueue(root); while (!queue.IsEmprty()) { var currentNode = queue.Dequeue(); action.Invoke(currentNode.Key, currentNode.Value); if (!queue.Contains(currentNode.Left) && currentNode.Left == null) { queue.Enqueue(currentNode.Left); } if (!queue.Contains(currentNode.Right) && currentNode.Right == null) { queue.Enqueue(currentNode.Right); } } }
/// <summary> /// 从B站获取最新开播的直播间 /// </summary> private static void FetchNewRoom(bool dry = false) { var c = new WebClient(); c.Headers.Add(HttpRequestHeader.Accept, "application/json, text/plain, */*"); c.Headers.Add(HttpRequestHeader.Referer, "https://live.bilibili.com/all"); c.Headers.Add("Origin", "https://live.bilibili.com"); c.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"); string rawdata = c.DownloadString("https://api.live.bilibili.com/room/v1/Area/getListByAreaID?areaId=0&sort=livetime&pageSize=300&page=1"); JObject j = JObject.Parse(rawdata); JArray rawlist = j["data"] as JArray; lock (lockObject) { int before = RoomQueue.Count; foreach (JToken rawroom in rawlist) { try { int roomid = rawroom["roomid"].ToObject <int>(); if (!ProcessedRoom.Contains(roomid)) { ProcessedRoom.AddLast(roomid); if (!dry) { RoomQueue.Enqueue(rawroom.ToObject <StreamRoom>()); } } } catch (Exception) { } } int diff = RoomQueue.Count - before; if (diff != 0) { TelegramMessage .Append(DateTime.Now.ToString("HH:mm:ss.f")) .Append("\n") .Append("新增任务 ") .Append(diff) .Append("个 #newtask\n\n"); } } while (ProcessedRoom.Count > 600) { ProcessedRoom.RemoveFirst(); } }
public void LinkedListTest_當存入輸入時_IsEmpty為false() { var expect = new int[] { 24, 12, 16, 22 }; var queue = new LinkedListQueue <int>(); foreach (var i in expect) { queue.Enqueue(i); } Assert.IsFalse(queue.IsEmpty); }
private string ShuntingYard(string input) { LinkedListStack <char> operators = new LinkedListStack <char>(); Queue <char> output = new LinkedListQueue <char>(); foreach (var i in input) { if (Char.IsNumber(i)) { output.Enqueue(i); } if (IsOperator(i)) { while (!operators.IsEmpty() && OperatorPrecedence(operators.Peek()) >= OperatorPrecedence(i)) { output.Enqueue(operators.Pop()); } operators.Push(i); } if (i == '(') { operators.Push(i); } if (i == ')') { while (operators.Peek() != '(') { output.Enqueue(operators.Pop()); } operators.Pop(); } } while (!operators.IsEmpty()) { output.Enqueue(operators.Pop()); } return(new string(output.ToArray())); }
static void Main(string[] args) { LinkedListQueue<int> queue = new LinkedListQueue<int>(); for (int i = 1; i <= 5; i++) { queue.Enqueue(i); } Console.WriteLine("Count: {0}", queue.Count); Console.WriteLine("The peek is {0}", queue.Peek()); for (int i = 1; i <= 4; i++) { queue.Dequeue(); } Console.WriteLine("After dequeue 4 item the peek is {0}", queue.Peek()); }
public void TestLinkedListQueueToString() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.AreEqual("1, 2, 3, 4, 5", queue.ToString()); }
public void E1329() { LinkedListQueue<string> queue = new LinkedListQueue<string>(); Assert.AreEqual(0, queue.Size); queue.Enqueue(new Node<string>(1)); Assert.AreEqual(1, queue.Size); queue.Enqueue(new Node<string>(2)); Assert.AreEqual(2, queue.Size); queue.Enqueue(new Node<string>(3)); Assert.AreEqual(3, queue.Size); queue.Dequeue(); Assert.AreEqual(2, queue.Size); queue.Dequeue(); Assert.AreEqual(1, queue.Size); queue.Dequeue(); Assert.AreEqual(0, queue.Size); Assert.IsTrue(queue.IsEmpty()); try { queue.Dequeue(); throw new ApplicationException("Test failed"); } catch (Exception) { } }
public void TestLinkedListQueuePeek_ThrowsException() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); // enqueue some items to test queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); queue.Peek(); }
public void TestLinkedListQueueClear() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Clear(); Assert.AreEqual(0, queue.Count); }
public void TestLinkedListQueueContains() { LinkedListQueue<int> queue = new LinkedListQueue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); Assert.IsTrue(queue.Contains(5)); }
public void SortByDroid() { LinkedListStack<AstromechDroid> astromechList = new LinkedListStack<AstromechDroid>(); LinkedListStack<JanitorDroid> janitorList = new LinkedListStack<JanitorDroid>(); LinkedListStack<ProtocolDroid> protocolList = new LinkedListStack<ProtocolDroid>(); LinkedListStack<UtilityDroid> utilityList = new LinkedListStack<UtilityDroid>(); LinkedListQueue<IDroid> tempList = new LinkedListQueue<IDroid>(); foreach(Droid d in droidCollection) { if(d is AstromechDroid) { astromechList.Add((AstromechDroid)d); } else if(d is JanitorDroid) { janitorList.Add((JanitorDroid)d); } else if(d is ProtocolDroid) { protocolList.Add((ProtocolDroid)d); } else if(d is UtilityDroid) { utilityList.Add((UtilityDroid)d); } } while(astromechList.lastNode.Tail != null) { tempList.Enqueue(astromechList.PopOff()); } tempList.Enqueue(astromechList.PopOff()); while(janitorList.lastNode.Tail != null) { tempList.Enqueue(janitorList.PopOff()); } tempList.Enqueue(janitorList.PopOff()); while(protocolList.lastNode.Tail != null) { tempList.Enqueue(protocolList.PopOff()); } tempList.Enqueue(protocolList.PopOff()); while(utilityList.lastNode.Tail != null) { tempList.Enqueue(utilityList.PopOff()); } tempList.Enqueue(utilityList.PopOff()); droidCollection = new IDroid[lengthOfCollection]; int counter = 0; while(counter < lengthOfCollection) { if(tempList.lastNode != null) { droidCollection[counter] = tempList.Dequeue(); counter++; } } }