Encode() public static method

public static Encode ( string input ) : string
input string
return string
    public void Encode_with_single_values()
    {
        const string input    = "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB";
        const string expected = "12WB12W3B24WB";

        Assert.That(RunLengthEncoding.Encode(input), Is.EqualTo(expected));
    }
    public void Encode_and_then_decode()
    {
        const string input    = "zzz ZZ  zZ";
        const string expected = "zzz ZZ  zZ";

        Assert.That(RunLengthEncoding.Decode(RunLengthEncoding.Encode(input)), Is.EqualTo(expected));
    }
    public void Encode_unicode()
    {
        const string input    = "⏰⚽⚽⚽⭐⭐⏰";
        const string expected = "⏰3⚽2⭐⏰";

        Assert.That(RunLengthEncoding.Encode(input), Is.EqualTo(expected));
    }
Beispiel #4
0
        public static IList <byte> RLE(IList <byte> bytes)
        {
            var rle       = new RunLengthEncoding(bytes);
            var rleResult = rle.Encode();

            return(rleResult);
        }
Beispiel #5
0
        public void NewIntRunLengthEncoding()
        {
            int length = (int)dataStack.Pop();
            RunLengthEncoding <int> enc = RunLengthEncoding <int> .Encode(YieldValues <int>(length));

            dataStack.Push(enc);
        }
Beispiel #6
0
        public void NewByteRunLengthEncoding()
        {
            int length = (int)dataStack.Pop();
            RunLengthEncoding <byte> enc = RunLengthEncoding <byte> .Encode(YieldValues <byte>(length));

            dataStack.Push(enc);
        }
        public void EncodingTest(string input, string expected)
        {
            var    target = new RunLengthEncoding();
            string actual = target.Encode(input);

            Assert.That(actual, Is.EqualTo(expected));
        }
    public void Encode_simple()
    {
        const string input    = "AABBBCCCC";
        const string expected = "2A3B4C";

        Assert.That(RunLengthEncoding.Encode(input), Is.EqualTo(expected));
    }
Beispiel #9
0
    public void Encode_unicode()
    {
        const string input    = "⏰⚽⚽⚽⭐⭐⏰";
        const string expected = "⏰3⚽2⭐⏰";

        Assert.Equal(expected, RunLengthEncoding.Encode(input));
    }
Beispiel #10
0
        private static void RunLengthEncodingTest()
        {
            string input = "AAAABBBCCDAE";

            WriteLine("RunLengthEncoding");

            string encodedOutput = RunLengthEncoding.Encode(input);

            WriteLine($"Input : {input} , Encoded : {encodedOutput}");

            string decodedOutput = RunLengthEncoding.Decode(encodedOutput);

            WriteLine($"Input : {input} , Decoded : {decodedOutput}");

            WriteLine(input == decodedOutput);
        }
Beispiel #11
0
 public void Run_length_encode_a_string_single_characters_only_are_encoded_without_count()
 {
     Assert.Equal("XYZ", RunLengthEncoding.Encode("XYZ"));
 }
        public void EncodeTestNormalInput()
        {
            RunLengthEncoding target = new RunLengthEncoding();

            Assert.AreEqual("3A2B4C", target.Encode("AAABBCCCC"));
        }
 public void Encode_empty_string()
 {
     Assert.Equal("", RunLengthEncoding.Encode(""));
 }
        public void EncodeTestLowercase()
        {
            RunLengthEncoding target = new RunLengthEncoding();

            Assert.AreEqual("2a3b4c", target.Encode("aabbbcccc"));
        }
        public void EncodeTestStringAndSpaces()
        {
            RunLengthEncoding target = new RunLengthEncoding();

            Assert.AreEqual("2 3AB", target.Encode("  AAAB"));
        }
Beispiel #16
0
 public void test_encode_lowercase_characters()
 {
     Assert.AreEqual("2a3b4c", RunLengthEncoding.Encode("aabbbcccc"));
 }
Beispiel #17
0
 public void test_combination()
 {
     Assert.AreEqual("zzz ZZ  zZ", RunLengthEncoding.Decode(RunLengthEncoding.Encode("zzz ZZ  zZ")));
 }
        public void EncodeTestNoRepeats()
        {
            RunLengthEncoding target = new RunLengthEncoding();

            Assert.AreEqual("ABC", target.Encode("ABC"));
        }
