예제 #1
0
        public void TestMethod1()
        {
            int[]    arr  = { 1, 3, 2 };
            TreeSort tree = new TreeSort(arr);

            Assert.AreEqual('3', tree.ToString().Trim()[tree.ToString().Trim().Length - 1]);
        }
        public void TreeSort_Ascending_Smoke_Test()
        {
            var result = TreeSort <int> .Sort(testArray).ToArray();

            for (int i = 0; i < testArray.Length; i++)
            {
                Assert.AreEqual(i, result[i]);
            }
        }
예제 #3
0
        private void TreeSortButton_Click(object sender, EventArgs e)
        {
            TreeLabel.Text = "Time: ";
            var Tree = new TreeSort <int>(Collection, "TreeSort");

            Tree.Sort();
            DisplayInfoFromSort(Tree);
            TreeLabel.Text += Tree.Time.ToString();
        }
        public void TreeSort_Descending_Smoke_Test()
        {
            var result = TreeSort <int> .Sort(testArray, SortDirection.Descending).ToArray();

            for (int i = 0; i < testArray.Length; i++)
            {
                Assert.AreEqual(testArray.Length - i - 1, result[i]);
            }
        }
        public void TreeSort_Smoke_Test()
        {
            var result = TreeSort <int> .Sort(TestArray);

            for (int i = 0; i < TestArray.Length; i++)
            {
                Assert.AreEqual(i, result[i]);
            }
        }
예제 #6
0
        public void TreeSortTest()
        {
            //arrange
            var TreeSort = new TreeSort <int>(dataList, "Tree");

            //act
            TreeSort.Sort();
            //assert
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(sortedItems[i], TreeSort.Items[i]);
            }
        }
        public void TreeSortTest()
        {
            // Arrange
            var tree = new TreeSort <int>(Items);

            // Act
            tree.Sort();

            // Assert
            for (var i = 0; i < Items.Count; i++)
            {
                Assert.AreEqual(Sorted[i], tree.Items[i]);
            }
        }
예제 #8
0
        public void TreeSortTest()
        {
            // arrange
            var tree = new TreeSort <int>(items);

            // act
            tree.Sort();

            // assert
            for (int i = 0; i < items.Count; i++)
            {
                Assert.AreEqual(sorted[i], tree.Items[i]);
            }
        }
        public void TreeSort_Descending_Stress_Test()
        {
            var rnd           = new Random();
            var nodeCount     = 1000;
            var randomNumbers = Enumerable.Range(1, nodeCount)
                                .OrderBy(x => rnd.Next())
                                .ToList();

            var result = TreeSort <int> .Sort(randomNumbers, SortDirection.Descending).ToArray();

            for (int i = 0; i < nodeCount; i++)
            {
                Assert.AreEqual(randomNumbers.Count - i, result[i]);
            }
        }
        public void TreeSort_Ascending_Stress_Test()
        {
            var rnd           = new Random();
            var nodeCount     = 1000;
            var randomNumbers = Enumerable.Range(1, nodeCount)
                                .OrderBy(x => rnd.Next())
                                .ToList();

            var result = TreeSort <int> .Sort(randomNumbers).ToArray();

            for (int i = 1; i <= nodeCount; i++)
            {
                Assert.AreEqual(i, result[i - 1]);
            }
        }
        public void TreeSortTest()
        {
            // arange
            var test = new TreeSort <int>();

            test.Items.AddRange(Items);

            // act
            test.Sort();

            // assert
            for (int i = 0; i < Sorted.Count; i++)
            {
                Assert.AreEqual(Sorted[i], test.Items[i]);
            }
        }
