Exemple #1
0
 private static void AddElements(MyLinkedList<int> myLList, int count)
 {
     for (int i = 0; i < count; i++)
     {
         myLList.Add(i);
     }
 }
            public void should_find_the_last_third_element()
            {
                var listToRead = new List<int> {1, 4, 5, 7, 9, 0, -3, 4, 6, 8};
                var target = 3;
                var pointerslow = listToRead.GetEnumerator();
                var pointerfast = listToRead.GetEnumerator();
                for(int i=0; i<target;i++)
                    pointerfast.MoveNext();
                while(pointerfast.MoveNext())
                {
                    pointerslow.MoveNext();
                }
                pointerslow.MoveNext();
                Assert.That(pointerslow.Current.Equals(4));

                var list = new MyLinkedList<int>();
                list.Insert(0);
                list.Insert(1);
                list.Insert(2);
                list.Insert(3);
                list.Insert(4);
                list.Insert(5);
                list.Insert(6);
                Assert.That(list.FindLastNthElement(3).Equals(4));
            }
 public void NotContainTest()
 {
     MyList<int> List = new MyLinkedList<int>();
     List.Add(31);
     List.Add(9);
     Assert.AreEqual(List.Contains(63), false);
 }
 public void ContainTest()
 {
     MyList<int> List = new MyLinkedList<int>();
     List.Add(31);
     List.Add(9);
     Assert.AreEqual(List.Contains(31), true);
 }
        public VehicleDistance GetDrivedOutVehicleBehindAbsPosition(MyLinkedList<IVehicle> VehicleDrivedOut, VehicleDistance BehindVehicle)
        {
            if (VehicleDrivedOut != null)
            {
                foreach (IVehicle v in VehicleDrivedOut)
                {
                    double x = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.Y - _state.positionAbs.Y);
                    double y = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.Y - _state.positionAbs.Y);

                    double x_rear = -300.0;
                    double y_rear = -300.0;

                    if (BehindVehicle != null)
                    {
                        x_rear = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (BehindVehicle.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (BehindVehicle.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                        y_rear = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (BehindVehicle.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (BehindVehicle.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                    }

                    if (x > x_rear && x < 0 && ((Math.Abs(y) < 50.0 && Math.Abs(y) > 10.0)))
                    {
                        return new VehicleDistance(v, x);
                    }

                }
            }

            return BehindVehicle;
        }
Exemple #6
0
        static void Main(string[] args)
        {
            MyLinkedList<string> list = new MyLinkedList<string>();

            list.AddLast("pesho");
            list.AddLast("gosho");
            list.AddLast("anna");
            list.Add(1, "mariq");
            list.AddFirst("ala bala");

            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            list.Remove("anna");
            list.RemoveFirst();
            list.RemoveLast();

            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            list.Clear();

            Console.WriteLine(list.Count);
        }
        public VehicleDistance GetDrivedOutVehicleFrontAbsPositin(MyLinkedList<IVehicle> VehicleDrivedOut, VehicleDistance FrontVehicle)
        {
            if (VehicleDrivedOut != null)
            {
                foreach (IVehicle v in VehicleDrivedOut)
                {
                    double x = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.Y - _state.positionAbs.Y);
                    double y = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.Y - _state.positionAbs.Y);

                    double x_front = Constants.lookaheadDistance;
                    double y_front = 0.0;

                    if (FrontVehicle != null)
                    {
                        x_front = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (FrontVehicle.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (FrontVehicle.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                        y_front = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (FrontVehicle.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (FrontVehicle.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                    }

                    if (x < x_front && x > 0 && Math.Abs(y) < 50.0)
                    {
                        return new VehicleDistance(v, x);
                    }

                }
            }

            return FrontVehicle;
        }
Exemple #8
0
        private static void TestMyLinkedList()
        {
            MyLinkedList<int> foo = new MyLinkedList<int>();
            foo.AddLast(1);
            foo.AddLast(2);
            foo.AddLast(3);

            try
            {
                foo.AddBefore(foo.First.Next.Next.Next, 7);
                foreach (int item in foo)
                {
                    Console.WriteLine(item);
                }
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("---------");
            foo.Remove(7);
            foreach(int item in foo)
            {
                Console.WriteLine(item);
            }
        }
Exemple #9
0
        static void Main(string[] args)
        {
            MyLinkedList<int> list = new MyLinkedList<int>();
            list.AddFirst(5);
            list.AddAfter(list.FirstElement, -1);
            Console.WriteLine(list);
            list.AddFirst(9);
            Console.WriteLine(list);

            list.Remove(5);
            Console.WriteLine(list);
            return;
            Console.WriteLine();
            Console.WriteLine(list);
            list.AddLast(10);
            Console.WriteLine(list);
            list.AddAfter(list.FirstElement, 111);
            Console.WriteLine(list);
            list.AddAfter(list.FirstElement.NextItem, -100);
            Console.WriteLine(list);
            list.AddBefore(list.FirstElement.NextItem, 999);
            Console.WriteLine(list);
            list.AddBefore(list.FirstElement.NextItem.NextItem.NextItem, 800);
            Console.WriteLine(list);
        }
Exemple #10
0
 private static void PrintWithForEach(MyLinkedList<int> myLList)
 {
     foreach (var element in myLList)
     {
         Console.Write("{0}, ", element);
     }
     Console.WriteLine();
 }
 static void Main(string[] args)
 {
     var ht = new HashTable<int, int>();
     var ll = new MyLinkedList<int>();
     var stackLL = new StackLL<int>();
     var stackArr = new StackArray<int>();
     var queueArr = new QueueArr<int>();
 }
 public void ClearTest()
 {
     MyList<int> List = new MyLinkedList<int>();
     List.Add(1);
     List.Add(2);
     List.Clear();
     Assert.AreEqual(List.Count, 0);
 }
 public void CopyConstructorTest()
 {
     MyList<int> List = new MyLinkedList<int>();
     List.Add(1);
     List.Add(2);
     MyList<int> List2 = new MyLinkedList<int>(List);
     Assert.AreEqual(List2, List);
 }
Exemple #14
0
        public static List<Node> PossibleNode = new List<Node>(); // Les noeuds possibles (cases adjacentes de tout le chemin)

        #endregion Fields

        #region Methods

        public static MyLinkedList<Tile> CalculatePathWithAStar(Map map, Tile startTile, Tile endTile)
        {
            PossibleNode.Clear();
            NodeList<Node> openList = new NodeList<Node>(); // Contiens tout les noeuds candidat (qui vont être examinés)
            NodeList<Node> closedList = new NodeList<Node>(); // Contiens la liste des meilleurs noeuds (le resultat du plus cours chemin)
            List<Node> possibleNodes; // cases adjacentes du noeud courant

            // Le noeud de départ
            Node startNode = new Node(startTile, null, endTile); // FIXME : on recupère le noeud de départ

            /**********************************/
            /* Traitement des noeuds candidat */
            /**********************************/

            openList.Add(startNode);

            while (openList.Count > 0) // Tant que la liste ouverte contient des éléments
            {
                Node current = openList[0];
                openList.RemoveAt(0);
                closedList.Add(current);

                if (current.Tile == endTile) // si l'élément courant est la case destination
                {
                    MyLinkedList<Tile> solution = new MyLinkedList<Tile>();
                    // on reverse la liste fermée et on la retourne pour l'avoir dans le bonne ordre
                    while (current.Parent != null)
                    {
                        solution.AddFirst(current.Tile);
                        current = current.Parent;
                    }
                    return solution;
                }
                possibleNodes = current.GetPossibleNode(map, endTile); // FIXME : recupère la listes des cases adjacentes

                // on ajoute cette liste a notre variable static qui contient l'ensemble des listes adjacentes (gestion de l'affichage)
                PossibleNode.AddRange(possibleNodes) ;

                /***************************************/
                /* Ajout des noeuds adjacents candidat */
                /***************************************/
                for (int i = 0; i < possibleNodes.Count; i++) // on vérifie que chaque noeuds adjacent (possibleNodes)
                {
                    if (!closedList.Contains(possibleNodes[i])) // n'existe pas dans la liste fermée (eviter la redondance)
                    {
                        if (openList.Contains(possibleNodes[i])) // FIXME : Si il existe dans la liste ouverte on vérifie
                        {
                            if (possibleNodes[i].EstimatedMovement < openList[possibleNodes[i]].EstimatedMovement) // si le cout de deplacement du
                                // noeud est inferieur a un coût calculer précedement, dance cas la on remonte le chemin dans la liste ouverte
                                openList[possibleNodes[i]].Parent = current;
                        }
                        else
                            openList.DichotomicInsertion(possibleNodes[i]);
                    }
                }
            }
            return null;
        }
Exemple #15
0
 public void C2Q3()
 {
     var ll = new MyLinkedList<int>();
     ll.Add(1); ll.Add(2); ll.Add(3); ll.Add(4); ll.Add(5);
     ll.DeleteMiddle(ll.FindMiddleNode());
     var test = new MyLinkedList<int>();
     test.Add(1); test.Add(2); test.Add(4); test.Add(5);
     Assert.AreEqual(ll, test);
 }
 //this is an example of generic limitations in C#
 //static bool GenericFunction<T>(T value)
 //where T : operators( +, -, /, * )
 public static MyLinkedList<int> SumOfTwoLists(MyLinkedList<int> list1, MyLinkedList<int> list2)
 {
     var list1CurrentNode = list1.Header;
     var list2CurrentNode = list2.Header;
     const int carry = 0;
     var sumList = new MyLinkedList<int>();
     sumList.Header = SumOfTwoNode(list1CurrentNode, list2CurrentNode, carry);
     return sumList;
 }
Exemple #17
0
 public void C2Q1()
 {
     var result = new MyLinkedList<int>();
     result.Add(1); result.Add(2); result.Add(1); result.Add(3); result.Add(1); result.Add(4); result.Add(1);
     result.RemoveDuplicates();
     var test = new MyLinkedList<int>();
     test.Add(1); test.Add(2); test.Add(3); test.Add(4);
     Assert.AreEqual(result, test);
 }
        public void AddTest()
        {
            int actualValue = 38;
            MyList<int> List = new MyLinkedList<int>();
            List.Add(actualValue);
            Assert.AreEqual(List.Count, 1);
            Assert.AreEqual(List[0], actualValue);

        }
 public void CopyToLinked()
 {
     int[] array = new int[2];
     MyList<int> List = new MyLinkedList<int>();
     List.Add(51);
     List.Add(94);
     List.CopyTo(array, 0);
     Assert.AreEqual(array[0], 51);
     Assert.AreEqual(array[1], 94);
 }
Exemple #20
0
        public static void Main()
        {
            MyLinkedList<int> testLList = new MyLinkedList<int>();
            testLList.InsertElementAtBack(3);
            testLList.InsertElementAtFront(2);
            testLList.InsertElementAtIndex(10, 1);
            testLList.PrintLList();

            testLList.RemoveElementAtIndex(1);
            testLList.PrintLList();
        }
Exemple #21
0
 static void Main(string[] args)
 {
     var ll = new MyLinkedList<int>();
     ll.AddFirst(1);
     ll.AddFirst(2);
     ll.AddFirst(3);
     ll.AddFirst(4);
     ll.AddFirst(5);
     foreach (var link in ll)
     {
         Console.WriteLine(link);
     }
 }
Exemple #22
0
        public void AddAfterKey_OneElem_NoKey()
        {
            //arrange
            Person p1 = new Person("1", 1);
            Person p2 = new Person("2", 2);

            MyLinkedList list = new MyLinkedList(p1);

            //act
            list.AddAfterKey(p2, p1);

            ////assert
            Assert.AreEqual(list.Count(), 1);
        }
Exemple #23
0
        public static void display(MyLinkedList list)
        {
            var temp = list.Root;

            while (temp != null)
            {
                Console.Write($"{temp.Data}->");
                //Console.Write($"{temp.Next?.Data ?? 0}");
                temp = temp.Next;
                //Console.WriteLine();
            }
            Console.Write("null");
            Console.WriteLine();
        }
Exemple #24
0
        public void AmountAfterPopulateEmpty()
        {
            //arrange
            var          amount_of_elements = 0;
            int          expected           = 1;
            MyLinkedList list = new MyLinkedList();

            //act
            list.Populate(amount_of_elements);
            int actual = list.Count;

            //assert
            Assert.AreEqual(expected, actual);
        }
Exemple #25
0
        public void InsertBefore_should_add_node_before_specified_node()
        {
            var myLinkedList = new MyLinkedList();

            myLinkedList.AddToFirst("firstElement");
            myLinkedList.AddToLast("thirdElement");

            myLinkedList.InsertBefore("thirdElement", "secondElement");
            //get node
            var secondElement = myLinkedList.GetNode("secondElement");

            //verify that the secondElement is added before third
            Assert.AreEqual(secondElement.Next.Data, "thirdElement");
        }
Exemple #26
0
        public void RemoveNode_should_remove_Node_from_the_list()
        {
            var myLinkedList = new MyLinkedList();

            myLinkedList.AddToLast("firstElement");
            myLinkedList.AddToLast("secondElement");
            myLinkedList.AddToLast("thirdElement");

            myLinkedList.RemoveNode("secondElement");

            var firstNode = myLinkedList.GetFirstNode();

            Assert.AreEqual(firstNode.Next.Data, "thirdElement");
        }
Exemple #27
0
        static void Main(string[] args)
        {
            var list = new MyLinkedList();

            list.AddNode("3");
            list.AddNode("4");
            list.AddNode("5");
            var worker = new LinkedListWorker();

            worker.PrintLinkedList(list);
            worker.ReverseList(list);
            worker.PrintLinkedList(list);
            Console.ReadLine();
        }
Exemple #28
0
        public void AddNode_NegativeAdd2Node_outCount0()
        {
            //arrange
            int expected = 0;//Предпологаем что отработает не корректно.
            //actual
            MyLinkedList myList = new MyLinkedList();

            myList.AddNode(1);
            myList.AddNode(1);
            int actual = myList.GetCount();

            //assert
            Assert.AreEqual <int>(expected, actual);
        }
Exemple #29
0
        public void LinkedListTest_SingleElementYesCycleReturnsTrue()
        {
            // Arrange
            MyLinkedList l    = new MyLinkedList();
            MyListNode   head = new MyListNode(1);

            head.next = head;

            // Act
            bool result = l.HasCycle(head);

            // Assert
            Assert.IsTrue(result);
        }
        public void Given3NumbersWhenAppendedToLinkedListShouldAddedToLast()
        {
            MyNode <int> myFirstNode  = new MyNode <int>(56);
            MyNode <int> mySecondNode = new MyNode <int>(30);
            MyNode <int> myThirdNode  = new MyNode <int>(70);
            MyLinkedList myLinkedList = new MyLinkedList();

            myLinkedList.Add((INode <int>)myFirstNode);
            myLinkedList.append((INode <int>)mySecondNode);
            myLinkedList.append((INode <int>)myThirdNode);
            bool result = myLinkedList.head.Equals(myFirstNode) && myLinkedList.head.GetNext().Equals(mySecondNode) && myLinkedList.tail.Equals(myThirdNode);

            Assert.AreEqual(result, false);
        }
        public void AddAfterCanAddLast()
        {
            //Arrange
            Node         firstNode  = new Node(1);
            Node         secondNode = new Node(2);
            MyLinkedList list1      = new MyLinkedList(firstNode);

            //Act
            list1.AddAfter(secondNode, firstNode);
            Node found = list1.KthElement(0);

            //Assert
            Assert.Equal(secondNode, found);
        }
        public void TestgenericDeleteLast()
        {
            MyLinkedList <ClubMember> list = new MyLinkedList <ClubMember>();

            list.Insert(p5);  // p5
            list.Insert(p21); // p21, p5
            list.Insert(p9);  // p9, p21, p5
            list.Insert(p24); // p24, p9, p21, p5
            list.Delete(3);   // p24, p9, p21

            Assert.AreEqual(p24, list.ItemAt(0));
            Assert.AreEqual(p9, list.ItemAt(1));
            Assert.AreEqual(p21, list.ItemAt(2));
        }
        public void Destroy_LinkedList()
        {
            var myLinkedList = new MyLinkedList <int>(10);

            myLinkedList.Append(51);
            myLinkedList.Append(16);
            myLinkedList.Append(99);

            myLinkedList.Destroy();

            Assert.Null(myLinkedList.Head);
            Assert.Null(myLinkedList.Tail);
            Assert.Equal(0, myLinkedList.Length);
        }
        public void Append_Two_Elements()
        {
            var myLinkedList = new MyLinkedList <int>(10);

            myLinkedList.Append(5);
            myLinkedList.Append(16);

            Assert.Equal(10, myLinkedList.Head.Value);
            Assert.Equal(5, myLinkedList.Head.Next.Value);
            Assert.Equal(16, myLinkedList.Head.Next.Next.Value);
            Assert.Null(myLinkedList.Head.Next.Next.Next);
            Assert.Equal(16, myLinkedList.Tail.Value);
            Assert.Equal(3, myLinkedList.Length);
        }
Exemple #35
0
        public void RemoveNodeByNode_removeInEmptyList_outEception()
        {
            //arrange

            //actual
            MyLinkedList myList = new MyLinkedList();
            Node         fNode  = new Node()
            {
                Value = 1
            };

            myList.RemoveNode(fNode);
            //assert
        }
        public MyLinkedList <T> DeleteMiddleNode(MyLinkedList <T> nodeToDelete)
        {
            if (nodeToDelete == null || nodeToDelete.Next == null)
            {
                return(null);
            }

            MyLinkedList <T> next = nodeToDelete.Next;

            nodeToDelete.Data = next.Data;
            nodeToDelete.Next = next.Next;

            return(_list);
        }
Exemple #37
0
        public void AddNode_add2Node_outCount2()
        {
            //arrange
            int expected = 2;
            //actual
            MyLinkedList myList = new MyLinkedList();

            myList.AddNode(1);
            myList.AddNode(1);
            int actual = myList.GetCount();

            //assert
            Assert.AreEqual <int>(expected, actual);
        }
Exemple #38
0
        /// <summary>
        ///
        /// using a Stack
        ///
        /// 1 -> 2 -> 2 -> 1
        ///
        /// 1 -> 2 -> 3 -> 2 -> 1
        ///
        /// </summary>
        public static void Run()
        {
            MyLinkedList list1 = new MyLinkedList();

            list1.head                     = new Node(1);
            list1.head.next                = new Node(2);
            list1.head.next.next           = new Node(3);
            list1.head.next.next.next      = new Node(2);
            list1.head.next.next.next.next = new Node(1);
            bool result = IsPalindrome(list1.head);

            Console.WriteLine(result);
            Console.ReadLine();
        }
Exemple #39
0
        public void FindNode_FindValue1_outValue1()
        {
            //arrange
            int expected = 1;
            //actual
            MyLinkedList myList = new MyLinkedList();

            myList.AddNode(1);
            Node fNode  = myList.FindNode(1);
            int  actual = fNode.Value;

            //assert
            Assert.AreEqual <int>(expected, actual);
        }
Exemple #40
0
        public void Test_RemoveLast_add_another(int removeAt, params int[] expected)
        {
            var cut = new MyLinkedList <int> {
                1, 2, 3, 4
            };

            cut.RemoveAt(removeAt);
            cut.Add(5);

            var actual = cut.Items().ToList();

            Assert.Equal(expected.ToList(), actual);
            Assert.Equal(4, cut.Count);
        }
        public void Given3ElementCheckPerticularElementPresentOrNot()
        {
            MyNode <int> firstNode    = new MyNode <int>(56);
            MyNode <int> secondNode   = new MyNode <int>(30);
            MyNode <int> thirdNode    = new MyNode <int>(70);
            MyLinkedList myLinkedList = new MyLinkedList();

            myLinkedList.append((INode <int>)firstNode);
            myLinkedList.append((INode <int>)secondNode);
            myLinkedList.append((INode <int>)thirdNode);
            bool result = myLinkedList.searchNode((INode <int>)secondNode);

            Assert.AreEqual(true, result);
        }
Exemple #42
0
        static void Main(string[] args)
        {
            var myll = new MyLinkedList();

            myll.AddTail(10);
            myll.AddTail(20);
            myll.AddTail(30);
            myll.AddTail(40);
            myll.AddTail(50);


            Console.WriteLine(myll.KthNodeFromEnd(2));
            myll.Print();
        }
        public void Example1()
        {
            var myLinkedList = new MyLinkedList();

            myLinkedList.AddAtHead(1);
            myLinkedList.AddAtTail(3);
            myLinkedList.AddAtIndex(1, 2);

            Assert.AreEqual(3, myLinkedList.Get(2));

            myLinkedList.DeleteAtIndex(1);

            Assert.AreEqual(3, myLinkedList.Get(1));
        }
Exemple #44
0
        public void ContainsTest()
        {
            MyLinkedList <string> list = new MyLinkedList <string>();

            list.AddLast("abs");
            list.AddLast("zzz");
            list.AddLast("ыыыы");
            Assert.IsTrue(list.Contains("abs"));
            Assert.IsTrue(list.Contains("zzz"));
            Assert.IsTrue(list.Contains("ыыыы"));
            Assert.IsFalse(list.Contains("iqewojf   2"));
            Assert.IsFalse(list.Contains(""));
            Assert.IsFalse(list.Contains(null));
        }
Exemple #45
0
        public void RemoveAt_RemoveItemAtIndex3InListOf3Items_ThrowsIndexOutOfRangeException()
        {
            //arrange
            int index = 3;
            MyLinkedList <int> list = new MyLinkedList <int>()
            {
                1, 2, 3
            };

            //act

            //assert
            Assert.Throws <IndexOutOfRangeException>(() => list.RemoveAt(index));
        }
Exemple #46
0
        public void AddAfterKey_ClearCollection()
        {
            //arrange
            Person p1 = new Person("1", 1);
            Person p2 = new Person("2", 2);

            MyLinkedList list = new MyLinkedList();

            //act
            list.AddAfterKey(p1, p2);

            ////assert
            Assert.AreEqual(list.Count(), 0);
        }
Exemple #47
0
        public void Add_AddOneItemToCollection_CollectionSizeIncreased()
        {
            //arrange
            int item                = 0;
            int expected            = 1;
            MyLinkedList <int> list = new MyLinkedList <int>();

            //act
            list.Add(item);
            int actual = list.Count;

            //assert
            Assert.Equal(expected, actual);
        }
Exemple #48
0
        static void Main()
        {
            MyLinkedList<int> myLList = new MyLinkedList<int>();

            AddElements(myLList, 20);

            PrintWithForEach(myLList);

            int pos = myLList.LastIndexOf(4);

            Console.WriteLine("{0}", pos);

            Console.Read();
        }
        public void TestDesigner2NullRef()
        {
            bool result = true;

            try
            {
                MyLinkedList <string> l = new MyLinkedList <string>(null);
            }
            catch
            {
                result = false;
            }
            Assert.AreEqual(false, result);
        }
Exemple #50
0
        public void Indexer_GetItemAtIndexNegative1_ThrowsIndexOutOfRangeException()
        {
            //arrange
            int index = -1;
            MyLinkedList <int> list = new MyLinkedList <int>()
            {
                1, 2, 3
            };

            //act

            //assert
            Assert.Throws <IndexOutOfRangeException>(() => list[index]);
        }
        public void TestDesignerSizeDelowZero()
        {
            bool result = true;

            try
            {
                MyLinkedList l = new MyLinkedList(-4);
            }
            catch
            {
                result = false;
            }
            Assert.AreEqual(false, result);
        }
Exemple #52
0
        public void TestDeleteAt()
        {
            MyLinkedList l1 = new MyLinkedList();

            l1.Insert(c2);
            l1.Insert(c1);
            l1.Insert(c3, 1);
            l1.Insert(c4, 0);
            l1.Insert(c5, 4);
            l1.Delete(3);
            l1.Delete(3);
            Assert.AreEqual(3, l1.Count);
            Assert.AreEqual("4 Kurt Nielsen 33\n2 Bjørn Borg 30\n3 Cristian Nielsen 20\n", l1.ToString());
        }
 public void should_return_list_with_all_unique_elements()
 {
     var list = new MyLinkedList<int>();
     list.Insert(0);
     list.Insert(1);
     list.Insert(1);
     list.Insert(2);
     list.Insert(3);
     list.Insert(3);
     list.Insert(1);
     list.Insert(0);
     list.Insert(5);
     list.RemoveDuplicates();
     Assert.That(list.Size().Equals(5));
 }
 public void InvalidCopyToLinked()
 {
     int[] array = new int[2];
     MyList<int> List = new MyLinkedList<int>();
     List.Add(51);
     List.Add(94);
     try
     {
         List.CopyTo(array, 2);
     }
     catch (IndexOutOfRangeException e)
     {
         StringAssert.Contains(e.Message, "Индекс вне диапазона.");
     }
 }
            public void should_return_one_single_linked_list_reprenting_the_sum()
            {
                var list1 = new MyLinkedList<int>();
                list1.Insert(3);
                list1.Insert(1);
                list1.Insert(5);

                var list2 = new MyLinkedList<int>();
                list2.Insert(5);
                list2.Insert(9);
                list2.Insert(2);

                var sumList = LinkedListHelper.SumOfTwoLists(list1, list2);
                Assert.That(sumList.Size().Equals(3));
            }
        static void Main()
        {
            ListItem<string> first = new ListItem<string>("First");
            ListItem<string> second = new ListItem<string>("Second");
            ListItem<string> third = new ListItem<string>("Third");

            var myLinkedList = new MyLinkedList<string>();
            myLinkedList.FirstElement = first;
            first.Next = second;
            second.Next = third;

            foreach (var item in myLinkedList)
            {
                Console.WriteLine(item);
            }
        }
    static void Main()
    {
        Console.WriteLine("Dot Net LinkedList");
        LinkedList<int> dotNetList = new LinkedList<int>();
        dotNetList.AddFirst(3);
        dotNetList.AddFirst(1);
        dotNetList.AddBefore(dotNetList.Last, 2);
        dotNetList.AddBefore(dotNetList.First, 4);
        dotNetList.AddAfter(dotNetList.Last, 5);
        dotNetList.AddAfter(dotNetList.First, 6);
        dotNetList.AddLast(7);
        dotNetList.AddLast(8);
        dotNetList.RemoveFirst();
        dotNetList.RemoveLast();

        foreach (var item in dotNetList)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine("Dot Net LinkedList.Count = {0}", dotNetList.Count);

        Console.WriteLine();
        Console.WriteLine("My LinkedList<T>");
        MyLinkedList<int> myList = new MyLinkedList<int>();
        myList.AddFirst(3);
        myList.AddFirst(1);
        myList.AddBefore(myList.Last, 2);
        myList.AddBefore(myList.First, 4);
        myList.AddAfter(myList.Last, 5);
        myList.AddAfter(myList.First, 6);
        myList.AddLast(7);
        myList.AddLast(8);
        myList.RemoveFirst();
        myList.RemoveLast();

        foreach (var number in myList)
        {
            Console.WriteLine(number);
        }
        Console.WriteLine("MyList.Count = {0}", myList.Count);
    }
        public void JumpOrder_FiveElements_MixOfPointers_OrderIsCorrect()
        {
            MyLinkedList<string> list = new MyLinkedList<string>();
              list.Append("hi");
              list.Append("there");
              list.Append("friend");
              list.Append("and");
              list.Append("gents");

              list.SetJumpNode(0, 3);
              list.SetJumpNode(1, 0);
              list.SetJumpNode(2, 1);
              list.SetJumpNode(3, 1);
              list.SetJumpNode(4, 3);

              list.ComputeJumpOrder();

              MyLinkedListNode<string>[] nodes = list.GetNodeElements();
              List<int> expectedOrder = new List<int>() { 1, 3, 4, 2, 5 };
              VerifyJumpOrders(expectedOrder, nodes);
        }
        public void GetDrivedOutVehiclesAroundAbsPosition(MyLinkedList<IVehicle> VehicleDrivedOut)
        {
            if (VehicleDrivedOut != null)
            {
                foreach (IVehicle v in VehicleDrivedOut)
                {
                    double x = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.Y - _state.positionAbs.Y);
                    double y = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (v.state.positionAbs.Y - _state.positionAbs.Y);

                    double x_front = 300.0;
                    double y_front = 300.0;

                    double x_rear = -300.0;
                    double y_rear = -300.0;

                    if (otherVehicles.Left != null)
                    {
                        x_rear = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Left.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Left.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                        y_rear = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Left.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Left.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                    }

                    if (otherVehicles.Right != null)
                    {
                        x_front = Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Right.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Right.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                        y_front = -Math.Sin(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Right.vehicle.state.positionAbs.X - _state.positionAbs.X) + Math.Cos(Math.Atan(_state.orientation.Y / _state.orientation.X)) * (otherVehicles.Right.vehicle.state.positionAbs.Y - _state.positionAbs.Y);
                    }

                    if (x < x_front && x > 0 && Math.Abs(y) < 50.0)
                    {
                        if (otherVehicles.Right != null)
                        {
                            otherVehicles.Right = null;
                            otherVehicles.Right = new VehicleDistance(v, x);
                        }
                        else
                        {
                            otherVehicles.Right = new VehicleDistance(v, x);
                        }
                    }
                    if (x > x_rear && x < 0 && Math.Abs(y) < 50.0)
                    {
                        if (otherVehicles.Left != null)
                        {
                            otherVehicles.Left = null;
                            otherVehicles.Left = new VehicleDistance(v, x);
                        }
                        else
                        {
                            otherVehicles.Left = new VehicleDistance(v, x);
                        }
                    }
                }
            }
        }
 public void FindExistingElement()
 {
     MyList<int> List = new MyLinkedList<int>();
     List.Add(8);
     List.Add(61);
     Assert.AreEqual(List.Find(8), 0);
     Assert.AreEqual(List.Find(61), 1);
 }