public void ConstructListSucceeds()
        {
            IList <int> list = new SortedLinkedList <int>();

            Assert.IsNotNull(list);
            Assert.IsTrue(list.Length() == 0);
        }
Exemplo n.º 2
0
        public SortedLinkedList <T> SymmetricDifferenceList(TwoThreeTree <T> B)
        {
            SortedLinkedList <T> ANB = UnionList(B);        //A OR B
            SortedLinkedList <T> BNA = IntersectionList(B); //A AND B.

            return(ANB.Difference(BNA));                    //A OR B - (A AND B)
        }
    public static void Main(string[] args)
    {
        LinkedList <int>         theList = new SortedLinkedList <int>( );
        LinkedListIterator <int> theItr;
        int i;

        theItr = theList.Zeroth( );
        PrintList(theList);

        for (i = 0; i < 10; i++)
        {
            theList.Insert(i * 7 % 10, theItr);
            PrintList(theList);
            theItr.Advance( );
        }

        for (i = 0; i < 10; i += 2)
        {
            theList.Remove(i);
        }

        for (i = 0; i < 10; i++)
        {
            if ((i % 2 == 0) == (theList.Find(i).IsValid( )))
            {
                Console.WriteLine("Find fails!");
            }
        }

        Console.WriteLine("Finished deletions");
        PrintList(theList);
    }
Exemplo n.º 4
0
        public void EmptyFlagFalseInNonEmptyLinkedList()
        {
            var list = new SortedLinkedList <int>();

            list.Insert(4);
            Assert.IsFalse(list.IsEmpty());
        }
        public void RemoveItemSucceeds()
        {
            IList <int> list = new SortedLinkedList <int>();

            list.AddItem(16);
            list.AddItem(3);
            list.AddItem(11);
            list.AddItem(4);
            list.AddItem(25);

            Assert.IsTrue(list.Length() == 5);

            Assert.IsTrue(list.GetNextItem() == 3);
            Assert.IsTrue(list.GetNextItem() == 4);
            Assert.IsTrue(list.GetNextItem() == 11);
            Assert.IsTrue(list.GetNextItem() == 16);
            Assert.IsTrue(list.GetNextItem() == 25);

            list.RemoveItem(11);

            list.ResetList();

            Assert.IsTrue(list.GetNextItem() == 3);
            Assert.IsTrue(list.GetNextItem() == 4);
            Assert.IsTrue(list.GetNextItem() == 16);
            Assert.IsTrue(list.GetNextItem() == 25);
        }
 public static SortedLinkedList<VocabularyItem> Collect(TrieNode root)
 {
     _itemsCollectedInCurThread = new SortedLinkedList<VocabularyItem>
                                         (Configuration.Default.MaxWordsNumberToReturn);
     CollectFromNode(root);
     return _itemsCollectedInCurThread;
 }
        public void InsertInSortedListTest1()
        {
            SortedLinkedList <int> sortedLinkedList = new SortedLinkedList <int>();

            sortedLinkedList.Insert(27);

            Assert.Equal(expected: "27,", actual: sortedLinkedList.ToString());
        }
        public void RemoveElementFromEmptyList_DoesNotThrow()
        {
            var list = new SortedLinkedList <string>((a, b) => a.CompareTo(b));

            Assert.Empty(list);
            list.Remove("Not Present");
            Assert.Empty(list);
        }
        public void ClearElementsFromEmptyList()
        {
            var list = new SortedLinkedList <string>((a, b) => a.CompareTo(b));

            Assert.Empty(list);
            list.Clear();
            Assert.Empty(list);
        }
        public void AddItemFailsWithDuplicateItem()
        {
            IList <int> list = new SortedLinkedList <int>();

            list.AddItem(16);

            Assert.ThrowsException <InvalidOperationException>(() => list.AddItem(16));
        }
        public void AddItemSucceeds()
        {
            IList <int> list = new SortedLinkedList <int>();

            list.AddItem(16);

            Assert.IsTrue(list.Contains(16));
        }
Exemplo n.º 12
0
        public void ctorTest()
        {
            //Act
            var list = new SortedLinkedList();

            //Assert
            Assert.Null(list.Head);
        }
Exemplo n.º 13
0
        public void RemoveShouldNotUpdateCountWhenNotFound()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            list.Add(1);

            Assert.IsFalse(list.Remove(2), "Remove should return false on failure");
            Assert.AreEqual(1, list.Count, "Remove shoud not decrement count on failure");
        }
Exemplo n.º 14
0
        public void AddToEmptyListShouldNoLongerBeEmpty()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            Assert.IsTrue(list.IsEmpty, "New list should be empty");

            list.Add(1);
            Assert.IsFalse(list.IsEmpty, "Added item should no longer be empty list");
        }
