Esempio n. 1
0
 public void SampleTests()
 {
     Assert.AreEqual(new List <string> {
         "e", "d", "a"
     }, TopWords.Top3("a a a  b  c c  d d d d  e e e e e"));
     Assert.AreEqual(new List <string> {
         "e", "ddd", "aa"
     }, TopWords.Top3("e e e e DDD ddd DdD: ddd ddd aa aA Aa, bb cc cC e e e"));
     Assert.AreEqual(new List <string> {
         "won't", "wont"
     }, TopWords.Top3("  //wont won't won't "));
     Assert.AreEqual(new List <string> {
         "e"
     }, TopWords.Top3("  , e   .. "));
     Assert.AreEqual(new List <string> {
     }, TopWords.Top3("  ...  "));
     Assert.AreEqual(new List <string> {
     }, TopWords.Top3("  '  "));
     Assert.AreEqual(new List <string> {
     }, TopWords.Top3("  '''  "));
     Assert.AreEqual(new List <string> {
         "a", "of", "on"
     }, TopWords.Top3(
                         string.Join("\n", new string[] { "In a village of La Mancha, the name of which I have no desire to call to",
                                                          "mind, there lived not long since one of those gentlemen that keep a lance",
                                                          "in the lance-rack, an old buckler, a lean hack, and a greyhound for",
                                                          "coursing. An olla of rather more beef than mutton, a salad on most",
                                                          "nights, scraps on Saturdays, lentils on Fridays, and a pigeon or so extra",
                                                          "on Sundays, made away with three-quarters of his income." })));
 }
Esempio n. 2
0
 public void Test5()
 {
     Assert.AreEqual(new List <string> {
     }, TopWords.Top3("  '  "));
     Assert.AreEqual(new List <string> {
     }, TopWords.Top3("  '''  "));
 }
Esempio n. 3
0
        public void ToptenwordsTest()
        {
            TopWords topWords = new TopWords();

            string[] str    = { "abcd2", "Adgdg", "gggg", "jhufd", "lovejx97", "abcd2" };
            string   real   = topWords.Toptenwords(str);
            string   expect = "abcd2 (2)\r\nAdgdg (1)\r\ngggg (1)\r\njhufd (1)\r\nlovejx97 (1)\r\n";

            Assert.AreEqual(real, expect);
        }
Esempio n. 4
0
 public void Test1()
 {
     Assert.AreEqual(new List <string> {
         "e", "d", "a"
     }, TopWords.Top3("a a a  b  c c  d d d d  e e e e e"));
     Assert.AreEqual(new List <string> {
         "e", "ddd", "aa"
     }, TopWords.Top3("e e e e DDD ddd DdD: ddd ddd aa aA Aa, bb cc cC e e e"));
     Assert.AreEqual(new List <string> {
         "won't", "wont"
     }, TopWords.Top3("  //wont won't won't "));
 }
Esempio n. 5
0
 public void TestLongText()
 {
     Assert.AreEqual(new List <string> {
         "a", "of", "on"
     }, TopWords.Top3(
                         string.Join("\n", new string[] { "In a village of La Mancha, the name of which I have no desire to call to",
                                                          "mind, there lived not long since one of those gentlemen that keep a lance",
                                                          "in the lance-rack, an old buckler, a lean hack, and a greyhound for",
                                                          "coursing. An olla of rather more beef than mutton, a salad on most",
                                                          "nights, scraps on Saturdays, lentils on Fridays, and a pigeon or so extra",
                                                          "on Sundays, made away with three-quarters of his income." })));
 }
Esempio n. 6
0
        public TopWords GetTopWords(int cnt)
        {
            var tw = new TopWords();

            var allText  = GetAllText();
            var allWords = SplitWords(allText);

            tw.WordCount = allWords.Length;

            var wc = allWords.GroupBy(x => x).Select(x => new WordCount(x.Key, x.Count()));

            tw.Words = wc.OrderByDescending(x => x.Count).Take(cnt).ToList();

            return(tw);
        }
Esempio n. 7
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();
        }
Esempio n. 8
0
 public void TestWeird1()
 {
     Assert.AreEqual(new List <string> {
     }, TopWords.Top3("  ...  "));
 }
Esempio n. 9
0
 public void SetUp()
 {
     _filereader = new Mock <IFileReader>();
     _topWords   = new TopWords(_filereader.Object);
     url         = "Test.txt";
 }
Esempio n. 10
0
 public void Test4()
 {
     Assert.AreEqual(new List <string> {
         "e"
     }, TopWords.Top3("  , e   .. "));
 }
Esempio n. 11
0
 public void Test3()
 {
     Assert.AreEqual(new List <string> {
         "e", "ddd", "aa"
     }, TopWords.Top3("e e e e DDD ddd DdD: ddd ddd aa aA Aa, bb cc cC e e e"));
 }
Esempio n. 12
0
 public void Test2()
 {
     Assert.AreEqual(new List <string> {
         "won't", "wont"
     }, TopWords.Top3("  //wont won't won't "));
 }
Esempio n. 13
0
 public void Test1()
 {
     Assert.AreEqual(new List <string> {
         "e", "d", "a"
     }, TopWords.Top3("a a a  b  c c  d d d d  e e e e e"));
 }