예제 #12
0
        /// <summary>
        /// Retrieve file system information for a path
        /// </summary>
        /// <param name="path"></param>
        /// <param name="noCache"></param>
        /// <param name="distinct"></param>
        /// <param name="results"></param>
        /// <returns></returns>
        public bool GetPath(string path, bool noCache, bool distinct, out List<BrowsingFile> results)
        {
            results = new List<BrowsingFile>();

            //At the root so just return a list of shares
            if (string.IsNullOrEmpty(path) || path == "/")
            {
                var ms = from s in model.Shares
                             orderby s.Name
                             group s by s.Name
                                 into g
                                 select new
                                 {
                                     Name = g.Key,
                                     Size = g.Sum(s => s.Size),
                                     LastModified = g.Count() > 1 ? DateTime.Now : g.First().LastRefresh
                                 };

                foreach (var share in ms)
                {
                    results.Add(new BrowsingFile()
                                    {
                                        IsFolder = true,
                                        Size = share.Size,
                                        LastModified = share.LastModified,
                                        Name = share.Name
                                    });
                }

                return true;
            }

            string[] posiblePaths;
            bool isVirtual = false;

            if (ToLocalPath(path, out posiblePaths))
            {
                Directory scanInfo = GetPath(path, out isVirtual);
                //Have cache info and cache allowed
                if (null != scanInfo && !noCache)
                {
                    foreach (var dir in scanInfo.SubDirectories)
                    {
                        results.Add(new BrowsingFile
                                        {
                                            IsFolder = true,
                                            Size = dir.Size,
                                            Name = dir.Name,
                                            LastModified = DateTime.FromFileTime(dir.LastModified)
                                        });
                    }

                    foreach (var file in scanInfo.Files)
                    {
                        results.Add(new BrowsingFile
                                        {
                                            IsFolder = false,
                                            Size = file.Size,
                                            Name = file.Name,
                                            LastModified = DateTime.FromFileTime(file.LastModified)
                                        });
                    }

                    //Virtual info so clear down to ensure GC works.
                    if (isVirtual)
                    {
                        scanInfo.SubDirectories.Clear();
                        scanInfo.Files.Clear();
                    }
                }
                else
                {
                    //No cache info or cache not allowed, try to pull file information directly.

                    foreach (string posiblePath in posiblePaths)
                    {
                        string fsPath = posiblePath.Replace('/', '\\');
                        if (!fsPath.EndsWith("\\"))
                            fsPath += "\\";

                        //Check for parent folder usage.
                        string checkedPath = Path.GetFullPath(fsPath);
                        //If the evaluated path is different then someone tried to use '..' or similar.
                        if (fsPath != checkedPath)
                            continue;

                        try
                        {
                            var directory = new DirectoryInfo(checkedPath);
                            DirectoryInfo[] directories = directory.GetDirectories();
                            //Get directories
                            foreach (DirectoryInfo dir in directories)
                            {
                                results.Add(new BrowsingFile
                                                {
                                                    IsFolder = true,
                                                    Size = 0,
                                                    Name = dir.Name,
                                                    LastModified = dir.LastWriteTime
                                                });
                            }
                            //Get files
                            FileInfo[] files = directory.GetFiles();
                            foreach (FileInfo file in files)
                            {
                                results.Add(new BrowsingFile
                                                {
                                                    IsFolder = false,
                                                    Size = file.Length,
                                                    Name = file.Name,
                                                    LastModified = file.LastWriteTime
                                                });
                            }
                        }
                        catch { }
                    }

                    if (posiblePaths.Length > 1)
                        isVirtual = true;
                }

                if (distinct)
                {
                    //Check for file folder overlap where multiple directories were used.

                    var folders = new TreeSort<BrowsingFile>();
                    var files = new TreeSort<BrowsingFile>();

                    foreach (var browsingFile in results)
                    {
                        if (browsingFile.IsFolder)
                        {
                            var search = folders.GetValue(browsingFile.Name);
                            if (search.Count == 0)
                            {
                                //Folder not found so add it to the list.
                                folders.PutValue(browsingFile.Name, browsingFile);
                            }
                            else
                            {
                                //Folder already exists, append info.
                                var bf = search.First();
                                bf.Size += browsingFile.Size;
                                if (bf.LastModified < browsingFile.LastModified)
                                    bf.LastModified = browsingFile.LastModified;
                            }

                        }
                        else
                        {
                            var search = files.GetValue(browsingFile.Name);
                            //Only add file the first instance of a file.  Duplicates are hidden.
                            if (search.Count == 0)
                                files.PutValue(browsingFile.Name, browsingFile);
                        }
                    }

                    //Clear existing results
                    results.Clear();
                    //Re-add distinct sorted results.
                    
                    //Folders
                    var fsort = folders.GetAllNodes();
                    for(int i=fsort.Count-1;i>=0;i--)
                    {
                         var search = fsort[i].Values.FirstOrDefault();
                        if (null != search)
                            results.Add(search);
                    }

                  

                    //Files
                    var filesort = files.GetAllNodes();
                    for (int i = filesort.Count - 1; i >= 0; i--)
                    {
                        var search = filesort[i].Values.FirstOrDefault();
                        if (null != search)
                            results.Add(search);
                    }
                }
                return true;
            }

            return false;
        }
