public void Add_ShouldGiveCharCountsOfCharacters()
        {
            var totaliser = new CharacterTotaliser();

            totaliser.Add("abca.");
            totaliser.Add("foo bar wibble!");
            var counts = totaliser.GetCharCounts();

            Assert.That(counts['a'], Is.EqualTo(3));
            Assert.That(counts['b'], Is.EqualTo(4));
        }
 public void Add(ITextFile textFile)
 {
     foreach (string line in textFile.ReadLines())
     {
         totaliser.Add(line);
     }
 }
 private void ConsumeQueue()
 {
     while (!textLineQueue.IsCompleted)
     {
         string line;
         if (textLineQueue.TryTake(out line))
         {
             totaliser.Add(line);
         }
     }
 }
Beispiel #4
0
        private ICharacterCounter ComputeCharCounts(ITextFile textFile)
        {
            ++NumberOfCallsToComputeCharCounts;
            var counter = new CharacterTotaliser();

            foreach (string line in textFile.ReadLines())
            {
                counter.Add(line);
            }

            return(counter);
        }
Beispiel #5
0
        private IReadOnlyDictionary <char, int> ComputeCharCounts(IReadOnlyCollection <string> allLines)
        {
            using (SystemMode.Counter) // don't remove this - that's cheating!
            {
                var totaliser = new CharacterTotaliser();
                foreach (string line in allLines)
                {
                    totaliser.Add(line);
                }

                return(totaliser.GetCharCounts());
            }
        }
 public void Add(ITextFile textFile)
 {
     // We could possibly put the lock around just Add(), but would then incur a lot of lock-entry/exit
     // time. It could sometimes be better, but this way probably wins most times.
     readerWriterLock.EnterWriteLock();
     try
     {
         foreach (string line in textFile.ReadLines())
         {
             totaliser.Add(line);
         }
     }
     finally
     {
         readerWriterLock.ExitWriteLock();
     }
 }