///Need to fix the logic of finding the start point of loop in linkedList with out using extra space. using runner technique public void FindLoopStartPoint_Positive_Test() { DSLinkedList <int> lnkLst = new DSLinkedList <int>(); lnkLst.Add(-1); lnkLst.Add(-7); lnkLst.Add(7); lnkLst.Add(-4); lnkLst.Add(19); lnkLst.Add(6); lnkLst.Add(-9); lnkLst.Add(-5); lnkLst.Add(2); lnkLst.Add(-5); lnkLst._current.Next = lnkLst._head.Next.Next.Next.Next.Next.Next; DSNode <int> expected = lnkLst._head.Next.Next.Next.Next.Next.Next; IntDSNodeEqualityComparer intDSNodeEqualityComparer = new IntDSNodeEqualityComparer(); DSNode <int> actual = lnkLst.FindLoopStartPoint(); Assert.IsNotNull(actual); Assert.AreEqual(expected, actual); }
public void Add_Detect_Loop_IN_Flyod_Algo_LinkedList() { DSLinkedList <int> lnkLst = new DSLinkedList <int>(); lnkLst.Add(-1); lnkLst.Add(-7); lnkLst.Add(7); lnkLst.Add(-4); lnkLst.Add(19); lnkLst.Add(6); lnkLst.Add(-9); lnkLst.Add(-5); lnkLst.Add(2); lnkLst.Add(-5); lnkLst._head.Next.Next.Next.Next.Next.Next = lnkLst._head; bool expected = true; IntDSNodeEqualityComparer intDSNodeEqualityComparer = new IntDSNodeEqualityComparer(); bool actual = lnkLst.FloydLoopDetect(intDSNodeEqualityComparer); Assert.AreEqual(expected, actual); }
public void Count_Number_Of_Times_Element_Repeated() { DSLinkedList <int> lnkLst = new DSLinkedList <int>(); for (int i = 1; i <= 10; i++) { lnkLst.Add(i * 5); } lnkLst.Add(5); int expected = 2; IntDSNodeEqualityComparer comparer = new IntDSNodeEqualityComparer(); int actual = lnkLst.CountOfRepetationOfElement(5, comparer); Assert.AreEqual(expected, actual); }
public void Add_Test_Delete_Positive_Data_Validation() { DSLinkedList <int> lnkLst = new DSLinkedList <int>(); IntDSNodeEqualityComparer intDSNodeEqualityComparer = new IntDSNodeEqualityComparer(); lnkLst.Add(5); lnkLst.Add(10); lnkLst.Add(15); lnkLst.Add(20); lnkLst.Delete(10, intDSNodeEqualityComparer); int actual2ndIndex = lnkLst.ValueAtIndex(2); lnkLst.Add(25); int actualAt3rdIndex = lnkLst.ValueAtIndex(3); Assert.AreEqual(20, actual2ndIndex); Assert.AreEqual(25, actualAt3rdIndex); }