예제 #13
0
        private void BtnTreeSort_Click(object sender, EventArgs e)
        {
            var tree = new TreeSort <SortedItem>(items);

            BtnClick(tree);
        }
예제 #14
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}";
        }
예제 #15
0
        /// <summary>
        /// Retrieve file system information for a path
        /// </summary>
        /// <param name="path"></param>
        /// <param name="noCache"></param>
        /// <param name="distinct"></param>
        /// <param name="results"></param>
        /// <returns></returns>
        public bool GetPath(string path, bool noCache, bool distinct, out List <BrowsingFile> results)
        {
            results = new List <BrowsingFile>();

            //At the root so just return a list of shares
            if (string.IsNullOrEmpty(path) || path == "/")
            {
                var ms = from s in model.Shares
                         orderby s.Name
                         group s by s.Name
                         into g
                         select new
                {
                    Name         = g.Key,
                    Size         = g.Sum(s => s.Size),
                    LastModified = g.Count() > 1 ? DateTime.Now : g.First().LastRefresh
                };

                foreach (var share in ms)
                {
                    results.Add(new BrowsingFile()
                    {
                        IsFolder     = true,
                        Size         = share.Size,
                        LastModified = share.LastModified,
                        Name         = share.Name
                    });
                }

                return(true);
            }

            string[] posiblePaths;
            bool     isVirtual = false;

            if (ToLocalPath(path, out posiblePaths))
            {
                Directory scanInfo = GetPath(path, out isVirtual);
                //Have cache info and cache allowed
                if (null != scanInfo && !noCache)
                {
                    foreach (var dir in scanInfo.SubDirectories)
                    {
                        results.Add(new BrowsingFile
                        {
                            IsFolder     = true,
                            Size         = dir.Size,
                            Name         = dir.Name,
                            LastModified = DateTime.FromFileTime(dir.LastModified)
                        });
                    }

                    foreach (var file in scanInfo.Files)
                    {
                        results.Add(new BrowsingFile
                        {
                            IsFolder     = false,
                            Size         = file.Size,
                            Name         = file.Name,
                            LastModified = DateTime.FromFileTime(file.LastModified)
                        });
                    }

                    //Virtual info so clear down to ensure GC works.
                    if (isVirtual)
                    {
                        scanInfo.SubDirectories.Clear();
                        scanInfo.Files.Clear();
                    }
                }
                else
                {
                    //No cache info or cache not allowed, try to pull file information directly.

                    foreach (string posiblePath in posiblePaths)
                    {
                        string fsPath = posiblePath.Replace('/', '\\');
                        if (!fsPath.EndsWith("\\"))
                        {
                            fsPath += "\\";
                        }

                        //Check for parent folder usage.
                        string checkedPath = Path.GetFullPath(fsPath);
                        //If the evaluated path is different then someone tried to use '..' or similar.
                        if (fsPath != checkedPath)
                        {
                            continue;
                        }

                        try
                        {
                            var             directory   = new DirectoryInfo(checkedPath);
                            DirectoryInfo[] directories = directory.GetDirectories();
                            //Get directories
                            foreach (DirectoryInfo dir in directories)
                            {
                                results.Add(new BrowsingFile
                                {
                                    IsFolder     = true,
                                    Size         = 0,
                                    Name         = dir.Name,
                                    LastModified = dir.LastWriteTime
                                });
                            }
                            //Get files
                            FileInfo[] files = directory.GetFiles();
                            foreach (FileInfo file in files)
                            {
                                results.Add(new BrowsingFile
                                {
                                    IsFolder     = false,
                                    Size         = file.Length,
                                    Name         = file.Name,
                                    LastModified = file.LastWriteTime
                                });
                            }
                        }
                        catch { }
                    }

                    if (posiblePaths.Length > 1)
                    {
                        isVirtual = true;
                    }
                }

                if (distinct)
                {
                    //Check for file folder overlap where multiple directories were used.

                    var folders = new TreeSort <BrowsingFile>();
                    var files   = new TreeSort <BrowsingFile>();

                    foreach (var browsingFile in results)
                    {
                        if (browsingFile.IsFolder)
                        {
                            var search = folders.GetValue(browsingFile.Name);
                            if (search.Count == 0)
                            {
                                //Folder not found so add it to the list.
                                folders.PutValue(browsingFile.Name, browsingFile);
                            }
                            else
                            {
                                //Folder already exists, append info.
                                var bf = search.First();
                                bf.Size += browsingFile.Size;
                                if (bf.LastModified < browsingFile.LastModified)
                                {
                                    bf.LastModified = browsingFile.LastModified;
                                }
                            }
                        }
                        else
                        {
                            var search = files.GetValue(browsingFile.Name);
                            //Only add file the first instance of a file.  Duplicates are hidden.
                            if (search.Count == 0)
                            {
                                files.PutValue(browsingFile.Name, browsingFile);
                            }
                        }
                    }

                    //Clear existing results
                    results.Clear();
                    //Re-add distinct sorted results.

                    //Folders
                    var fsort = folders.GetAllNodes();
                    for (int i = fsort.Count - 1; i >= 0; i--)
                    {
                        var search = fsort[i].Values.FirstOrDefault();
                        if (null != search)
                        {
                            results.Add(search);
                        }
                    }



                    //Files
                    var filesort = files.GetAllNodes();
                    for (int i = filesort.Count - 1; i >= 0; i--)
                    {
                        var search = filesort[i].Values.FirstOrDefault();
                        if (null != search)
                        {
                            results.Add(search);
                        }
                    }
                }
                return(true);
            }

            return(false);
        }
