コード例 #1
0
        public void GnomeSort()
        {
            var algorithm    = new GnomeSort();
            var sortedVector = algorithm.Sort(DataDefinition.UnsortedVector());

            Assert.Equal(DataDefinition.SortedVector, sortedVector);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: KorzunK/Sorting
        static void Main(string[] args)
        {
            Random r = new Random();
            int size = r.Next(100, 100);
            var sortable = new List<int>();
            Stopwatch timer = new Stopwatch();

            for (int i = 0; i < size; i++)
            {
                sortable.Add(r.Next(-230, 26));
            }

            var algorithm = new GnomeSort<int>();

            timer.Start();
            algorithm.Sort(sortable);
            timer.Stop();

            TimeSpan time = timer.Elapsed;

            string elapsedTime = String.Format("{0:00}.{1:00}", time.Seconds, time.Milliseconds / 10);

            Console.WriteLine("GnomeSort runtime = " + elapsedTime + "\n");

            Console.WriteLine("Result:");
            foreach (var res in sortable)
            {
                Console.WriteLine(res);
            }

            Console.ReadLine();
        }
コード例 #3
0
   public void TestGnomeSort()
   {
       int[] arr = { 3, 7, 4, 8, 6, 2, 1, 5 };
       int n = arr.Length;
 
       var actual = sort.Sort(arr, n);
       var expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
       Assert.Equal(expected, actual);
   }
コード例 #4
0
ファイル: ArraySortTest.cs プロジェクト: amendubaev/Practice
        public void SortTest(double[] array, double[] result)
        {
            var gnomeSort  = new GnomeSort();
            var bubbleSort = new BubbleSort();

            double[] testGnomeResult  = gnomeSort.Sort(array);
            double[] testBubbleResult = bubbleSort.Sort(array);
            Assert.AreEqual(testBubbleResult, result);
            Assert.AreEqual(testGnomeResult, result);
        }
コード例 #5
0
ファイル: SortTests.cs プロジェクト: Yersen/Sort_Algorithms
        public void GnomeSort()
        {
            var gnome = new GnomeSort <int>();

            gnome.Items.AddRange(items);
            gnome.Sort();
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], gnome.Items[i]);
            }
        }
コード例 #6
0
ファイル: AllTest.cs プロジェクト: vlyashko02/Sort
        public void GnomeSortTest()
        {
            int[] result = CreateResultArray();

            GnomeSort <int> sort = new GnomeSort <int>(result);

            result = sort.Sort();

            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
コード例 #7
0
        public void GnomeSortTest()
        {
            //arrange
            var gnome = new GnomeSort <int>(dataList, "Gnome");

            //act
            gnome.Sort();
            //assert
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(sortedItems[i], gnome.Items[i]);
            }
        }
コード例 #8
0
        public void GnomeSortTest()
        {
            // arrange
            var gnome = new GnomeSort <int>();

            gnome.Items.AddRange(Items);
            // act
            gnome.Sort();
            // assert
            for (int i = 0; i < gnome.Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], gnome.Items[i]);
            }
        }
コード例 #9
0
        public void GnomeSortTest()
        {
            //Act
            var gnome = new GnomeSort <int>();

            gnome.Items.AddRange(items);
            gnome.Sort();
            items.Sort();

            //Assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(items[i], gnome.Items[i]);
            }
        }
コード例 #10
0
 private void GnomeSortButton_Click(object sender, EventArgs e)
 {
     if (Collection.Count < 10001)
     {
         GnomeLabel.Text = "Time: ";
         var Gnome = new GnomeSort <int>(Collection, "GnomeSort");
         Gnome.Sort();
         DisplayInfoFromSort(Gnome);
         GnomeLabel.Text += Gnome.Time.ToString();
     }
     else
     {
         GnomeLabel.Text = "To much for it ...";
     }
 }
