Beispiel #1
0
 public BookAnalyzer(IBookLoader loader, IWordCounter counter, IPrimeTestable tester, string path)
 {
     bookLoader  = loader;
     wordCounter = counter;
     primeTester = tester;
     bookPath    = path;
 }
        public void EmailAddressTest()
        {
            string sentence = "Further information or details can be sent to [email protected], [email protected] or  [email protected]";

            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["further"]                   = 1;
            correctAnswer["information"]               = 1;
            correctAnswer["or"]                        = 2;
            correctAnswer["details"]                   = 1;
            correctAnswer["can"]                       = 1;
            correctAnswer["be"]                        = 1;
            correctAnswer["sent"]                      = 1;
            correctAnswer["to"]                        = 1;
            correctAnswer["*****@*****.**"]            = 2;
            correctAnswer["*****@*****.**"] = 1;


            AssertCorrectness(calculatedAnswer, calculatedAnswer);
        }
 public WordCountCalculator(ITextSplitter textSplitter, IWordCounter wordCounter, IPrimeNumberChecker primeChecker)
 {
     this.textSplitter = textSplitter;
     this.wordCounter = wordCounter;
     this.primeChecker = primeChecker;
     
 }
Beispiel #4
0
 public CompareTheWords(IFileReader fileReader, IWordCounter wordCounter, IPrimeNumberCalculator primeNumberCalculator, IOutputGenerator outputGenerator)
 {
     _fileReader            = fileReader;
     _wordCounter           = wordCounter;
     _primeNumberCalculator = primeNumberCalculator;
     _outputGenerator       = outputGenerator;
 }
 public ContentAnalyser(IDataStore <string> dataStore, IWordCounter counter, IWordFilter filter)
 {
     Content    = string.Empty;
     _dataStore = dataStore;
     _counter   = counter;
     _filter    = filter;
 }
Beispiel #6
0
 public void SetUp()
 {
     wordCounter = Substitute.For <IWordCounter>();
     wordCounter.GetCountedWords(Arg.Any <IEnumerable <Word> >()).Returns(w => w[0]);
     wordSelector = Substitute.For <IWordSelector>();
     wordSelector.IsSelectedWord(null).ReturnsForAnyArgs(true);
 }
Beispiel #7
0
 public JudoTestApp(IFileService fileService, IWordSplitter wordSplitter, IWordCounter wordCounter, IConsole console, ICompoundFilter compoundFilter)
 {
     _compoundFilter = compoundFilter;
     _console = console;
     _wordCounter = wordCounter;
     _wordSplitter = wordSplitter;
     _fileService = fileService;
 }
        public void Setup()
        {
            // Not using any mocking frameworks in this project, so lets use our own mock object
            // to keep WordCounterTest independent of actual splitter implementations

            var textSplitter = new TextSplitterMock();

            _wordCounter = Unity.Container.Resolve<IWordCounter>(new DependencyOverride<ITextSplitter>(textSplitter));
        }
Beispiel #9
0
 public CloudLayouter(IFileParser parser, IWordCounter wordCounter, ISizeTranslator translator,
                      IVisualizer visualizer, IWordLayouter layouter)
 {
     this.parser      = parser;
     this.wordCounter = wordCounter;
     this.translator  = translator;
     this.visualizer  = visualizer;
     this.layouter    = layouter;
 }
 public TagCloudTextAnalyzer(IFontAnalyzer fontAnalyzer, ITextAnalyzer textAnalyzer,
                             IEnumerable <IWordFilter> wordFilters, IEnumerable <IWordConverter> wordConverters, IWordCounter wordCounter)
 {
     this.fontAnalyzer   = fontAnalyzer;
     this.textAnalyzer   = textAnalyzer;
     this.wordFilters    = wordFilters;
     this.wordConverters = wordConverters;
     this.wordCounter    = wordCounter;
 }
