コード例 #1
0
        public void CalculateAverage_WordLength_ReturnsDoubleAverageWordLength(string text, double expectedResult)
        {
            //Act
            var result = WordLength.CalculateAverage(text);

            //Assert
            Assert.That(result, Is.EqualTo(expectedResult));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //A method which allows to define an average word length in an input string (returns double)
            string pathToText = @"EnglishIT.txt";

            Files.CreateFileWithText(pathToText);
            string text = FileProvider.Get(pathToText);

            Console.WriteLine("An average word length is {0:0.000}", WordLength.CalculateAverage(text));
            Console.WriteLine();

            //A method that doubles in the first string parameter all characters belonging the second string parameter
            Console.WriteLine("Print a string, that you want to double:");
            string firstString = UserData.CheckInput();

            Console.WriteLine("Print another string with letters you want to double:");
            string secondString = UserData.CheckInput();
            string doubled      = StringParametr.DoubleLetters(firstString, secondString);

            Console.WriteLine($"The string was doubled - {doubled}");
            Console.WriteLine();

            //A method, that returns the sum of two big numbers (bigger than long)
            string pathToNumbers = @"NumbersFromString.txt";

            Files.CreateFileWithNumbersFromString(pathToNumbers);
            string firstNumber  = FileProvider.GetAstring(pathToNumbers, 0);
            string secondNumber = FileProvider.GetAstring(pathToNumbers, 1);

            Console.WriteLine("First number from file, that we want to sum is: {0}", firstNumber);
            Console.WriteLine("Second number from file, that we want to sum is: {0}", secondNumber);
            string summary = Sum.Calculate(firstNumber, secondNumber);

            Console.WriteLine($"The strings was summed : {summary}");
            Console.WriteLine();

            //A method which reverses all of the words within the string passed in
            string pathToSentence = @"EnglishIT.txt";
            string sentence       = FileProvider.GetAstring(pathToSentence, 0);

            Console.WriteLine("The first string from file, that we want to reverse: {0}", sentence);
            string reversedSentence = Words.Reverse(sentence);

            Console.WriteLine($"The strings reversed : {reversedSentence}");
            Console.WriteLine();

            //A method that takes a string which contains text with phone numbers and saves the numbers to file
            string pathToTextWithNumbers = @"C:Text.txt";

            Files.CreateTextWithNumbers(pathToTextWithNumbers);
            text = FileProvider.Get(pathToTextWithNumbers);
            List <string> phoneNumbers = PhoneNumbers.GetFromTheText(text);

            Console.WriteLine();

            Console.WriteLine("A file Numbers.txt was created");
            Console.ReadKey();
        }
コード例 #3
0
        public void Count_Expected_4_2_1_4_8()
        {
            var wordLength     = new WordLength();
            var expectedNumbrs = new List <int>()
            {
                4, 2, 1, 4, 8
            };
            List <int> actualNumbers = wordLength.Count("This is a long sentence");

            CollectionAssert.AreEqual(expectedNumbrs, actualNumbers);
        }
コード例 #4
0
        private static WordLength[] BuildWordLengths(string[] words)
        {
            var wordLengths = new WordLength[words.Length];

            for (var i = 0; i < words.Length; i++)
            {
                wordLengths[i] = new WordLength
                {
                    AlphabetMap = BuildAlphabetMap(words[i]),
                    Length      = words[i].Length,
                    Word        = words[i]
                };
            }

            return(wordLengths);
        }