Exemplo n.º 15
0
        public void EmptyList()
        {
            var list = new SortedLinkedList <Int32>(compareLogic_Ascending);

            Assert.NotNull(list);
            Assert.Empty(list);
            Assert.Equal(0, list.Count);
            Assert.Equal(null, list.First?.Value);
        }
Exemplo n.º 16
0
        public void RemoveShouldDecrementCountWhenFound()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            list.Add(1);

            Assert.IsTrue(list.Remove(1), "Remove should return true on success");
            Assert.AreEqual(0, list.Count, "Remove should decrement count on success");
        }
Exemplo n.º 17
0
        public void RemoveOfSingleItemInListShouldNowBeEmpty()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            list.Add(1);

            _ = list.Remove(1);
            Assert.IsTrue(list.IsEmpty, "Remove should update IsEmpty on success");
        }
Exemplo n.º 18
0
        public void AddShouldIncrementCount()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            Assert.AreEqual(0, list.Count, "New list should have count of 0");

            list.Add(1);
            Assert.AreEqual(1, list.Count, "Add should increment count");
        }
Exemplo n.º 19
0
        public void AddSingleElementToEmptyList()
        {
            int element = 34;
            var list    = new SortedLinkedList <int>(compareLogic_Ascending);

            list.Add(element);

            Assert.Equal(list.Count, 1);
            Assert.Equal(list.First.Value, element);
        }
Exemplo n.º 20
0
        public void TestClear()
        {
            var list = new SortedLinkedList <int>();

            list.Insert(5);
            list.Insert(-4);
            list.Clear();
            Assert.AreEqual(0, list.Size);
            Assert.True(list.IsEmpty());
        }
Exemplo n.º 21
0
        public void SearchShouldReturnNullWhenNotFound()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            list.Add(1);

            DoubleLinkedNode <int> actual = list.Search(2);

            Assert.IsNull(actual, "Search should return null result when value does not exist in the list");
        }
        public void ListIsFullFails()
        {
            IList <int> list = new SortedLinkedList <int>();

            list.AddItem(16);
            list.AddItem(3);
            list.AddItem(11);

            Assert.IsFalse(list.IsFull());
        }
Exemplo n.º 23
0
        public void SearchShouldReturnNonNullWhenFound()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            list.Add(1);

            DoubleLinkedNode <int> actual = list.Search(1);

            Assert.IsNotNull(actual, "Search should return non-null result when value exists in the list");
            Assert.AreEqual(1, actual.Value, "Search should return the correct value when it exists in the list");
        }
Exemplo n.º 24
0
        public void GivenNumbers_WhenAdded_ShouldBeInAscendingOrder()
        {
            SortedLinkedList list = new SortedLinkedList();

            list.AddElement(56);
            list.AddElement(30);
            list.AddElement(40);
            list.AddElement(70);

            Assert.AreEqual(30, list.head.data);
        }
Exemplo n.º 25
0
        public void TestSimpleLinkedListAddition()
        {
            var list = new SortedLinkedList <int>();

            list.Add(0);
            list.Add(1);
            list.Add(3);
            list.Add(2);

            Assert.AreEqual(2, list.ElementAt(2));
        }
Exemplo n.º 26
0
        private void Init()
        {
            this.solutionPathList = new ArrayList();
            this.ignoredPathList  = new ArrayList();

            this.startNode = new Node(null, this.goalNode, G_COST, this.formula, START_POINT, START_POINT);
            this.goalNode  = new Node(null, null, G_COST, this.formula, MAP_SIZE, MAP_SIZE);

            this.openList   = new SortedLinkedList();
            this.closedList = new SortedLinkedList();
        }
Exemplo n.º 27
0
        /// <summary>
        /// Tests the <see cref="SortedLinkedList{T}.Add(T)"/> method to ensure
        /// that sort order is maintained.
        /// </summary>
        public void AddShouldMaintainSortOrder()
        {
            SortedLinkedList <int> list = new SortedLinkedList <int>();

            list.Add(1);
            list.Add(7);
            list.Add(34);
            list.Add(-1);
            list.Add(9);

            Assert.AreEqual("34, 9, 7, 1, -1", list.ToString(), "Sort order should be maintained by adding values");
        }
        public void RemoveItemFailsWithMissingItem()
        {
            IList <int> list = new SortedLinkedList <int>();

            list.AddItem(16);
            list.AddItem(3);
            list.AddItem(11);
            list.AddItem(4);
            list.AddItem(25);

            Assert.ThrowsException <InvalidOperationException>(() => list.RemoveItem(32));
        }
        public void TestMethod1()
        {
            var list = new SortedLinkedList <int>();

            list.Add(5);
            list.Add(1);
            list.Add(3);
            list.Add(6);
            list.Add(10);
            list.Add(3);
            list.Add(5);
        }