예제 #16
0
        private void TreeSortButton_Click_1(object sender, EventArgs e)
        {
            var tree = new TreeSort <SortedItem>(items);

            BttnSort_Click(tree);
        }
예제 #17
0
        private async void Button3_Click(object sender, EventArgs e)
        {
            AlgorithmsBase <int> algorithmsBase = null;
            var Items     = new List <int>();
            var timeSpan  = new List <TimeSpan>();
            var swapCount = new List <int>();

            richTextBoxParser(Items);

            #region Методы для вычисления сортировок.

            algorithmsBase = new BubbleSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.BubbleSort, timeSpan[0], swapCount[0]);
            }
                                                     ));

            algorithmsBase = new CoctailSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.CoctailSort, timeSpan[1], swapCount[1]);
            }
                                                     ));

            algorithmsBase = new InsertSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.InsertionSort, timeSpan[2], swapCount[2]);
            }
                                                     ));

            algorithmsBase = new ShellSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.ShellSort, timeSpan[3], swapCount[3]);
            }
                                                     ));

            algorithmsBase = new HeapSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.HeapSort, timeSpan[4], swapCount[4]);
            }
                                                     ));

            algorithmsBase = new TreeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.TreeSort, timeSpan[5], swapCount[5]);
            }
                                                     ));

            algorithmsBase = new SelectionSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.SelectionSort, timeSpan[6], swapCount[6]);
            }
                                                     ));

            algorithmsBase = new GnomeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.GnomeSort, timeSpan[7], swapCount[7]);
            }
                                                     ));

            algorithmsBase = new MergeSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.MergeSort, timeSpan[8], swapCount[8]);
            }
                                                     ));

            algorithmsBase = new QuickSort <int>();
            await Task.Run(() => AnalysisAlgorithm(algorithmsBase, Items, timeSpan, swapCount));

            await Task.Run(() => richTextBox2.Invoke((Action) delegate
            {
                richTextBoxFill(Constants.QuickSort, timeSpan[9], swapCount[9]);
            }
                                                     ));

            #endregion

            button3.Enabled = false;

            string[] seriesArray = new string[10];
            int[]    pointsArray = new int[10];

            chart1.Series.Clear();
            var countSeries = 0;
            checkBoxCheckedAll(ref countSeries, seriesArray, pointsArray, swapCount);
            chartDefaultSettings(countSeries, pointsArray.Max());

            for (int i = 0; i < seriesArray.Length; i++)
            {
                if (seriesArray[i] != null)
                {
                    Series series = chart1.Series.Add(seriesArray[i]);
                    series.Points.Add(pointsArray[i]);
                }
            }
        }