コード例 #5
0
        public static void Main()
        {
            string[] transactions = { "bob,627,1973,amsterdam", "alex,387,885,bangkok", "alex,355,1029,barcelona", "alex,587,402,bangkok", "chalicefy,973,830,barcelona", "alex,932,86,bangkok", "bob,188,989,amsterdam" };
            int[]    test         = { 0, 1, 2, 3, 4, 5, 6, 0, 1 };
            int[]    test2        = { 1, 3, 5, 2 };
            string[] tests        = { "bella", "label", "roller" };
            string   input2       = "10#11#12";

            string something = Program.Mapping.FreqAlphabets(input2);

            Ranks instanceOfRanks = new Ranks();

            string[] medals = instanceOfRanks.FindRelativeRanks(test2);


            int         response4 = WordLength.LengthOfLastWord("b   a    ");
            IList <int> response2 = Program.SelfDivide.SelfDividingNumbers(1, 22);

            IList <string> transactionsResponse = Program.Invalid.InvalidTransactions(transactions);

            int[] response = ArrayIntersect.Intersect(test, test2);
            response = ArrayParity.SortArrayByParity(test);

            IList <int> smallAnswer = Smaller.CountSmaller(test);

            IList <string> answers = Common.GetValues(tests);

            int [] answer = Smaller.SmallerNumbersThanCurrent(test);

            // int response = ReduceToZero.NumberOfSteps(14);

            //response = Max69.Maximum69Number(9669);

            ListNode head   = new ListNode(1);
            ListNode second = new ListNode(0);

            head.next = second;
            ListNode third = new ListNode(1);

            second.next = third;

            GetDecimalValue.GetDecimal(head);

            BalancedString.GetBalancedCount("RLRRRLLRLL");

            string stones = "aAAbbbb";
            string jewels = "aA";
            int    count  = JewelsAndStones.GetJewelCount(jewels, stones);

            int[] digits = { 12, 345, 2, 6, 7896 };
            int   J      = EvenDigits.NumEvenDigits(digits);

            int i = SubtractProdAndSum.SubtractProductAndSum(234);

            char[] values = new char[] { 'a', 'a', 'b', 'b', 'c', 'c', 'c' };
            StringCompression.StringCompression.Compress(values);


            int[] input = new int[] { 3, 2, 3, 4, 3, 3 };
            Console.WriteLine("Result is: {1}", Decompress.Decompress.DecompressRLElist(input));
        }
コード例 #6
0
        public async Task Decode()
        {
            /* --Structure--
             * word length : byte
             * original file length in bytes : long
             * tree : Bit...
             * code : Bit...
             */

            //Reading word length, original file length
            this.wordLength = (byte)await reader.ReadCustomLength(8);

            long originalFileLength = (long)await reader.ReadCustomLength(64);

            WordLength?.Invoke(this.wordLength, originalFileLength);

            if (originalFileLength > 0)
            {
                //Parsing tree from bits
                TreeNode root = await ParseDecodeTreeAsync();


                //Creating decode table
                Dictionary <long?, (long?code, int codeLength)> encodingTable = await CreateEncodingsAsync(root);

                decimal bytesWritten = 0;
                decimal wordToBytes  = ((decimal)this.wordLength) / 8;

                while (bytesWritten + wordToBytes <= originalFileLength)
                {
                    TreeNode branch = root;
                    while (branch.leaf == null)
                    {
                        long?currentBit = await reader.ReadCustomLength(1);

                        branch = currentBit == 1 ? branch.Right : branch.Left;
                    }
                    bytesWritten += wordToBytes;
                    await this.writer.WriteCustomLength((long)branch.leaf, this.wordLength);

                    WordsWritten?.Invoke(1);
                }
                TreeNode branch2   = root;
                var      da        = (((decimal)originalFileLength) - bytesWritten);
                var      remainder = (8 * (((decimal)originalFileLength) - bytesWritten));
                if (remainder > 0)
                {
                    while (true)
                    {
                        long?currentBit = await reader.ReadCustomLength(1);

                        branch2 = currentBit == 1 ? branch2.Right : branch2.Left;
                        if (branch2.leaf != null)
                        {
                            bytesWritten += wordToBytes;
                            var d = (int)(remainder * this.wordLength);
                            await this.writer.WriteCustomLength((long)(branch2.leaf >> (this.wordLength - (int)remainder)), (int)remainder);

                            WordsWritten?.Invoke(1);
                            break;
                        }
                    }
                }
            }

            //Save
            //await this.writer.FlushBuffer();
        }