Esempio n. 1
0
        static void Main(string[] args)
        {
            var start = DateTime.Now;

            foreach (string arg in args)
            {
                FileContent fileContent = new FileContent(arg);
                if (fileContent.IsFileLoaded())
                {
                    Console.WriteLine($"-----{fileContent.GetFileName()}-----");
                    StatisticalAnalysis charAnalysis = new StatisticalAnalysis(fileContent.CharIterator());
                    StatisticalAnalysis wordAnalysis = new StatisticalAnalysis(fileContent.WordIterator());
                    charAnalysis.View.Print("Number of characters", charAnalysis.Size());
                    wordAnalysis.View.Print("Number of words", wordAnalysis.Size());
                    wordAnalysis.View.Print("Dictionary size", wordAnalysis.DictionarySize());
                    wordAnalysis.View.Print("Most used words (>1%)", wordAnalysis.MostUsedElements());
                    wordAnalysis.View.Print("Count of word 'love'", wordAnalysis.CountOf("love"));
                    wordAnalysis.View.Print("Count of word 'hate'", wordAnalysis.CountOf("hate"));
                    wordAnalysis.View.Print("Count of word 'music'", wordAnalysis.CountOf("music"));
                    charAnalysis.View.Print("Vowels %", charAnalysis.VowelsPercentage());
                    charAnalysis.View.Print("a:e count ratio", charAnalysis.Ratio("a", "e"));
                    charAnalysis.View.Print(charAnalysis.ElementOccurance());
                    //wordAnalysis.View.Print(wordAnalysis.OccurMoreThan(5));
                }
                Console.WriteLine("\n");
            }

            Console.WriteLine($"Benchmark: {DateTime.Now - start}");
        }
        public void WordSizeTest()
        {
            StatisticalAnalysis wordAnalysis  = new StatisticalAnalysis(new FileContent(_testFilePath).WordIterator());
            StatisticalAnalysis wordAnalysis2 = new StatisticalAnalysis(new FileContent(_testFilePath2).WordIterator());

            Assert.Equal(268, wordAnalysis.Size());
            Assert.Equal(235, wordAnalysis2.Size());
        }
        public void CharSizeTest()
        {
            StatisticalAnalysis charAnalysis  = new StatisticalAnalysis(new FileContent(_testFilePath).CharIterator());
            StatisticalAnalysis charAnalysis2 = new StatisticalAnalysis(new FileContent(_testFilePath2).CharIterator());

            Assert.Equal(1031, charAnalysis.Size());
            Assert.Equal(939, charAnalysis2.Size());
        }
        public void MostUsedTest()
        {
            StatisticalAnalysis wordAnalysis  = new StatisticalAnalysis(new FileContent(_testFilePath).WordIterator());
            StatisticalAnalysis wordAnalysis2 = new StatisticalAnalysis(new FileContent(_testFilePath2).WordIterator());

            var expected = new List <string> {
                "a", "and", "as", "been", "but", "figure", "had", "i", "in", "is", "it", "me", "music", "no", "not", "of", "old", "the", "to", "was", "where"
            };

            Assert.Equal(expected, wordAnalysis.MostUsedElements());
        }