Beispiel #1
0
        public void TopWords_Emptyfile_ReturnsEmptyDictionaryCase()
        {
            _filereader.Setup(fr => fr.ReadFileLines(url)).Returns(new List <string>());
            var result   = _topWords.GetTopWords(url);
            var expected = new Dictionary <string, int> {
                { "file is empty", 0 }
            };

            Assert.That(result.Keys, Is.EquivalentTo(expected.Keys));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            /*I used console app to implement the Number of 10 top words in the text file. I implemented the requied
             * function in topwords class, I wanted to install ninject framework for implementing dependency
             * injection, but I thought its better not to complicate the code for a small application*/
            //instantiate top words class
            var mytopwords = new TopWords();
            //calling Gettopwords to return the dictionary of top 10 words and their accurances
            //also returns the error message in key if filepath is not valid or if text file is empty
            var result = mytopwords.GetTopWords(@"Test.txt");

            //print each top 10 words with their accurances and their rank in console
            result.ToList().ForEach(x => Console.WriteLine(string.Format("the top {0} word are: {1} with {2} accurences",
                                                                         result.ToList().IndexOf(x) + 1, x.Key, x.Value)));
            Console.Read();
        }