Exemplo n.º 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());
        }
Exemplo n.º 2
0
        public async Task DiscoverAndProcess_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());

            Assert.AreEqual(totalWordCount, fd.AggregateWordOccurrenceCount.Values.Sum());
            Assert.AreEqual(4, fd.AggregateWordOccurrenceCount["PRODUCETH."]);
            Assert.AreEqual(4, fd.AggregateWordOccurrenceCount["ZAHAB?"]);
        }
Exemplo n.º 3
0
        public async Task DiscoverAndProcess_FlatFolderTextOnlyTest()
        {
            long totalWordCount =
                FileWordCounts.FiveWordFile +
                (2 * FileWordCounts.FiveHundredWordFile) +
                FileWordCounts.PrinciplesofHumanKnowledge +
                FileWordCounts.ThreeDialogues +
                FileWordCounts.CritiqueofPureReason +
                FileWordCounts.Theodicy +
                FileWordCounts.EssayConcerningHumaneUnderstandingVol1 +
                FileWordCounts.EssayConcerningHumaneUnderstandingVol2;

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

            Assert.AreEqual(totalWordCount, fd.AggregateWordOccurrenceCount.Values.Sum());
            Assert.AreEqual(7, fd.AggregateWordOccurrenceCount["Lorem"]);
            Assert.AreEqual(2, fd.AggregateWordOccurrenceCount["lorem"]);
        }
Exemplo n.º 4
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);
        }