Exemple #1
0
        public void TestClone()
        {
            UniGram unigram = new UniGram();

            unigram.AddData(null, "a");
            unigram.AddData(null, "a");
            unigram.AddData(null, "b");

            CompiledUniGram compiledUnigram = new CompiledUniGram(unigram.Grammar);
            ICompiledGram   clone           = compiledUnigram.Clone();

            Assert.AreEqual(compiledUnigram.GetN(), clone.GetN());
            Assert.AreEqual(compiledUnigram.GetValues(null), clone.GetValues(null));
        }
Exemple #2
0
        public void TestGet()
        {
            UniGram unigram = new UniGram();

            unigram.AddData(null, "a");
            unigram.AddData(null, "a");
            unigram.AddData(null, "b");
            unigram.AddData(null, "c");

            CompiledUniGram compiledUnigram = new CompiledUniGram(unigram.Grammar);

            bool seenA = false;
            bool seenB = false;
            bool seenC = false;

            for (int i = 0; i < 1000; ++i)
            {
                string val = compiledUnigram.Get(null);
                switch (val)
                {
                case "a":
                    seenA = true;
                    break;

                case "b":
                    seenB = true;
                    break;

                case "c":
                    seenC = true;
                    break;

                default:
                    Assert.Fail($"{val} should not be possible.");
                    break;
                }
            }

            // in theory, we could potentially not see one of these but it is very unlikely.
            Assert.IsTrue(seenA);
            Assert.IsTrue(seenB);
            Assert.IsTrue(seenC);
        }