public void SortTest()
        {
            //arrenge
            var koktail = new KoktailSort <int>();
            var rnd     = new Random();
            var items   = new List <int>();

            for (int i = 0; i < 15; i++)
            {
                items.Add(rnd.Next(0, 100));
            }
            koktail.Items.AddRange(items);
            var sorted = items.OrderBy(x => x).ToArray();//стадартная сортировка List

            //act
            koktail.Sort();
            //assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], koktail.Items[i]);
            }
        }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            var sw = new Stopwatch();

            Thread.Sleep(1500);
            sw.Start();
            var rnd = new Random();

            for (int i = 0; i < 20; i++)
            {
                var val  = rnd.Next(0, 100);
                var item = new SortedItem(val);
                items.Add(item);
                SetProperty(label3, item);
            }
            //---------------
            sw.Restart();
            var bubble = new BubbleSort <SortedItem>();

            bubble.Items.AddRange(items);
            bubble.Sort();
            foreach (var i in bubble.Items)
            {
                SetProperty(label4, i);
            }
            sw.Stop();
            label4.Text += $"\t{sw.ElapsedMilliseconds.ToString()} мс";
            //----------------
            sw.Restart();
            var coctail = new KoktailSort <SortedItem>();

            coctail.Items.AddRange(items);
            coctail.Sort();
            foreach (var i in coctail.Items)
            {
                SetProperty(label5, i);
            }
            sw.Stop();
            label5.Text += $"\t{sw.ElapsedMilliseconds.ToString()} мс";
            //-----------------
            sw.Restart();
            var insert = new InsertSort <SortedItem>();

            insert.Items.AddRange(items);
            insert.Sort();
            foreach (var i in insert.Items)
            {
                SetProperty(label6, i);
            }
            sw.Stop();
            label6.Text += $"\t  {sw.ElapsedMilliseconds.ToString()} мс";
            //----------------------
            sw.Restart();
            var shell = new ShellSort <SortedItem>();

            shell.Items.AddRange(items);
            shell.Sort();
            foreach (var i in shell.Items)
            {
                SetProperty(label7, i);
            }
            sw.Stop();
            label7.Text += $"\t{sw.ElapsedMilliseconds.ToString()} мс";
            //----------------------
            items.Clear();
        }