Beispiel #19
0
 public void test_encode_single_characters_mixed_with_repeated_characters()
 {
     Assert.AreEqual("12WB12W3B24WB", RunLengthEncoding.Encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"));
 }
Beispiel #20
0
 public void Run_length_encode_a_string_empty_string()
 {
     Assert.Equal("", RunLengthEncoding.Encode(""));
 }
Beispiel #21
0
 public void Run_length_encode_a_string_multiple_whitespace_mixed_in_string()
 {
     Assert.Equal("2 hs2q q2w2 ", RunLengthEncoding.Encode("  hsqq qww  "));
 }
Beispiel #22
0
 public void Run_length_encode_a_string_string_with_no_single_characters()
 {
     Assert.Equal("2A3B4C", RunLengthEncoding.Encode("AABBBCCCC"));
 }
Beispiel #23
0
        static void Main(string[] args)
        {
            SortedMatrixSearch.Run();
            SparseSearch.Run();
            SearchInRotatedArray.Run();
            GroupAnagrams.Run();
            CombinationsOfNPairsParentheses.Run();
            PermutationWithDuplicates.Run();
            PermutationNoDuplicates.Run();

            var subsetList = new List <List <int> >();

            subsetList = SubsetInSet.FindAllSubsetInSet(new List <int> {
                1, 2, 3
            });
            ReverseLinkedList.Run();
            IsUniqueString.Run();
            StoneDivisionProblem.Run();
            Kangaroo.Run();
            AppleAndOrange.Run();
            AbbreviationProblem.Run();
            FibonacciModifiedProblem.Run();
            RecursiveDigitSum.Run();
            RangeSumOfBST.Run();
            GradingStudentsProblem.Run();
            // XorSequenceProblem.Run();
            CounterGameProblem.Run();
            MaximizingXORProblem.Run();
            LonelyIntegerProblem.Run();
            FlippingBitsProblem.Run();
            QueueUsingTwoStacksProblem.Run();
            GetNodeValue.Run();
            MergeTwoSortedLinkedLists.Run();
            Compare_Two_linked_lists.Run();

            DeleteNodeProblem.Run();
            ArrayManipulationProblem.Run();
            LeftRotationProblem.Run();
            HourGlass2D.Run();
            SimpleTextEditorProblem.Run();
            EqualStacksProblem.Run();
            MaximumElementProblem.Run();
            BinarySearchTreeInsertion.Run();
            TopViewProblem.Run();
            TimeConvertsionProblem.Run();
            BinaryTreePathsProblem.Run();
            IncreasingOrderSearchTree.Run();
            RemoveAllAdjacentDuplicatesInStringWithKLength.Run();
            RemoveAllAdjacentDuplicatesInString.Run();
            CheckStraightLineProblem.Run();
            HouseRobber.Run();
            UniquePathsProblem.Run();
            FirstUniqueCharacterInString.Run();
            BinaryTreeInorderTraversal.Run();
            DailyTemperaturesProblem.Run();
            CountingBitsproblem.Run();
            SortIntegersByTheNumberOf1BitsProblem.Run();
            HammingDistanceProblem.Run();
            RansomNoteProblem.Run();
            ConvertBinaryNumberInLinkedListToIntegerProblem.Run();
            NumberOfStepsToReduceNumberToZeroProblem.Run();
            JewelsAndStones.Run();
            ClimbingStairsProblem.Run();
            BestTimeToBuyAndSellStock.Run();
            MajorityElementProblem.Run();
            MoveZeroesProblem.Run();
            InvertBinaryTree.Run();
            SingleNumberProblem.Run();
            MaximumDepthInTrree.Run();
            MergeTwoBinaryTrees.Run();
            AddBinaryProblem.Run();
            PlusOneProblem.Run();
            LengthOfLastWordProblem.Run();
            KadaneAlgorithmForMaxSubArray.Run();
            KMPAlgorithm.Run();
            CountAndSayProblem.Run();
            SearchInsertPosition.Run();
            ImplementIndexOfString.Run();
            RemoveElement.Run();
            RemoveDuplicatesFromSortedArray.Run();
            MergeTwoSortedLists.Run();
            ValidParentheses.Run();
            LongestCommonPrefix.Run();
            RomanToInteger.Run();
            PalindromeNumber.Run();
            ReverseInteger.Run();
            TwoSumProblem.Run();
            AddOneToNumber.Run();
            MostAmountOfChange.Run();
            #region BinaryTree
            LeastCommonAncestor.Run();
            PrintAllPaths.Run();
            HasPathSum.Run();
            CheckIfBinaryTreeIsBinarySearchTree.Run();
            PrintAllNodesWithRangeInBinarySearchTree.Run();
            UniqueTreeStructureNumber.Run();
            MirrorTree.Run();
            #region BitManuiplation_GetNthNumber
            NumberOfStepsToReduceNumberToZeroProblem.Run();
            CountNumbersOf1InBit.Run();
            ReverseThebitsInInteger.Run();
            PrintBitsInInteger.Run();
            GetNthBit.Run();
            setNthBitTo1.Run();
            SetNthBitTo0.Run();
            #endregion
            MinimumtValueInTrree minValueInTree = new MinimumtValueInTrree();
            minValueInTree.Run();
            #endregion

            #region Recursion
            Chessboard chessboard = new Chessboard();
            chessboard.Run();
            RatPathToMaze ratPathToMaze = new RatPathToMaze();
            ratPathToMaze.Run();
            List <string> anagramList = new List <string>();
            anagramList        = WordAnagram.GenerateWordAnagram("abc");
            Pixel[,] pixelList = new Pixel[3, 3] {
                { new Pixel(0, 0, "red"), new Pixel(0, 1, "green"), new Pixel(0, 2, "green") },
                { new Pixel(1, 0, "red"), new Pixel(1, 1, "green"), new Pixel(1, 2, "green") },
                { new Pixel(2, 0, "red"), new Pixel(2, 1, "green"), new Pixel(2, 2, "green") }
            };
            FillPaint.PaintFill(pixelList, 1, 2, "green", "black");

            BinaryTreesAreTheSame.Run();

            #endregion

            #region General problems
            RotateArrayByKSpaces.Run();

            #region AddtwoNumbersReferencedByTheirDigits
            var addRes = AddtwoNumbersReferencedByTheirDigits.AddNumbers(new int[] { 1, 2, 7 }, new int[] { 9, 4 });
            #endregion

            #region RunLengthEncoding
            var encodedStr = RunLengthEncoding.Encode("aabbbbc");
            var decodedStr = RunLengthEncoding.Decode(encodedStr);
            #endregion

            #region BreakDocumentIntoChunk
            var chunkRes = BreakDocumentIntoChunk.Chunkify("ab:dd:ddfcct:aab:cccc", ':', 5);
            #endregion

            #region GameOfLife
            var gameRes = GameOfLife.GetNextInteration(new int[3, 3] {
                { 1, 0, 0 }, { 0, 1, 1 }, { 1, 0, 0 }
            });
            #endregion .

            #endregion


            #region InsertionSort
            InsertionSort.insertionSort(listToSort);
            #endregion

            #region BinarySearch
            Console.WriteLine(String.Format("%s is present at index: %s", 30, BinarySearch.binarySearch(sortedArray, 30, 0, sortedArray.Length - 1)));
            Console.WriteLine(String.Format("%s is present at index: %s", 4, BinarySearch.binarySearch(sortedArray, 4, 0, sortedArray.Length - 1)));
            Console.WriteLine(String.Format("%s is present at index: %s", 15, BinarySearch.binarySearch(sortedArray, 15, 0, sortedArray.Length - 1)));
            #endregion


            #region MergeSort
            MergeSort.print(listToSort);
            MergeSort.mergeSort(listToSort);
            #endregion


            #region QuickSort
            QuickSort.print(listToSort);
            QuickSort.quickSort(listToSort, 0, listToSort.Length - 1);
            QuickSort.print(listToSort);
            #endregion
        }
        public void EncodeAndDecodeTest()
        {
            RunLengthEncoding target = new RunLengthEncoding();

            Assert.AreEqual("zzz ZZ  zZ", target.Decode(target.Encode("zzz ZZ  zZ")));
        }
Beispiel #25
0
 public void Run_length_encode_a_string_single_characters_mixed_with_repeated_characters()
 {
     Assert.Equal("12WB12W3B24WB", RunLengthEncoding.Encode("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"));
 }
Beispiel #26
0
 public void test_encode_empty_string()
 {
     Assert.AreEqual("", RunLengthEncoding.Encode(""));
 }
Beispiel #27
0
 public void Run_length_encode_a_string_lowercase_characters()
 {
     Assert.Equal("2a3b4c", RunLengthEncoding.Encode("aabbbcccc"));
 }
Beispiel #28
0
 public void test_encode_single_characters_only_are_encoded_without_count()
 {
     Assert.AreEqual("XYZ", RunLengthEncoding.Encode("XYZ"));
 }
Beispiel #29
0
 public void Encode_and_then_decode_encode_followed_by_decode_gives_original_string()
 {
     Assert.Equal("zzz ZZ  zZ", RunLengthEncoding.Decode(RunLengthEncoding.Encode("zzz ZZ  zZ")));
 }
Beispiel #30
0
 public void test_encode_string_with_no_single_characters()
 {
     Assert.AreEqual("2A3B4C", RunLengthEncoding.Encode("AABBBCCCC"));
 }