Пример #1
0
        private static INawArrayUnordered InitializeTestsubject(int maxSize, int initialFilledSize, out NAW[] testSet, int?maxStringLenght = null)
        {
            testSet = RandomNawGenerator.NewArray(initialFilledSize);
            var array = new NawArrayUnordered(maxSize);

            Array.ForEach(testSet, naw => array.Add(naw));

            // We have to clear the log because adding to the array will cause the logger to log as well.
            Logger.Instance.ClearLog();
            return(array);
        }
Пример #2
0
 int FindNaw(NawArrayUnordered array, NAW item, int maxIndex)
 {
     for (int i = 0; i < maxIndex; i++)
     {
         if (array.Array[i].CompareTo(item) == 0)
         {
             return(i);
         }
     }
     return(-1);
 }
Пример #3
0
        static void Main(string[] args)
        {
            // voorbeeld uitprobeercode

            var nieuwArray = new NawArrayUnordered(20);

            nieuwArray.Add(new NAW("Persoon1", "Adres1", "Woonplaats1"));
            var persoon = new NAW("Persoon 1", "Adres 5", "Woonplaats 1");
            int index   = nieuwArray.FindNaam(persoon.Naam);

            System.Console.ReadKey();
        }
Пример #4
0
        private static void week1_UnorderedArray_Testaanroepen()
        {
            // >>>> Testaanroepen week 1 - Unordered Array <<<<

            // Maak het console venster wat groter
            Console.BufferWidth  = 160;
            Console.BufferHeight = 2000;

            NawArrayUnordered array = new NawArrayUnordered(20);

            array.Add(new NAW("Persoon 1", "Adres 1", "Woonplaats 1"));
            array.Add(new NAW("Persoon 2", "Adres 2", "Woonplaats 2"));
            array.Add(new NAW("Persona non grata", "Adres 3", "Woonplaats 3"));
            array.Add(new NAW("Persoon 4", "Adres 4", "Woonplaats 2"));
            array.Add(new NAW("Persoon 1", "Adres 5", "Woonplaats 1"));
            array.Add(new NAW("Persoon 2", "Adres 6", "Woonplaats 2"));
            array.Add(new NAW("Persona non grata", "Adres 7", "Woonplaats 3"));
            array.Add(new NAW("Persoon 2", "Adres 8", "Woonplaats 2"));
            array.Add(new NAW("Persoon 9", "Adres 9", "Woonplaats 1"));
            array.Add(new NAW("Persoon 10", "Adres 10", "Woonplaats 2"));

            System.Console.WriteLine("De ongeordende array na initialisatie maar voor bewerkingen is:");
            array.Show();

            // Activeer onderstaande Huiswerk testaanroepen wanneer je de bijhorende methode hebt geimplementeerd door de commentaarhaken weg te halen.

            /*
             * array.RemoveAtIndex(3);
             * System.Console.WriteLine("\nNa verwijderen van index 3:");
             * array.Show();
             */

            /*
             * array.RemoveFirstNaam("Persoon 1");
             * System.Console.WriteLine("\nNa verwijderen 1e persoon met naam 'Persoon 1':");
             * array.Show();
             */

            /*
             * array.RemoveLastNaam("Persoon 2");
             * System.Console.WriteLine("\nNa verwijderen van laatste persoon met naam 'Persoon 2':");
             * array.Show();
             */

            /*
             * array.RemoveAllNaam("Persona non grata");
             * System.Console.WriteLine("\nNa verwijderen van alle personen met naam 'Persona non grata':");
             * array.Show();
             */
        }
Пример #5
0
        public void NawArrayUnordered_Add_FillWholeArray_ShouldFit()
        {
            // Arrange
            var expectedSize = 10;
            var expectedNaws = RandomNawGenerator.NewArray(expectedSize);

            var array = new NawArrayUnordered(expectedSize);

            // Act
            for (int i = 0; i < expectedSize; i++)
            {
                try
                {
                    array.Add(expectedNaws[i]);
                    Assert.AreEqual(i + 1, array.Count, "\n\nNawArrayUnordered.Add(): Het aantal elementen in de array komt niet overeen met het aantal toegevoegde items.");
                }
                catch (NawArrayUnorderedOutOfBoundsException)
                {
                    // Assert
                    Assert.Fail("\n\nNawArrayUnordered.Add(): Er konden maar {0} NAW-objecten aan een array die met omvang {1} is geinitialiseerd worden toegevoegd", i, expectedSize);
                }
            }
        }
        public void SelectionSort_vs_BubbleSort_10_000Items()
        {
            // Arrange
            NAW[] testSet1; NAW[] testSet2; NAW[] testSet3;

            var expectedLength = 10000;
            var arrayb1        = ArrayExtensions.InitializeTestSubject(new NawArrayUnordered(expectedLength), expectedLength, out testSet1);
            var arrayb2        = ArrayExtensions.InitializeTestSubject(new NawArrayUnordered(expectedLength), expectedLength, out testSet2);
            var arrayb3        = ArrayExtensions.InitializeTestSubject(new NawArrayUnordered(expectedLength), expectedLength, out testSet3);
            var arrays1        = new NawArrayUnordered(expectedLength);
            var arrays2        = new NawArrayUnordered(expectedLength);
            var arrays3        = new NawArrayUnordered(expectedLength);

            for (int i = 0; i < expectedLength; i++)
            {
                arrays1.Add(arrayb1.Array[i]);
                arrays2.Add(arrayb2.Array[i]);
                arrays3.Add(arrayb3.Array[i]);
            }

            Stopwatch stopwatchB1 = new Stopwatch();
            Stopwatch stopwatchB2 = new Stopwatch();
            Stopwatch stopwatchB3 = new Stopwatch();
            Stopwatch stopwatchS1 = new Stopwatch();
            Stopwatch stopwatchS2 = new Stopwatch();
            Stopwatch stopwatchS3 = new Stopwatch();


            // Act

            stopwatchS1.Start();
            arrays1.SelectionSort();
            stopwatchS1.Stop();
            Console.Write("SelectionSort Array 1 :");
            PrintOutput(expectedLength, stopwatchS1);
            Console.WriteLine("");

            stopwatchS2.Start();
            arrays2.SelectionSort();
            stopwatchS2.Stop();
            Console.Write("SelectionSort Array 2 :");
            PrintOutput(expectedLength, stopwatchS2);
            Console.WriteLine("");

            stopwatchS3.Start();
            arrays3.SelectionSort();
            stopwatchS3.Stop();
            Console.Write("SelectionSort Array 3 :");
            PrintOutput(expectedLength, stopwatchS3);
            Console.WriteLine("");

            stopwatchB1.Start();
            arrayb1.BubbleSort();
            stopwatchB1.Stop();
            Console.Write("BubbleSort Array 1 : ");
            PrintOutput(expectedLength, stopwatchB1);
            Console.WriteLine("");

            stopwatchB2.Start();
            arrayb2.BubbleSort();
            stopwatchB2.Stop();
            Console.Write("BubbleSort Array 2 : ");
            PrintOutput(expectedLength, stopwatchB2);
            Console.WriteLine("");

            stopwatchB3.Start();
            arrayb3.BubbleSort();
            stopwatchB3.Stop();
            Console.Write("BubbleSort Array 3 : ");
            PrintOutput(expectedLength, stopwatchB3);
        }