コード例 #11
0
        public void Run()
        {
            int[]           iArrary = new int[] { 1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47 };
            GnomeSort       gs      = new GnomeSort();
            InsertionSorter ii      = new InsertionSorter();
            BubbleSorter    bs      = new BubbleSorter();
            SelectionSorter ss      = new SelectionSorter();
            ShellSorter     sh      = new ShellSorter();

            gs.Sort(iArrary);
            for (int m = 0; m < iArrary.Length; m++)
            {
                Console.Write("{0} ", iArrary[m]);
            }
            Console.WriteLine();

            Console.ReadKey();
        }
コード例 #12
0
        private void AllSortButton_Click(object sender, EventArgs e)
        {
            SortDatarichTextBox.Text = "Calculating ... Wait a moment ...";
            BubbleLabel.Text         = "Time: ";
            SelectionLabel.Text      = "Time: ";
            CocktailLabel.Text       = "Time: ";
            GnomeLabel.Text          = "Time: ";
            HeapLabel.Text           = "Time: ";
            InsertionLabel.Text      = "Time: ";
            LSDLabel.Text            = "Time: ";
            MSDLabel.Text            = "Time: ";
            MergeLabel.Text          = "Time: ";
            QuickLabel.Text          = "Time: ";
            ShellLabel.Text          = "Time: ";
            TreeLabel.Text           = "Time: ";
            SortDatarichTextBox.Text = "";
            var min = new List <BaseAlgorithm <int> >();

            if (Collection.Count < 10001)
            {
                var bubble = new BubbleSort <int>(Collection, "BubbleSort");
                bubble.Sort();
                BubbleLabel.Text += bubble.Time.ToString();
                min.Add(bubble);
            }
            if (Collection.Count < 10001)
            {
                var selection = new SelectionSort <int>(Collection, "SelectionSort");
                selection.Sort();
                SelectionLabel.Text += selection.Time.ToString();
                min.Add(selection);
            }
            if (Collection.Count < 10001)
            {
                var cocktail = new CocktailSort <int>(Collection, "CocktailSort");
                cocktail.Sort();
                CocktailLabel.Text += cocktail.Time.ToString();
                min.Add(cocktail);
            }
            if (Collection.Count < 10001)
            {
                var Gnome = new GnomeSort <int>(Collection, "GnomeSort");
                Gnome.Sort();
                GnomeLabel.Text += Gnome.Time.ToString();
                min.Add(Gnome);
            }
            if (Collection.Count < 10001)
            {
                var Insertion = new InsertionSort <int>(Collection, "InsertionSort");
                Insertion.Sort();
                InsertionLabel.Text += Insertion.Time.ToString();
                min.Add(Insertion);
            }
            var Tree = new TreeSort <int>(Collection, "TreeSort");

            Tree.Sort();
            TreeLabel.Text += Tree.Time.ToString();
            min.Add(Tree);
            var Heap = new HeapSort <int>(Collection, "HeapSort");

            Heap.Sort();
            HeapLabel.Text += Heap.Time.ToString();
            min.Add(Heap);
            var LSDRadix = new LSDRadixSort <int>(Collection, "LSDRadixSort");

            LSDRadix.Sort();
            LSDLabel.Text += LSDRadix.Time.ToString();
            min.Add(LSDRadix);
            var MSDRadix = new MSDRadixSort <int>(Collection, "MSDRadixSort");

            MSDRadix.Sort();
            MSDLabel.Text += MSDRadix.Time.ToString();
            min.Add(MSDRadix);
            var Merge = new MergeSort <int>(Collection, "MergeSort");

            Merge.Sort();
            MergeLabel.Text += Merge.Time.ToString();
            min.Add(Merge);
            var Quick = new QuickSort <int>(Collection, "QuickSort");

            Quick.Sort();
            QuickLabel.Text += Quick.Time.ToString();
            min.Add(Quick);
            var Shell = new ShellSort <int>(Collection, "ShellSort");

            Shell.Sort();
            ShellLabel.Text += Shell.Time.ToString();
            min.Add(Shell);
            var best = GetMinTime(min);

            SortDatarichTextBox.Text = $"THE BEST:\n" + best.Name + $"\n{best.Time}";
        }