Beispiel #1
0
        public void TestSimpleFileParser(string filename, long expectedCount, long expectedRepeat, bool xsb)
        {
            IParser  parser      = new SimpleFileParser(filename, xsb);
            ICounter testCounter = new MemoryCounter();

            parser.Parse(testCounter);

            List <BigramCountValue> counts = testCounter.BigramCountList();

            Assert.AreEqual(expectedCount, counts.Count);

            var count = from c in counts
                        where c.Bigram == "the quick"
                        select c.Count;

            Assert.AreEqual(1, count.Count());
            Assert.AreEqual(expectedRepeat, count.First());
        }
Beispiel #2
0
        public void TestCommandLineArgsParser(string argString, long expectedValue)
        {
            string[] args = argString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            IParser parser = new CommandLineTextParser(args);

            ICounter testCounter = new MemoryCounter();

            parser.Parse(testCounter);

            List <BigramCountValue> counts = testCounter.BigramCountList();

            Assert.AreEqual(7, counts.Count);   // 8 bigrams added but 7 values since 1 repeats

            var count = from c in counts
                        where c.Bigram == "the quick"
                        select c.Count;

            Assert.AreEqual(1, count.Count());
            Assert.AreEqual(expectedValue, count.First());
        }
Beispiel #3
0
        public void TestMemoryCounter(string bigram, long expectedCount)
        {
            ICounter testCounter = new MemoryCounter();

            testCounter.Add("the", "quick");
            testCounter.Add("quick", "brown");
            testCounter.Add("brown", "fox");
            testCounter.Add("fox", "and");
            testCounter.Add("and", "the");
            testCounter.Add("the", "quick");
            testCounter.Add("quick", "blue");
            testCounter.Add("blue", "hare");

            List <BigramCountValue> bigramCountList = testCounter.BigramCountList();

            Assert.AreEqual(7, bigramCountList.Count);   // 8 bigrams added but 7 values since 1 repeats

            var targetBigramCounts = from c in bigramCountList
                                     where c.Bigram == bigram
                                     select c.Count;

            Assert.AreEqual(1, targetBigramCounts.Count()); // there should be only one instance of this bigram count
            Assert.AreEqual(expectedCount, targetBigramCounts.First());
        }