示例#1
0
        public void InsertionTest()
        {
            int[] xs = { 3, 2, 1, 6, 5, 9, 4 };
            Insertion <int> .Sort(xs);

            Assert.True(Sorting <int> .IsSorted(xs));
        }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void IndexSort_Elementary_IsSorted()
        {
            IComparable[]     unsortedArray = "edcba".Select(c => c.ToString()).ToArray();
            IEnumerable <int> expectedArray = new List <int>()
            {
                4, 3, 2, 1, 0
            };

            var sortedIndex = Insertion.IndexSort(unsortedArray);

            CollectionAssert.AreEqual(sortedIndex, expectedArray);

            unsortedArray = "ADBC".Select(c => c.ToString()).ToArray();
            //a[0]->A
            //a[2]->B
            //a[3]->C
            //a[1]->D
            expectedArray = new List <int>()
            {
                0, 2, 3, 1
            };

            sortedIndex = Insertion.IndexSort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, sortedIndex);
        }
示例#3
0
文件: Program.cs 项目: abulanadi/Lab4
        static void Main(string[] args)
        {
            Insertion  insertion  = new Insertion();
            NaiveQuick naiveQuick = new NaiveQuick();
            Merge      merge      = new Merge();
            Bubble     bubble     = new Bubble();
            Quick      quick      = new Quick();

            /*naiveQuick.checkSortCorrect();
             * Console.WriteLine();
             * insertion.checkSortCorrect();
             * Console.WriteLine();
             * merge.checkSortCorrect();
             * Console.WriteLine();
             * bubble.checkSortCorrect();
             * Console.WriteLine();
             * quick.checkSortCorrect();*/
            //bubble.RunFullBubble("BubbleTest1.txt");
            //naiveQuick.RunFullNaiveQuick("NaiveQuickTest2.txt");
            //merge.RunFullMerge("MergeTest2.txt");
            //quick.RunFullQuick("QuickTest1.txt");
            //insertion.RunFullInsertion("InsertionTest1.txt");
            //naiveQuick.RunFullNaiveQuickSorted("NaiveSorted.txt");
            //quick.RunFullQuickSorted("QuickSorted.txt");
        }
