Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length != Program.NumArgs)
            {
                Program.PrintUsage();
                return;
            }

            WordCountDiscoverer discoverer;

            try
            {
                discoverer = new WordCountDiscoverer(args[0]);
            }
            catch (Exception)
            {
                Console.WriteLine(String.Format("Invalid input {0}", args[0]));
                Program.PrintUsage();
                return;
            }

            ConcurrentQueue <FileInfo> fileQueue = (ConcurrentQueue <FileInfo>)discoverer.DiscoverFiles();

            discoverer.ProcessFilesAsync(fileQueue).Wait();
            Program.PrintResults(discoverer.GetCountOfWordsByWordsWithCount());
        }
Exemple #2
0
        public async Task GetCountOfWordsByWordsWithCount_FlatFolderNestedArchivesTest()
        {
            long totalWordCount =
                (4 * FileWordCounts.PrinciplesofHumanKnowledge) +
                (4 * FileWordCounts.ThreeDialogues) +
                (1 * FileWordCounts.CritiqueofPureReason) +
                (1 * FileWordCounts.Theodicy) +
                (4 * FileWordCounts.EssayConcerningHumaneUnderstandingVol1) +
                (4 * FileWordCounts.EssayConcerningHumaneUnderstandingVol2);

            WordCountDiscoverer fd = new WordCountDiscoverer(FileDiscovererTests.FlatFolderNestedArchives);
            await fd.ProcessFilesAsync((ConcurrentQueue <FileInfo>) fd.DiscoverFiles());

            IEnumerable <KeyValuePair <long, int> > countOfWordsByWordsWithCount = fd.GetCountOfWordsByWordsWithCount();

            double wordCountsFromAggregate = countOfWordsByWordsWithCount.Sum(e => (e.Key * e.Value));

            Assert.AreEqual(totalWordCount, wordCountsFromAggregate);
        }