示例#1
0
        protected void Confirm_btn_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Trim().Count() < 1)
            {
                statusLabel.Text      = "Empty input, please enter valid string!";
                statusLabel.Font.Size = 30;
            }
            else
            {
                statusLabel.Text = "";
                StringStatistics statistics = new StringStatistics(TextBox1.Text);

                ResultsTable.Rows[0].Cells[1].Text = Convert.ToString(statistics.GetSentencesNumber());
                ResultsTable.Rows[1].Cells[1].Text = Convert.ToString(statistics.GetWordsNumber());
                ResultsTable.Rows[2].Cells[1].Text = Convert.ToString(statistics.GetIndicativeNumber());
                ResultsTable.Rows[3].Cells[1].Text = Convert.ToString(statistics.GetQuestionsNumber());
                ResultsTable.Rows[4].Cells[1].Text = Convert.ToString(statistics.GetImperativeNumber());
                ResultsTable.Rows[5].Cells[1].Text = Convert.ToString(statistics.GetConsonantNumber());
                ResultsTable.Rows[6].Cells[1].Text = Convert.ToString(statistics.GetVowelNumber());
                ResultsTable.Rows[7].Cells[1].Text = Convert.ToString(statistics.GetLinesNumber());
                ResultsTable.Rows[8].Cells[1].Text = Convert.ToString(statistics.GetSpecialCharactersNumber());
                ResultsTable.Rows[9].Cells[1].Text = Convert.ToString(statistics.GetParagraphNumber());

                MostFreqWord.Text = statistics.GetExtremeFrequentWordsString(true);
                LongestSntc.Text  = statistics.GetLongestSentences();
                LongestWrds.Text  = statistics.GetLongestWords();
                ShortestSntc.Text = statistics.GetShortestSentences();
                ShortestWrds.Text = statistics.GetShortestWords();

                PrintDicionary(statistics.WordMap, statistics.GetWordsNumber(), WrdsMapDiv);
                PrintDicionary(statistics.CharMap, statistics.GetCharacterCount(), CharMapDiv);
            }
        }
示例#2
0
        public void StringStatisticsTest()
        {
            const string text = "Toto je skusobny text so skr. a dvomi! Vetami.";
            var          stat = new StringStatistics(text);

            Assert.IsNotNull(stat);
        }
示例#3
0
        public void GetShortestSentencesTest()
        {
            const string expected = "Lol";
            const string text     = "Toto je skusobny text so skr. a tromi!\n Vetamimi.\nLol\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetShortestSentences();

            Assert.AreEqual(expected, result);
        }
示例#4
0
        public void GetLongestWordsTest()
        {
            const string expected = "skusobny, Vetamimi";
            const string text     = "Toto je skusobny text so skr. a tromi!\n Vetamimi.\nLol\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetLongestWords();

            Assert.AreEqual(expected, result);
        }
示例#5
0
        public void GetParagraphNumberTest()
        {
            const int    expected = 2;
            const string text     = "Toto je skusobny text so skr. a dvomi!\r\n\n Vetami.\nLol\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetParagraphNumber();

            Assert.AreEqual(expected, result);
        }
示例#6
0
        public void GetCharacterCountTest()
        {
            const int    expected = 40;
            const string text     = "Toto je skusobny text so skr. a tromi!\n Vetamimi.\nLol?\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetCharacterCount();

            Assert.AreEqual(expected, result);
        }
示例#7
0
        public void GetIndicativeNumberTest()
        {
            const int    expected = 1;
            const string text     = "Toto je skusobny text so skr. a tromi!\n Vetamimi.\nLol?\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetIndicativeNumber();

            Assert.AreEqual(expected, result);
        }
示例#8
0
        public void GetWordsNumberTest()
        {
            const int    expected = 9;
            const string text     = "Toto je skusobny text so skr. a dvomi! Vetami.";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetWordsNumber();

            Assert.AreEqual(expected, result);
        }
示例#9
0
        public void GetCharactersMapTest()
        {
            const string expected = "T: 2\no: 3\nt: 4\nj: 1\ne: 3\ns: 2\nk: 1\nu: 1\nb: 1\nn: 1\ny: 1\nx: 2";
            const string text     = "Toto je skusobny text!\nText\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetCharactersMapInString();

            Assert.IsTrue(result.StartsWith(expected));
        }
示例#10
0
        public void GetWordsMapTest()
        {
            const string expected = "Toto: 1\nje: 1\nskusobny: 2\ntext: 1\nFakt: 1\nText: 1";
            const string text     = "Toto je skusobny text!\n Fakt skusobny.\nText\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetWordsMapInString();

            Assert.IsTrue(result.StartsWith(expected));
        }
示例#11
0
        public void GetExtremeFrequentWordsStringTest()
        {
            const string expected = "a";
            const string text     = "Toto je skusobny text so skr. a tromi!\n Vetamimi.\nLol a\n\n";
            var          stat     = new StringStatistics(text);
            var          result   = stat.GetExtremeFrequentWordsString(true);

            Assert.AreEqual(expected, result);
        }
示例#12
0
        public void GetAlphabeticalWordsTest()
        {
            const string expected    = "a";
            const string expectedEnd = "Vetamimi";
            const string text        = "Toto je skusobny text so skr. a tromi!\n Vetamimi.\nLol a\n\n";
            var          stat        = new StringStatistics(text);
            var          result      = stat.GetAlphabeticalWords();

            Assert.IsTrue(result.StartsWith(expected) && result.EndsWith(expectedEnd));
        }
示例#13
0
        private StringStatistics GetTextStatistics(string s)
        {
            StringStatistics stats = new StringStatistics();

            stats.Words = Regex.Matches(s, @"[^\s•]+").Count;
            stats.Lines = Regex.Matches(s, @"^.+", RegexOptions.Multiline).Count;
            stats.CharsWithoutSpaces = Regex.Matches(s, @"[^\s•]").Count;
            stats.CharsWithSpaces = Regex.Matches(s, @"[^•]").Count;

            return stats;
        }