Beispiel #11
0
        public KeywordsSummary(IWordCounter wordOccurenceHelper)
        {
            if (wordOccurenceHelper == null)
            {
                throw new ArgumentNullException(nameof(wordOccurenceHelper));
            }

            _wordOccurenceHelper = wordOccurenceHelper;
            Name = "Keywords";
        }
 public DocumentIndexator(
     ITokenizer tokenizer,
     IStemmer stemmer,
     IStopWordsProvider stopWordsProvider,
     IWordCounter wordCounter)
 {
     this.tokenizer         = tokenizer;
     this.stemmer           = stemmer;
     this.stopWordsProvider = stopWordsProvider;
     this.wordCounter       = wordCounter;
 }
        public void NullStringTest()
        {
            string sequence = null;
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sequence);

            Assert.IsTrue(calculatedAnswer.Count == 0, "Expected empty");
        }
        public void SplitInputChunk(IWordCounter wordCounter, string buffer)
        {
            var wholeBuffer = Previous + buffer;
            var lastPositionOfWordBoundary = wordCounter.LastPositionOfWordBoundary(wholeBuffer);

            Current = wholeBuffer.Substring(0, lastPositionOfWordBoundary);

            var fromLastWordBoundaryOnwards = wholeBuffer.Substring(lastPositionOfWordBoundary);

            Previous = fromLastWordBoundaryOnwards;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var wordCounters = new IWordCounter[0] {
            };
            WordCounter wcr  = new WordCounter();

            GC.Collect();
            GC.WaitForPendingFinalizers();
            var wcResult = wcr.CountWords(inputPath);

            File.WriteAllLines(ouputPath,
                               wcResult.Select(x => "[" + x.Key + " " + x.Value + "]").ToArray());
        }
        public void OnlyDashesTest()
        {
            string sequence = "--------";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sequence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            Assert.AreEqual(0, calculatedAnswer.Count, "Some word found - expected empty");
        }
        public void OneWordWithSpecialCharAtTheEndWithSpaceBetween()
        {
            string sequence = "Die !";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sequence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["die"] = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public void OneWordSequenceTest()
        {
            string sequence = "Die";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sequence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["die"] = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public TextEditorForm()
        {
            InitializeComponent();

            char[] nonCountedCharacters = new char[] { '\n', '\t', '\r', ' ', }; /// -> best to load from a settings file

            _characterCounter = new CharacterCounter(nonCountedCharacters, isCaseSensitiveToolStripMenuItem.Checked, MAX_INPUT_CHARACTERS);
            _characterCounter.CharacterCountChanged += new ChangedCharacterCountEventHandler(TextMonitor_CharacterCountChanged);

            char[] wordDelimiterCharacters = new char[] { ' ', ',', ';', '.', '!', '"', '(', ')', '\n', '\t', '\r', '?' }; /// -> best to load from a settings file
                                                                                   
            _wordCounter = new WordCounter(wordDelimiterCharacters);
            _wordCounter.WordCountChanged += new ChangedWordCountEventHandler(WordCounter_WordCountChanged);
        }
        public void StrangeFrechWordTest()
        {
            string sentence = "Qu'est-ce que ?";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["qu'est-ce"] = 1;
            correctAnswer["que"]       = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public void MultipleSentencesTest()
        {
            string sentence = "abc, abc - dbe. Dbe and ref. Abc.";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["abc"] = 3;
            correctAnswer["dbe"] = 2;
            correctAnswer["and"] = 1;
            correctAnswer["ref"] = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public void MultipleWordBreakersWitBeginWithSpaceTests()
        {
            string sentence = "abc   aftertriplespace        afterdoubletab.   aftertriplespace and     afterdoubletab";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["abc"] = 1;
            correctAnswer["aftertriplespace"] = 2;
            correctAnswer["afterdoubletab"]   = 2;
            correctAnswer["and"] = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public void MultiLineHandlingTest()
        {
            string sequence = @"Some Multiline
sequence in
test.";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sequence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["some"]      = 1;
            correctAnswer["multiline"] = 1;
            correctAnswer["sequence"]  = 1;
            correctAnswer["in"]        = 1;
            correctAnswer["test"]      = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public void ExcerciseExampleTest()
        {
            string sentence = "This is a statement, and so is this.";

            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["this"]      = 2;
            correctAnswer["is"]        = 2;
            correctAnswer["a"]         = 1;
            correctAnswer["statement"] = 1;
            correctAnswer["and"]       = 1;
            correctAnswer["so"]        = 1;

            AssertCorrectness(calculatedAnswer, calculatedAnswer);
        }
        public void WordWithDashTest()
        {
            string sentence = "This is cross-section of the public.";

            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["this"]          = 1;
            correctAnswer["is"]            = 1;
            correctAnswer["cross-section"] = 1;
            correctAnswer["of"]            = 1;
            correctAnswer["the"]           = 1;
            correctAnswer["public"]        = 1;

            AssertCorrectness(calculatedAnswer, calculatedAnswer);
        }
        public void FrenchInterpunctionTest()
        {
            string sentence = "	Les enfants  les règles d'orthographe à l'école primaire. Qu'est-ce que ?";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sentence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["les"]           = 2;
            correctAnswer["enfants"]       = 1;
            correctAnswer["règles"]        = 1;
            correctAnswer["d'orthographe"] = 1;
            correctAnswer["à"]             = 1;
            correctAnswer["l'école"]       = 1;
            correctAnswer["primaire"]      = 1;
            correctAnswer["qu'est-ce"]     = 1;
            correctAnswer["que"]           = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
        public void MultiLineDialogTest()
        {
            string sequence = @"Dialog (me and you):
- hi,
-Hi you too!
-bye";
            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();

            IWordCounter wc = CreateInstance();

            calculatedAnswer = wc.CountWordsInStringSequence(sequence);

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["dialog"] = 1;
            correctAnswer["me"]     = 1;
            correctAnswer["and"]    = 1;
            correctAnswer["you"]    = 2;
            correctAnswer["hi"]     = 2;
            correctAnswer["too"]    = 1;
            correctAnswer["bye"]    = 1;
            AssertCorrectness(calculatedAnswer, correctAnswer);
        }
Beispiel #28
0
        private void btnCount_Click(object sender, EventArgs e)
        {
            Application.DoEvents();

            IWordCounter wordCounter = null;

            if (cmbWordCounters.SelectedIndex != -1)
            {
                wordCounter =
                    _wordCounters.SingleOrDefault(x => x.GetType().Name == cmbWordCounters.SelectedItem.ToString());
            }

            if (wordCounter != null)
            {
                var results = wordCounter.CountWords(txtInput.Text)
                              .OrderByDescending(x => x.Count)
                              .ToList();

                resultsView.Items.Clear();

                foreach (var result in results)
                {
                    var item = new ListViewItem(result.Word);
                    item.SubItems.Add(result.Count.ToString(CultureInfo.InvariantCulture));

                    resultsView.Items.Add(item);
                }

                lblCount.Text = results.Count().ToString();
            }

            else
            {
                MessageBox.Show("Please choose a word counter");
            }
        }
 public void SetUp()
 {
     wordCounter = new WordCounterLogic();
 }
        }                                // For deserialization only

        public CommentCountScorer(IWordCounter wordCounter)
        {
            _wc = wordCounter ?? throw new ArgumentNullException(nameof(wordCounter));
        }
Beispiel #31
0
        private static object CreateInstance(Type s, IApprovalAnalyzer approvalAnalyzer, IWordCounter wc)
        {
            if (s == typeof(ApprovalScorer))
            {
                return(Activator.CreateInstance(typeof(ApprovalScorer), approvalAnalyzer));
            }

            if (s == typeof(CommentCountScorer))
            {
                return(Activator.CreateInstance(typeof(CommentCountScorer), wc));
            }

            if (s == typeof(WordCountScorer))
            {
                return(Activator.CreateInstance(typeof(WordCountScorer), wc));
            }

            return(Activator.CreateInstance(s));
        }
Beispiel #32
0
        private static IScorerFactory GetKnownScorers(IApprovalAnalyzer approvalAnalyzer, IWordCounter wc)
        {
            var scorers         = GetDerivedTypes <Scorer>(Assembly.GetAssembly(typeof(Scorer)));
            var scorerInstances = scorers
                                  .Select(s => CreateInstance(s, approvalAnalyzer, wc))
                                  .Cast <Scorer>()
                                  .ToDictionary(s => s.Attribute, StringComparer.OrdinalIgnoreCase);

            return(new ScorerFactory(scorerInstances));
        }
Beispiel #33
0
 public WordProcessor(IWordSelector wordSelector, IWordCounter wordCounter)
 {
     this.wordSelector = wordSelector;
     this.wordCounter = wordCounter;
 }
 public WordCountCalculator()
 {
     textSplitter = new TextSplitter();
     wordCounter = new WordCounter();
     primeChecker = new PrimeNumberChecker();
 }
Beispiel #35
0
 public void SetUp()
 {
     wc = new WordCounter();
 }
        public void ExecutionTimeTest()
        {
            string fileName = "BigFileTest.txt";

            try
            {
                File.Delete(fileName);
            }
            catch
            { };

            int iterations = 1000000;

            using (StreamWriter sw = new StreamWriter(fileName))
            {
                for (int i = 0; i < iterations; i++)
                {
                    sw.WriteLine("abc, def - ghi. Abc. ");
                }
                sw.Close();
            }

            IDictionary <string, int> calculatedAnswer = new Dictionary <string, int>();
            IWordCounter wc        = CreateInstance();
            Stopwatch    stopwatch = new Stopwatch();

            //0 current
            //1 - next
            using (StreamReader sr = new StreamReader(fileName))
            {
                stopwatch.Start();

                bool  isLastChar = false;
                int[] readValues = new int[2] {
                    -1, -1
                };

                readValues[0] = sr.Read();
                readValues[1] = sr.Read();

                if (readValues[0] == -1)
                {
                    return;
                }

                if (readValues[0] != -1 && readValues[1] == -1)
                {
                    isLastChar = true;
                }

                wc.CalculateChar((char)readValues[0], isLastChar);

                while (isLastChar == false)
                {
                    readValues[0] = readValues[1];
                    readValues[1] = sr.Read();
                    if (readValues[0] != -1 && readValues[1] == -1)
                    {
                        isLastChar = true;
                    }
                    wc.CalculateChar((char)readValues[0], isLastChar);
                }

                calculatedAnswer = wc.GetCurrentFinishedWordCounter();
                stopwatch.Stop();
                sr.Close();
            }

            IDictionary <string, int> correctAnswer = new Dictionary <string, int>();

            correctAnswer["abc"] = 2 * iterations;
            correctAnswer["def"] = 1 * iterations;
            correctAnswer["ghi"] = 1 * iterations;
            AssertCorrectness(calculatedAnswer, correctAnswer);

            long elapsedTimeinMs     = stopwatch.ElapsedMilliseconds;
            long expectedElapsedTime = (long)(0.006 * iterations);

            Assert.IsFalse(elapsedTimeinMs > expectedElapsedTime, string.Format("Processing time too long. Actual: {0}, Expected {1}", elapsedTimeinMs, expectedElapsedTime));
        }