public void TwoSameWords_ShouldReturnCount1() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "one one")); var words = wordsCounter.Count(); Assert.Equal(1, words.Count); }
public void TwoSameWords_ShouldReturnTwoOccurences() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "word word")); var words = wordsCounter.Count(); Assert.Equal(2, words["word"]); }
public void TestWordcountWithoutStopwords() { WordsCounter wordCounter = new WordsCounter(new string[0]); int result = wordCounter.Count(new[] { "a", "bc", "def" }); Assert.AreEqual(3, result); }
public void BlankSpaces_ShouldBe_Ignored() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "a b a ")); var words = wordsCounter.Count(); Assert.Equal(2, words.Count); }
public void DifferentWords_ShouldReturnOccurences() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "word test word word test")); var words = wordsCounter.Count(); Assert.Equal(3, words["word"]); Assert.Equal(2, words["test"]); }
public void EmptyArray_ShouldReturnZeroWords() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "")); var words = wordsCounter.Count(); Assert.Equal(0, words.Count); }
public void Count_WordStats() { var wordsCounter = new WordsCounter(); wordsCounter.MeasureWords(new[] { "a", "b", "c", "b", "c", "b" }) .Should() .BeEquivalentTo(new MeasuredWord("a", 1), new MeasuredWord("b", 3), new MeasuredWord("c", 2)); }
public void WordsWithPunctuation_ShouldNotTakePunctuationsIntoAccount() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "a word, word a, (word.")); var words = wordsCounter.Count(); Assert.Equal(3, words["word"]); }
public void TestWordcountWithStopwordsNotFound() { WordsCounter wordCounter = new WordsCounter(new[] { "xy" }); int result = wordCounter.Count(new[] { "a", "bc", "def" }); Assert.AreEqual(3, result); }
public void Words_ShouldSortOccurences() { var wordsCounter = new WordsCounter(CreateWordsLoaderStub(val => "word test word word test apple")); var words = wordsCounter.Count(); Assert.Equal("apple", words.Keys.ElementAt(0)); Assert.Equal("test", words.Keys.ElementAt(1)); Assert.Equal("word", words.Keys.ElementAt(2)); }
/// <summary> /// Приватный метод для работы с файлом. /// </summary> /// <param name="ts">TextSaver.</param> private void WorkWithFile(ref TextSaver ts) { string str;// Строка, для обработки ответа пользователя. while (true) { Console.WriteLine(ts.Text); Console.Write( "1. Delete symbol or word.\n" + "2. Count words.\n" + "3. Every tenth word.\n" + "4. Backward third sentence.\n" + "5. Close file.\n" + "(number) :" ); str = Console.ReadLine(); if (int.TryParse(str, out int result)) { switch (result) { case 1: Console.WriteLine("Symbol or word: "); RemoverFromText.Delete(Console.ReadLine(), ref ts); break; case 2: WordsCounter.CountWords(ts.Text); break; case 3: WordsCounter.CountTenthWord(ts.Words); break; case 4: SentencesReverser.ReverseThirdSentence(ts.Text); break; case 5: Console.WriteLine("Save changes ?(yes,no)"); str = Console.ReadLine().ToLower(); if (str == "yes" || str == "y") { CreateFile(ts.Text); //Creat backup } return; default: break; } } Console.WriteLine("\t\t *enter*"); Console.ReadKey(); Console.Clear(); } }
public void CountWords_StringIsEmptyString_ArgumentException() { //Arrange var str = ""; Dictionary <string, int> outcome = new Dictionary <string, int>(); //Act //Act => Assert Assert.ThrowsException <ArgumentException>(() => WordsCounter.CountWords(str, outcome)); }
public void CountWords_ListIsNullList_ArgumentNullException() { //Arrange string str = "Test String"; List <KeyValuePair <string, int> > outcome = null; //Act //Act => Assert Assert.ThrowsException <ArgumentNullException>(() => WordsCounter.CountWords(str, outcome)); }
public void CountWords_DictionaryIsNull_ArgumentNullException() { //Arrange string str = "Test String"; Dictionary <string, int> outcome = null; //Act //Act => Assert Assert.ThrowsException <ArgumentNullException>(() => WordsCounter.CountWords(str, outcome)); }
static void Main(string[] args) { var reader = new FileReader(); var counter = new WordsCounter(); var words = reader.ReadWords(args[0]); var substrings = counter.GenerateSubstrings(words, 4); var topTen = counter.GetTopNHits(substrings, 10); Console.WriteLine("Frequencies:"); topTen.ToList().ForEach(item => Console.WriteLine($"{item.Key} {Math.Round(item.Value * 100, 2)}%")); }
private static void RunPart1() { string fileLocation = GetFileLocation("part1fileinput.txt"); var fileLoader = new FileWordsLoader(fileLocation); var wordsCounter = new WordsCounter(fileLoader); try { PrintPart1(wordsCounter.Count()); } catch (FileNotFoundException) { Console.WriteLine("File was not found at location: {0}", fileLocation); } }
private static void Run(RunOptions options) { Console.InputEncoding = Encoding.UTF8; var weightedWords = new WordsCounter() .Сonsider(ReadPhrases(Console.In)) .OrderByDescending(w => w.Weight) .ToList(); var center = GetCenter(options.Width, options.Height); var cloud = new CircularCloudLayouter(center); var tagLayouter = new TagLayouter(cloud, options.MinFont, options.MaxFont); var tags = tagLayouter.GetTags(weightedWords).ToList(); var visualizer = new TagsCloudVisualizer(new SolidBrush(Color.DarkSlateBlue), Color.Bisque); using (var image = visualizer.GetCloudImage(tags, options.Width, options.Height)) { var fileName = options.PathToImage; SaveImage(image, fileName); } }
public void CountWords_CountWordsFromPreparedString_ReturnsList() { //Arrange string str = "One Two Three Three Three Three Four Five"; List <KeyValuePair <string, int> > outcome = new List <KeyValuePair <string, int> >(); int wordsCountInString = 0; int wordsCountInOutcome = 0; //Act WordsCounter.CountWords(str, outcome); //Assert Assert.IsInstanceOfType(outcome, typeof(List <KeyValuePair <string, int> >)); foreach (KeyValuePair <string, int> item in outcome) { wordsCountInOutcome += item.Value; } int index = 0; while (index < str.Length) { // check if current char is part of a word while (index < str.Length && !char.IsWhiteSpace(str[index])) { index++; } wordsCountInString++; // skip whitespace until next word while (index < str.Length && char.IsWhiteSpace(str[index])) { index++; } } Assert.AreEqual(wordsCountInOutcome, wordsCountInString); }
static void Main(string[] args) { while (true) { string line = default; Console.WriteLine("Choose: FILE = 1(D:1.txt); Console Input = 2; Exit = Any Other Number", Color.Green); string Choose = Console.ReadLine(); int Choose1 = Convert.ToInt32(Choose); if (Choose1 == 1) { line = File.ReadAllText(@"D:\\3.txt"); } else if (Choose1 == 2) { Console.WriteLine("Enter string"); line = Console.ReadLine(); } else { break; } line = DelAndCount.SpaceDel(line); Console.WriteLine(line); Console.WriteLine("Word Count = " + DelAndCount.WordCount(line), Color.Red); int count = WordsCounter.WordSeparator(line).Length; Console.WriteLine("Word Count 2 = " + count, Color.Yellow); Console.WriteLine("Statistics of the words", Color.Blue); WordsCounter.WordStatPrint(line); } }
static void Main() { String path; String word; while (true) { Console.WriteLine("\n1 --- Delete String from a text file"); Console.WriteLine("2 --- Show count of words and every tenth word in a text file"); Console.WriteLine("3 --- The third sentence method"); Console.WriteLine("4 --- Working with dir\n"); Console.WriteLine("Chose the method:\n"); switch (Console.ReadLine()) { case "1": { Console.WriteLine("\nEnter the path:"); path = Console.ReadLine(); Console.WriteLine("\nEnter the word or char:"); word = Console.ReadLine(); try { ITextEditable te = new TextEditer(path, word); Console.WriteLine("\n" + te.EditText()); Console.WriteLine(); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); break; } case "2": { Console.WriteLine("\nEnter the path:"); path = Console.ReadLine(); try { IWordsCountable wc = new WordsCounter(path); Console.WriteLine("\n" + wc.WordCounter()); IEveryTenthWordTakable wt = new EveryTenthWordTaker(path); Console.WriteLine("\n" + wt.EveryTenthWord()); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); break; } case "3": { Console.WriteLine("\nEnter the path:"); path = Console.ReadLine(); try { IThirdSentenceReversible ts = new ThirdSentenceReverser(path); Console.WriteLine("\n" + ts.ThirdSentenceReverse()); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); break; } case "4": { Console.WriteLine("\nEnter the path:"); path = Console.ReadLine(); try { IDirInformable di = new DirInformer(path); di.ShowCurrentDirContent(); Console.WriteLine("\nChoose the dir:"); di.ChooseElseDir(Int32.Parse(Console.ReadLine())); di.ShowCurrentDirContent(); } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); break; } default: { Console.WriteLine("\nWrong number..."); break; } } } }
public Dictionary <string, int> WordsCount(List <string> words, Dictionary <string, int> dict) { WordsCounter wc = new WordsCounter(); return(wc.WordsCountAsync(words, dict)); }
public WordsCounterUnitTest(ITestOutputHelper output) { _reader = new FileReader(); _counter = new WordsCounter(); _output = output; }