/** * Check if the number of NPC's in an area are 2 or less. * @param NPC * @return */ private Boolean lessThanTwoCheck(NPCObject[] NPC) { // NPCs are zero if (NPC.Length == 0) { return(true); } // create first linked list node. head = new DblLinkedList(NPC[0]); prev = head; if (NPC.Length == 1) { return(true); } // Else prepare the second linked list. DblLinkedList DLL_Two = new DblLinkedList(NPC[1]); head.next = DLL_Two; DLL_Two.prev = head; curr = DLL_Two; if (NPC.Length == 2) { return(true); } return(false); }
public void InsertBeforeTailOfEmptyList_ShouldThrowInvalidOperationException() { var list = new DblLinkedList <string>(); list.Invoking(l => l.InsertBefore(l.Tail, DblLinkedList.CreateNode("1"))) .ShouldThrow <InvalidOperationException>(); }
public void InsertAfterNull_ShouldThrowArgumentException() { var list = new DblLinkedList <string>(); list.Invoking(l => l.InsertAfter(null, DblLinkedList.CreateNode("1"))) .ShouldThrow <ArgumentNullException>(); }
public void RemoveNull_ShouldThrowArgumentException() { var list = new DblLinkedList <string>(); list.Invoking(l => l.Remove(null)) .ShouldThrow <ArgumentNullException>(); }
public void InsertAfterHeadOfEmptyList_ShouldThrowInvalidOperationException() { var list = new DblLinkedList <string>(); list.Invoking(l => l.InsertAfter(l.Head, DblLinkedList.CreateNode("1"))) .ShouldThrow <InvalidOperationException>(); }
public void InsertBeforeTailNull_ShouldThrowArgumentException() { var list = new DblLinkedList <string>(); list.Invoking(l => l.InsertBefore(l.Tail, null)) .ShouldThrow <ArgumentNullException>(); }
public void InsertAfterHeadNull_ShouldThrowArgumentException() { var list = new DblLinkedList <string>(); list.Invoking(l => l.InsertAfter(l.Head, null)) .ShouldThrow <ArgumentNullException>(); }
public void ListWithOneItem_ShouldNotBeEmpty() { var list = new DblLinkedList <int>(); var node = DblLinkedList.CreateNode(1); list.InsertHead(node); list.IsEmpty().Should().BeFalse(); }
public void InsertedToTailOfEmptyListNode_ShouldBeHeadOfList() { var list = new DblLinkedList <int>(); var node = DblLinkedList.CreateNode(1); list.InsertTail(node); list.Head.Should().Be(node); }
public void InsertedToHeadTwoNodes_ShouldBeInListInRightOrder() { var list = new DblLinkedList <int>(); list.InsertHead(DblLinkedList.CreateNode(1)); list.InsertHead(DblLinkedList.CreateNode(2)); list.Head.Value.Should().Be(2); list.Head.Next.Value.Should().Be(1); }
public void InsertedToTailTwoNodes_ShouldBeInListInRightOrder() { var list = new DblLinkedList <int>(); list.InsertTail(DblLinkedList.CreateNode(1)); list.InsertTail(DblLinkedList.CreateNode(2)); list.Tail.Value.Should().Be(2); list.Tail.Prev.Value.Should().Be(1); }
public void ListAfterInsertingAndRemovingNode_ShouldBeEmpty() { var list = new DblLinkedList <int>(); var node = DblLinkedList.CreateNode(1); list.InsertTail(node); list.Remove(node); list.IsEmpty().Should().BeTrue(); }
public void IterativeInsertAfterTail_ShouldProduceCorrectList(IList <int> input) { var list = new DblLinkedList <int>(); foreach (var i in input) { list.InsertAfter(list.Tail, DblLinkedList.CreateNode(i)); } VerifyList(list, input); }
public void IterativeInsertBeforeHead_ShouldProduceCorrectList(IList <int> input) { var list = new DblLinkedList <int>(); foreach (var i in input.Reverse()) { list.InsertBefore(list.Head, DblLinkedList.CreateNode(i)); } VerifyList(list, input); }
public void InsertedAfterTailNode_ShouldBecomeTheTailOfList() { var list = new DblLinkedList <int>(); list.InsertTail(DblLinkedList.CreateNode(1)); var newNode = DblLinkedList.CreateNode(3); list.InsertAfter(list.Tail, newNode); list.Tail.Value.Should().Be(newNode.Value); }
public void InsertedBeforeHeadNode_ShouldBecomeTheHeadOfList() { var list = new DblLinkedList <int>(); list.InsertHead(DblLinkedList.CreateNode(1)); var newNode = DblLinkedList.CreateNode(3); list.InsertBefore(list.Head, newNode); list.Head.Value.Should().Be(newNode.Value); }
public void InsertedAfterNode_ShouldBeInsertedInsertedInRightPlace() { var list = new DblLinkedList <int>(); var node1 = DblLinkedList.CreateNode(1); list.InsertHead(node1); var newNode = DblLinkedList.CreateNode(2); list.InsertAfter(node1, newNode); list.Head.Next.Value.Should().Be(newNode.Value); }
public void AfterRemovingHeadNode_HeadShouldBeChanged() { var list = new DblLinkedList <int>(); var node1 = DblLinkedList.CreateNode(1); var node2 = DblLinkedList.CreateNode(2); list.InsertHead(node1); list.InsertHead(node2); list.Remove(node2); list.Head.Value.Should().Be(node1.Value); }
public void IterativeInsertBefore_ShouldProduceCorrectList() { var input = new string[] { "1", "2", "3" }; var list = new DblLinkedList <string>(); var currentNode = list.Head; foreach (var i in input.Reverse()) { currentNode = list.InsertBefore(currentNode, DblLinkedList.CreateNode(i)); } VerifyList(list, input); }
private void VerifyListNode <T>(DblLinkedList <T> .Node node, IList <T> expectedList) { if (!expectedList.Any()) { node.IsNull.Should().BeTrue(); return; } node.Value.Should().Be(expectedList.First()); node.Prev.Next.Should().Be(node); node.Next.Prev.Should().Be(node); VerifyListNode(node.Next, expectedList.Skip(1).ToList()); }
private void VerifyList <T>(DblLinkedList <T> list, IList <T> expectedList) { if (!expectedList.Any()) { list.Head.IsNull.Should().BeTrue(); list.Tail.IsNull.Should().BeTrue(); list.IsEmpty().Should().BeTrue(); return; } list.Head.IsNull.Should().BeFalse(); list.Tail.IsNull.Should().BeFalse(); list.Head.Value.Should().Be(expectedList.First()); list.Tail.Value.Should().Be(expectedList.Last()); VerifyListNode(list.Head, expectedList); }
/** * Same as above but swapped the prev and next X and Y values so the slope intercept formula still works. * @param NPC * @param prev * @param currCheck * @param trav * @return */ public double hullCheckBottom(NPCObject[] NPC, DblLinkedList prev, DblLinkedList currCheck, int trav) { double prevX = NPC[trav].PV.x; double prevY = NPC[trav].PV.y; double nextX = prev.NPC.PV.x; double nextY = prev.NPC.PV.y; double thisX = currCheck.NPC.PV.x; // (3, 2) and (6, 3) // y = mx + b double slope = (nextY - prevY) / (nextX - prevX); // m double yInt = prevY - (slope * prevX); // b // If this is lower than current point, the current point is no longer // a part of the hull. return(slope * thisX + yInt); }
public static void ConvexHullTest() { Console.WriteLine("Creating Convex Hull"); JarvisMarch JMA = new JarvisMarch(5); MergeSort SA = new MergeSort(); NPCObject[] NPCO = SA.sort(FivePointSeed.getGameObjectSeedDataJarvis(), 0, 4); DblLinkedList DLL = JMA.getConvexHull(NPCO); while (DLL != null) { Console.Write(DLL.NPC.PV.x); Console.WriteLine(" " + DLL.NPC.PV.y); DLL = DLL.next; } //NPCO[0].PV.x = pv[0].x; //NPCO[0].PV.y = pv[0].y; //DblLinkedList DLLHead = new DblLinkedList(NPCO[0]); //NPCO[1].PV.x = pv[1].x; //NPCO[1].PV.y = pv[1].y; //DblLinkedList DLL = new DblLinkedList(NPCO[1]); //DLLHead.next = DLL; //DLL.prev = DLLHead; //for (int i = 2; i < 5; i++) //{ // NPCO[i].PV.x = pv[i].x; // NPCO[i].PV.y = pv[i].y; // DblLinkedList DL = new DblLinkedList(NPCO[i]); // DLL.next = DL; // DL.prev = DLL; // DLL = DL; //} }
public void DblLinkedList9() { Node node = new Node(1); node.xVal = 1; node.yVal = 2; DblLinkedList dll = new DblLinkedList(node); Node node2 = new Node(2); node2.xVal = 3; node2.yVal = 4; DblLinkedList dll2 = new DblLinkedList(node2); dll.setNext(dll2); dll2.setPrev(dll); Assert.Equal(1, dll.getNode().xVal); Assert.Equal(3, dll2.getNode().xVal); Assert.Equal(1, dll2.getPrev().getNode().xVal); Assert.Equal(3, dll.getNext().getNode().xVal); }
private void algoTop(NPCObject[] NPC) { // check if we need to perform a convex hull algorithm. if (lessThanTwoCheck(NPC)) { return; } // Go through all but the first and last index's for (int trav = 2; trav < size; trav++) { // find out if the current point is part of the convex hull or not. double hCheck = hullCheck(NPC, prev, curr, trav); DblLinkedList DLL = new DblLinkedList(NPC[trav]); /* * Check if the convex Hull should be outside of the current node */ if (hCheck < curr.NPC.PV.y) { /* * Check each previous node on the convex hull until up until we are sure no current * node will be fully contained in the new convex hull. */ while (prev != head) { /* * Check each new convex hull compared to the previous node. */ double newHullCheck = hullCheck(NPC, prev.prev, prev, trav); if (newHullCheck < prev.NPC.PV.y) { prev = prev.prev; prev.next = DLL; } /* * once we verify that we've found a previous convex hull node that won't change from the * current new node, we quit. */ else { break; } } /* * This handles the same situation as directly above but takes care not to go past the * head. */ if (prev == head) { double newHullCheck = hullCheck(NPC, prev, prev.next, trav); if (newHullCheck < prev.NPC.PV.y) { prev.next = DLL; } } /* * update the connection between the new next convex hull node and the last verified node * on the convex hull. */ DLL.prev = prev; prev.next = DLL; } /* * If the Current Node is Outside the convex hull Then it becomes a part of the new * convex hull */ else { curr.next = DLL; DLL.prev = curr; prev = curr; } /* * update the current node along the convex hull. */ curr = DLL; // printCurrList(); } topEnd = curr; algoBottom(NPC); }
public void NewlyCreatedList_ShouldBeEmpty() { var list = new DblLinkedList <int>(); list.IsEmpty().Should().BeTrue(); }