コード例 #1
0
 public void GetNameShouldReturnAName()
 {
     Node target = new Node("Jacob");
     string actual = target.GetName();
     string expected = "Jacob";
     Assert.AreEqual(expected, actual);
 }
コード例 #2
0
 public void SetNamesShouldChangeTheName()
 {
     Node target = new Node("Jacob");
     target.SetName("George");
     string actual = target.GetName();
     string expected = "George";
     Assert.AreEqual(expected, actual);
 }
コード例 #3
0
 public void Enqueue(Node newNode)
 {
     newNode.SetNextNode(tailNode);
     tailNode = newNode;
     if (tailNode.GetNextNode() == null)
     {
         headNode = tailNode;
     }
 }
コード例 #4
0
 public void DequeueShouldReturnHeadNode()
 {
     LinkedListQueue target = new LinkedListQueue();
     Node firstNode = new Node();
     target.Enqueue(firstNode);
     Node expected = firstNode;
     Node actual = target.Dequeue();
     Assert.AreEqual(expected, actual);
 }
コード例 #5
0
 public void EnqueueShouldAddPreviousTailToNewTailsNextNode()
 {
     LinkedListQueue target = new LinkedListQueue();
     Node nodeOne = new Node();
     Node nodeTwo = new Node();
     target.Enqueue(nodeOne);
     target.Enqueue(nodeTwo);
     Node expected = nodeOne;
     Node actual = nodeTwo.GetNextNode();
     Assert.AreEqual(expected, actual);
 }
コード例 #6
0
 public void ShouldBeAbleToGetAndSetNextNode()
 {
     Node nodeOne = new Node();
     Node target = new Node(nodeOne);
     Node expected = nodeOne;
     Node actual = target.GetNextNode();
     Assert.AreEqual(expected, actual);
     Node newNode = new Node("Emily");
     target.SetNextNode(newNode);
     expected = newNode;
     actual = target.GetNextNode();
     Assert.AreEqual(expected, actual);
 }
コード例 #7
0
 private Node FindNodeByData(Node currentlySearchingNode, string data)
 {
     if (currentlySearchingNode.GetName() == data)
     {
         return currentlySearchingNode;
     }
     else if (currentlySearchingNode.GetNextNode() != null)
     {
         return FindNodeByData(currentlySearchingNode.GetNextNode(), data);
     }
     return null;
     // Recusion here is not ideal, due to the fact that, for a sufficiently large queue, this recursive loop will blow the stack
 }
コード例 #8
0
 public void DequeueShouldCreateNewHeadNode()
 {
     LinkedListQueue target = new LinkedListQueue();
     Node firstNode = new Node();
     Node secondNode = new Node(firstNode);
     Node thirdNode = new Node(secondNode);
     target.Enqueue(firstNode);
     target.Enqueue(secondNode);
     target.Enqueue(thirdNode);
     target.Dequeue();
     Node expected = secondNode;
     Node actual = target.Head();
     Assert.AreEqual(expected, actual);
 }
コード例 #9
0
 private Node FindNextHeadNode(Node currentlySearchingNode)
 {
     Node currentNode = tailNode;
     Node nextNode;
     while (currentNode != null)
     {
         if (currentNode.GetNextNode() == headNode)
         {
             return currentNode;
         }
         else
         {
             currentNode = currentNode.GetNextNode();
         }
     }
     return null;
 }
コード例 #10
0
 public Node Dequeue()
 {
     Node temporaryNode = headNode;
     headNode = FindNextHeadNode(tailNode);
     return temporaryNode;
 }
コード例 #11
0
 public void SetNextNode(Node desiredNextNode)
 {
     nextNode = desiredNextNode;
 }
コード例 #12
0
 public void TailShouldReturnLastNodeInQueue()
 {
     LinkedListQueue target = new LinkedListQueue();
     Node newNode = new Node();
     target.Enqueue(newNode);
     Node expected = newNode;
     Node actual = target.Tail();
     Assert.AreEqual(expected, actual);
 }
コード例 #13
0
 public void ShouldBeAbleToCreateNodes()
 {
     Node target = new Node();
 }
コード例 #14
0
 public Node(string desiredName, Node desiredNextNode)
 {
     name = desiredName;
     nextNode = desiredNextNode;
 }
コード例 #15
0
 public void EnqueueShouldTakeANode()
 {
     LinkedListQueue target = new LinkedListQueue();
     Node newNode = new Node();
     target.Enqueue(newNode);
 }
コード例 #16
0
 public void ShouldBeAbleToCreateNodesWithNextNodes()
 {
     Node nodeOne = new Node("Jacob");
     Node nodeTwo = new Node("George", nodeOne);
     Node nodeThree = new Node(nodeTwo);
 }
コード例 #17
0
 public void ShouldBeAbleToCreateNodesWithNames()
 {
     Node target = new Node("Jacob");
 }
コード例 #18
0
 public void FindShouldReturnDesiredNode()
 {
     LinkedListQueue target = new LinkedListQueue();
     Node firstNode = new Node("First");
     Node secondNode = new Node("Second");
     Node thirdNode = new Node("Third");
     Node fourthNode = new Node("Fourth");
     target.Enqueue(firstNode);
     target.Enqueue(secondNode);
     target.Enqueue(thirdNode);
     target.Enqueue(fourthNode);
     Node actual = target.Find("Second");
     Node expected = secondNode;
     Assert.AreEqual(expected, actual);
 }
コード例 #19
0
 public Node(Node desiredNextNode)
 {
     nextNode = desiredNextNode;
 }