Exemplo n.º 30
0
        public void AddMultipleElementsToList_OrderedAscending_SortedAscending()
        {
            int[] ordered = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var   list    = new SortedLinkedList <int>(compareLogic_Ascending);

            foreach (int i in ordered)
            {
                list.Add(i);
            }

            Assert.Equal(list.Count, ordered.Length);
            Assert.Equal(list.ToArray(), ordered);
        }
Exemplo n.º 31
0
        public void ClearElementsFromList()
        {
            var list = new SortedLinkedList <string>((a, b) => a.CompareTo(b));

            list.Add("A");
            list.Add("B");
            list.Add("C");

            Assert.Equal(list.Count, 3);

            list.Clear();
            Assert.Empty(list);
        }
Exemplo n.º 32
0
		/// <summary>
		/// erstellt eine neue NodeConnection
		/// </summary>
		/// <param name="startNode">Anfangsknoten</param>
		/// <param name="endNode">Endknoten</param>
		/// <param name="ls">LineSegment</param>
		/// <param name="priority">Priorität</param>
		/// <param name="targetVelocity">target velocity</param>
		/// <param name="carsAllowed">Flag, ob Autos auf dieser NodeConnection erlaubt sind</param>
		/// <param name="busAllowed">Flag, ob Busse auf dieser NodeConnection erlaubt sind</param>
		/// <param name="tramAllowed">Flag, ob Straßenbahnen auf dieser NodeConnection erlaubt sind</param>
		/// <param name="enableIncomingLineChange">Flag, ob Spurwechsel auf diese NodeConnection erlaubt sind</param>
		/// <param name="enableOutgoingLineChange">Flag, ob Spurwechsel von dieser NodeConnection erlaubt sind</param>
		public NodeConnection(
			LineNode startNode, 
			LineNode endNode, 
			LineSegment ls, 
			int priority, 
			double targetVelocity,
			bool carsAllowed,
			bool busAllowed,
			bool tramAllowed,
			bool enableIncomingLineChange,
			bool enableOutgoingLineChange)
            {
			// TODO: NodeConnections werden stets mit lineSegment = null initialisiert? Warum?
            this.startNode = startNode;
            this.endNode = endNode;
            lineSegment = ls;

			this._priority = priority;
			this._targetVelocity = targetVelocity;
			this._carsAllowed = carsAllowed;
			this._busAllowed = busAllowed;
			this._tramAllowed = tramAllowed;
			this._enableIncomingLineChange = enableIncomingLineChange;
			this._enableOutgoingLineChange = enableOutgoingLineChange;

			UpdatePen();

			intersectionComparer = delegate(Intersection a, Intersection b)
				{
				bool aA = (this == a._aConnection);
				bool bA = (this == b._aConnection);

				if (aA && bA)
					return a._aTime.CompareTo(b._aTime);
				else if (!aA && bA)
					return a._bTime.CompareTo(b._aTime);
				else if (aA && !bA)
					return a._aTime.CompareTo(b._bTime);
				else
					return a._bTime.CompareTo(b._bTime);
				};

			_intersections = new SortedLinkedList<Intersection>(intersectionComparer);
			statistics = new Statistics[1];
			}
Exemplo n.º 33
0
		/// <summary>
        /// Standardconstruktor (!!! NICHT VERVENDEN !!!) [wird nur für XML Serialisierung gebraucht]
        /// </summary>
        public NodeConnection()
            {
            //** Hier passiert gar nix - die NodeConnection ist nicht funktionsfähig ***\\

			// den intersectionComparer müssen wir trotzdem erstellen...
			intersectionComparer = delegate(Intersection a, Intersection b)
			{
				bool aA = (this == a._aConnection);
				bool bA = (this == b._aConnection);

				if (aA && bA)
					return a._aTime.CompareTo(b._aTime);
				else if (!aA && bA)
					return a._bTime.CompareTo(b._aTime);
				else if (aA && !bA)
					return a._aTime.CompareTo(b._bTime);
				else
					return a._bTime.CompareTo(b._bTime);
			};

			_intersections = new SortedLinkedList<Intersection>(intersectionComparer);
			statistics = new Statistics[1];
			}