示例#4
0
        public void InsertionSort_Int_TestOnArrayWithOneElement()
        {
            var array = new int[] { 1 };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#5
0
        public void InsertionSortRange_Int_TestOnUnsortedArray()
        {
            var array = new int[] { 0, 3, 9, 1, 4, 5, 2, 7, 8, 6 };

            Insertion.Sort(array, 5, 9);
            Assert.IsTrue(array.IsSorted(5, 9));
        }
示例#6
0
        public void InsertionSort_String_TestOnUnsortedArrayWithDuplicates()
        {
            var array = new string[] { "f", "b", "g", "a", "d", "e", "a", "c", "b" };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#7
0
        public void InsertionSort_Int_TestOnUnsortedArrayWithDuplicates()
        {
            var array = new int[] { 0, 3, 9, 7, 1, 4, 5, 2, 7, 8, 6, 3, 1 };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#8
0
        public void InsertionSort_String_TestOnSortedArray()
        {
            var array = new string[] { "a", "b", "c", "d", "e", "f", "g" };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#9
0
        public void InsertionSort_Int_TestOnEmptyArray()
        {
            var array = new int[] { };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#10
0
        private void AddNewPalindromeNode(PalindromeNode longestPalindromePrefix, Insertion insertion)
        {
            var nextNodeIndex = _tree.Count; //todo: change null-suffix to smth

            var newNode = new PalindromeNode(nextNodeIndex);

            if (longestPalindromePrefix.IsImaginaryStringPalindromeNode)
            {
                newNode.Label = insertion.Letter.ToString();
            }
            else
            {
                newNode.Label = insertion.Letter + longestPalindromePrefix.Label + insertion.Letter;
            }
            _tree.Add(newNode);

            longestPalindromePrefix.OutgoingNodes.Add(insertion.Letter, newNode);

            if (longestPalindromePrefix.IsImaginaryStringPalindromeNode)
            {
                newNode = _tree[EmptyStringPalindromeNode.INDEX_EMPTY_STRING];
            }
            else
            {
                var suffixForNewNode =
                    GetLongestPalindromeSuffixForNewNode(insertion, longestPalindromePrefix);
                newNode.LongestPalindromeSuffix = suffixForNewNode;
            }

            _currentLongestPalindromeSuffixNodeIndex = newNode.Index;
        }
        private async Task Insert_After()
        {
            await UsingTempFile(DefaultFileContents, async file =>
            {
                // Arrange
                var modification                = new Insertion(5, "abc\r\n", InsertPosition.After);
                _fileModifierStep.File          = file;
                _fileModifierStep.Modifications = new List <Modification> {
                    modification
                };

                // Act
                await _fileModifierStep.Run();

                // Assert
                var contents = await File.ReadAllTextAsync(file);
                contents.ShouldBe(@"1
2
3
4
5
abc
");
            });
        }
示例#12
0
        public void InsertionSort_Int_TestOnReverseSortedArray()
        {
            var array = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#13
0
        public void InsertionSort_Int_TestOnSortedArray()
        {
            var array = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            Insertion.Sort(array);
            Assert.IsTrue(array.IsSorted());
        }
示例#14
0
        public void Run()
        {
            Console.WriteLine("Choose file:");   // Prompt
            Console.WriteLine("1 - tiny.txt");   // Prompt
            Console.WriteLine("2 - words3.txt"); // Prompt
            Console.WriteLine("or quit");        // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "tiny.txt";
                break;

            case "2":
                fieName = "words3.txt";
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in   = new In($"Files\\Sorting\\{fieName}");
            var words = @in.ReadAllStrings();

            var list = words.Select(word => new StringComparable(word)).ToList();

            var listComparable  = list.Cast <IComparable>().ToList();
            var arrayComparable = list.Cast <IComparable>().ToArray();
            var listStrings     = words.ToList();

            // sort list
            Insertion.Sort(listComparable);
            // print results.
            AbstractSort.Show(listComparable);

            Console.WriteLine("-----------------------------------------------------");

            // sort array
            Insertion.Sort(arrayComparable);
            // print results.
            AbstractSort.Show(arrayComparable);

            Console.WriteLine("-----------------------------------------------------");

            // sort list
            Insertion <string> .Sort(listStrings, new StringComparer());

            // print results
            Insertion <string> .Show(listStrings);

            Console.ReadLine();
        }
示例#15
0
        public void sort_an_array_of_integers()
        {
            var orderedNumbers   = new[] { 1, 2, 3, 4, 5, 6 };
            var unorderedNumbers = new[] { 2, 3, 1, 4, 5, 6 };
            var result           = new Insertion().Sort(unorderedNumbers);

            orderedNumbers.SequenceEqual(result).Should().BeTrue();
        }
示例#16
0
        public void SortTest(int[] input, int[] expected)
        {
            // Arrange & Act
            Insertion.Sort(input);

            // Assert
            CollectionAssert.AreEqual(expected, input);
        }
示例#17
0
        public void TestInsertionSort()
        {
            var expectedArray = new[] { 7, 9, 11, 22, 42, 88, 99 };
            var actualArray   = new[] { 22, 11, 99, 88, 9, 7, 42 };

            Insertion.Sort(actualArray);
            Assert.That(actualArray, Is.EqualTo(expectedArray));
        }
示例#18
0
        public void InsertionSort()
        {
            var array = new int[] { 6, 5, 4, 3, 212, 1, 32, 2 };

            Insertion.Sort(array);

            Assert.Equal(new int[] { 1, 2, 3, 4, 5, 6, 32, 212 }, array);
        }
示例#19
0
 public static void AddFourAxisPedalToMenu(ActionMenuPageType pageType, string text, Action <Vector2> onUpdate,
                                           Texture2D icon         = null, Insertion insertion = Insertion.Post, string topButtonText = "Up",
                                           string rightButtonText = "Right", string downButtonText = "Down", string leftButtonText   = "Left")
 {
     VRCActionMenuPage.AddPedalToList((ActionMenuPage)pageType,
                                      new PedalFourAxis(text, icon, onUpdate, topButtonText, rightButtonText, downButtonText, leftButtonText),
                                      insertion);
 }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void Sort_Words3_IsSorted()
        {
            IComparable[] unsortedArray = "bed bug dad yes zoo now for tip ilk dim tag jot sob nob sky hut men egg few jay owl joy rap gig wee was wad fee tap tar dug jam all bad yet".Split(' ');
            IComparable[] expectedArray = "all bad bed bug dad dim dug egg fee few for gig hut ilk jam jay jot joy men nob now owl rap sky sob tag tap tar tip wad was wee yes yet zoo".Split(' ');

            Insertion.Sort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, unsortedArray);
        }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void Sort_ReverseSorted_IsSorted()
        {
            IComparable[] unsortedArray = "XTSRPOMLEEA".Select(c => c.ToString()).ToArray();
            IComparable[] expectedArray = "AEELMOPRSTX".Select(c => c.ToString()).ToArray();

            Insertion.Sort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, unsortedArray);
        }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void Sort_Tiny_IsSorted()
        {
            IComparable[] unsortedArray = "SORTEXAMPLE".Select(c => c.ToString()).ToArray();
            IComparable[] expectedArray = "AEELMOPRSTX".Select(c => c.ToString()).ToArray();

            Insertion.Sort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, unsortedArray);
        }
示例#23
0
        public void AssertInsertionSort()
        {
            int[]     Array2    = { 8, 7, 6, 5, 4, 3, 2, 1, 9 };
            Insertion insertion = new Insertion();

            insertion.InsertionSort(Array2);

            Assert.AreEqual(Answer, Array2);
        }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void Sort_Elementary_IsSorted()
        {
            IComparable[] unsortedArray = "54321".Select(c => c.ToString()).ToArray();
            IComparable[] expectedArray = "12345".Select(c => c.ToString()).ToArray();

            Insertion.Sort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, unsortedArray);
        }
示例#25
0
        /// <summary>
        ///     Add a restricted radial puppet button pedal to a specific ActionMenu page. Restricted meaning that you can't rotate
        ///     past 100 to get to 0 and vice versa
        /// </summary>
        /// <param name="pageType">The page to add the button to</param>
        /// <param name="text">Button text</param>
        /// <param name="onUpdate">Calls action with a float between 0 - 1 depending on the current value of the radial puppet</param>
        /// <param name="startingValue">(optional) Starting value for radial puppet 0-1</param>
        /// <param name="icon">(optional) The Button Icon</param>
        /// <param name="locked">(optional)The starting state for the lockable pedal, true = locked, false = unlocked</param>
        /// <param name="insertion">
        ///     (optional) Determines whether or not the button is added before or after VRChat's buttons for
        ///     the target page
        /// </param>
        public static PedalRadial AddRestrictedRadialPuppet(ActionMenuPage pageType, string text,
                                                            Action <float> onUpdate, float startingValue = 0, Texture2D icon = null, bool locked = false,
                                                            Insertion insertion = Insertion.Post)
        {
            var pedal = new PedalRadial(text, startingValue, icon, onUpdate, locked, true);

            AddPedalToList(pageType, pedal, insertion);
            return(pedal);
        }
示例#26
0
        public void InsertAt(int index, T value, Insertion insertion = Insertion.Before)
        {
            if (index < 0 || index > Count)
            {
                throw new IndexOutOfRangeException();
            }
            if (index == Count)
            {
                Add(value);
                return;
            }
            if (index == 0)
            {
                Head = new SickLinkedNode <T>(
                    item: value,
                    n: Head
                    );
                Head.Next.Prev = Head;
            }
            else if (index == Count - 1)
            {
                Tail = new SickLinkedNode <T>(
                    item:  value,
                    p: Tail
                    );
                Tail.Prev.Next = Tail;
            }
            else
            {
                var temp = Current;
                MoveToPosition(index);
                switch (insertion)
                {
                case Insertion.InFront:
                    Current.Next = new SickLinkedNode <T>(
                        item: value,
                        n: Current.Next,
                        p: Current
                        );
                    Current.Next.Next.Prev = Current.Next;
                    break;

                case Insertion.Before:
                    Current.Prev = new SickLinkedNode <T>(
                        item: value,
                        n: Current,
                        p: Current.Prev
                        );
                    Current.Prev.Prev.Next = Current.Prev;
                    break;
                }
                Current = temp;
            }

            Count++;
        }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void Sort_NullItem_IsSorted()
        {
            IComparable[] unsortedArray = new string[0];

            IComparable[] expectedArray = new string[0];

            Insertion.Sort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, unsortedArray);
        }
        //[MethodName_StateUnderTest_ExpectedBehavior]
        public void Sort_EmptyItems_IsSorted()
        {
            IComparable[] unsortedArray = Enumerable.Range(1, 10).Select(x => string.Empty).ToArray();

            IComparable[] expectedArray = Enumerable.Range(1, 10).Select(x => string.Empty).ToArray();

            Insertion.Sort(unsortedArray);

            CollectionAssert.AreEqual(expectedArray, unsortedArray);
        }
示例#29
0
        private PalindromeNode GetLongestPalindromePrefixForNextPalindromeNode(Insertion insertion)
        {
            var longestPalindromePrefix = _tree[_currentLongestPalindromeSuffixNodeIndex];

            while (isNecessaryToKeepTraversingTheSuffixChain(insertion, longestPalindromePrefix)) //todo: fckng NRE .cs
            {
                longestPalindromePrefix = longestPalindromePrefix.LongestPalindromeSuffix;
            }
            return(longestPalindromePrefix);
        }
示例#30
0
        public void AscendingSort()
        {
            var nonSortedInput = GenerateNonSortedInput(-100, 100, 500);

            var insertionSort = new Insertion <int>();

            var result = insertionSort.Sort(nonSortedInput, SortingDirection.Ascending);

            IsSorted(result, SortingDirection.Ascending);
        }
        public static double time(string alg, IComparable[] a)
        {
            Stopwatch timer = new Stopwatch();
            if (alg.Equals("Insertion"))
            {
                var sort = new Insertion();
                sort.Sort(a);
            }
            else
            {
                var sort = new Selection();
                sort.Sort(a);
            }

            return timer.ElapsedMilliseconds;
        }