Exemplo n.º 34
0
        static void Main(string[] args)
        {

            int choice, data;

            SortedLinkedList List = new SortedLinkedList();
            List.Create();

            while (true)
            {

                Console.WriteLine(" 1.Display the List.");
                Console.WriteLine(" 2.Insert a new Node.");
                Console.WriteLine(" 3.Search.");
                Console.WriteLine(" 4.Exit.");
                Console.WriteLine("Please enter your Choice: ");

                    choice = Convert.ToInt32(Console.ReadLine());

                    if (choice == 4)
                    {
                        break;
                    }
               
                switch (choice)
                {
                    case 1:
                        List.DisplayList();
                        break;
                    case 2:
                        try
                        {
                            Console.WriteLine("Please write the Node to be inserted:");
                            data = Convert.ToInt32(Console.ReadLine());
                            List.InsertInOrder(data);
                        }
                        catch (Exception anExpected)
                        {
                            Console.WriteLine(anExpected.Message);
                        }
                        
                        break;
                    case 3:
                        try
                        {
                            Console.WriteLine("Please write which Node to be Search? ");
                            data = Convert.ToInt32(Console.ReadLine());
                            List.Search(data);
                        }
                        catch (Exception anExpected)
                        {
                            Console.WriteLine(anExpected.Message);
                        }
                        
                        break;
                    case 4:
                        Console.WriteLine("The program is terminated: ");
                        break;
                    default:
                        Console.WriteLine("Incorrect");
                        break;
                }
            }

        }
Exemplo n.º 35
0
        /// <summary>
        /// Złącza pliki wynikowe obiektów tworzących w plik odwróconego indeksu
        /// 
        /// Złącza wszystkie pliki tymczasowe posortowane wszystkich obiektów celu zapisu indeksu IxStdDiskRIIndex.Writer w jeden plik
        /// posortowany wg ID tokenów rosnąco, wag wystąpień w dokumentach malejąco. Tworzy indeks na plik danych.
        /// </summary>
        private void mergeAll()
        {
            /* Posortowana lista czytaczy plików tymczasowych */
            SortedLinkedList<TmpPostingsFileReader> sordedReaders = new SortedLinkedList<TmpPostingsFileReader>();

            /* Dodaj do listy czytacze plików ze wszystkich obiektów celu zapisu indeksu */
            for (int i = 0; i < writers.Count; i++)
            {
                TmpPostingsFileReader[] readers = writers[i].getTmpPostingsFileReaders();

                foreach (TmpPostingsFileReader reader in readers)
                    sordedReaders.add(reader);
            }

            /* Utwórz strumienie binarne do zapisu danych indeksu i indeksu indeksu i używając ich */
            using (BinaryWriter postingsFileWriter = new BinaryWriter(File.Create(indexDirPath + "postings.dat")),
                                postingsIndexFileWriter = new BinaryWriter(File.Create(indexDirPath + "postings.idx")))
            {
                /* Wybierz czytacz pliku tymczasowego o najniższym ID tokenu, najwyższej wadze (tak są posortowane) */
                TmpPostingsFileReader first = sordedReaders.getFirst();

                /* Na potrzeby tworzenia indeksu */
                uint lastTokenId = first.current().tokenId;
                uint count = 0;
                long offset = 0, startOffset = 0;

                /* Nie istnieje token o ID 0, dlatego musimy mu sztucznie wstawić wpis indeksu (zerowy)
                 * aby mechanizmy działały poprawnie */
                if (lastTokenId == 1)
                    writeIndex(postingsIndexFileWriter, 0, 0);

                do
                {
                    /* Usuń z listy pierwszy czytacz */
                    sordedReaders.remove(first);

                    /* Jeśli zmienił się ID tokenu, zapisz wpis w indeksie */
                    if (first.current().tokenId != lastTokenId)
                    {
                        writeIndex(postingsIndexFileWriter, startOffset, count);
                        lastTokenId = first.current().tokenId;
                        count = 0;
                        startOffset = offset;
                    }

                    /* Zapisz wystąpienie, już bez ID tokenu, do pliku danych indeksu */
                    writePosting(postingsFileWriter, first.current().posting);

                    offset += Posting.size;
                    count++;

                    /* Spróbuj odczytać następne wystąpienie przez czytacz, jeśli to nie koniec jego pliku,
                     * dodaj go do listy (sortowanie zostanie zachowane) */
                    first.moveNext();
                    if (!first.end())
                        sordedReaders.add(first);
                }
                while ((first = sordedReaders.getFirst()) != null); // Póki jest jeszcze jakiś czytacz

                /* Zapisz ostatni wpis indeksu */
                writeIndex(postingsIndexFileWriter, startOffset, count);
            }
        }