Beispiel #1
0
        public void SlashTagWithTwoOptions()
        {
            var core = new Core();

            string input = "[cat/dog]";

            int CatCount = 0;
            int DogCount = 0;
            for (int i = 0; i < 100; i++)
            {
                string actual = core.Parse(input);
                if (actual == "cat")
                {
                    CatCount++;
                }
                else if (actual == "dog")
                {
                    DogCount++;
                }
                else
                {
                    Assert.Fail("Output must be either cat or dog!");
                }
            }

            //Must produce both options with more than 1:100 chance
            Assert.IsTrue(CatCount > 1);
            Assert.IsTrue(DogCount > 1);
        }
Beispiel #2
0
        public void SlashTagWithOneOptionTwice()
        {
            var core = new Core();
            string input = "[dog/dog]";

            string actual = core.Parse(input);
            string expected = "dog";

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public void PickRandomlyFromCategoryOfThree()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "cat", "dog", "mouse" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[animal]";

            int CatCount = 0;
            int DogCount = 0;
            int MouseCount = 0;
            for (int i = 0; i < 1000; i++)
            {
                string actual = core.Parse(input);
                if (actual == "cat")
                {
                    CatCount++;
                }
                else if (actual == "dog")
                {
                    DogCount++;
                }
                else if (actual == "mouse")
                {
                    MouseCount++;
                }
                else
                {
                    Assert.Fail("Output did not come from dictionary: " + actual);
                }
            }

            //Must produce all options a fair amount (1 in 100)
            Assert.IsTrue(CatCount > 10);
            Assert.IsTrue(DogCount > 10);
            Assert.IsTrue(MouseCount > 10);
        }
Beispiel #4
0
        public void MultipleInjectedValuesUsedInsteadOfRandom()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "letter", new List<string> { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" } },
                { "word b", new List<string> { "banana" } },
                { "role", new List<string> { "fruit", "food", "meal", "sweet", "item", "snack", "gun", "prop" } },
            };

            core.LoadThisGrammar(sampleDictionary);

            string input = "[!letter][word [letter]] [role]";

            var injection = new Dictionary<string, string> {
                { "letter", "b" },
                { "role", "fruit" }
            };

            string expected = "banana fruit";
            string actual = core.Parse(input, injection);

            Assert.AreEqual(expected, actual);
        }
Beispiel #5
0
        public void NestedTagWithNoEarlyCallThrowsError()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "canine" } },
                { "canine", new List<string> { "dog" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[[animal]]";
            
            //We expect a FormatException using the ExpectedException attribute
            string actual = core.Parse(input);
            
        }
Beispiel #6
0
        public void FairDistributionOfNestedTagResults()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "canine", "feline" } },
                { "canine", new List<string> { "dog", "wolf" } },
                { "feline", new List<string> { "cat", "lion" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[animal] [[animal]]";

            int Dog = 0;
            int Wolf = 0;
            int Cat = 0;
            int Lion = 0;
            for (int i = 0; i < 1000; i++)
            {
                string actual = core.Parse(input);
                if (actual == "canine dog")
                {
                    Dog++;
                }
                else if (actual == "canine wolf")
                {
                    Wolf++;
                }
                else if (actual == "feline cat")
                {
                    Cat++;
                }
                else if (actual == "feline lion")
                {
                    Lion++;
                }
                else
                {
                    Assert.Fail("Output did not come from dictionary: " + actual);
                }
            }

            //Must produce all options a fair amount (1 in 100)
            Assert.IsTrue(Dog > 10);
            Assert.IsTrue(Wolf > 10);
            Assert.IsTrue(Cat > 10);
            Assert.IsTrue(Lion > 10);
        }
Beispiel #7
0
        public void HiddenTagPopulatesNestedInstance()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "canine" } },
                { "canine", new List<string> { "dog" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[!animal][[animal]]";
            string expected = "dog";
            string actual = core.Parse(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void HiddenTagDoesNotDisplay()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "canine", "feline" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[!animal]";
            string expected = "";
            string actual = core.Parse(input);
            
            Assert.AreEqual(expected, actual);
        }
Beispiel #9
0
        public void NestedTagEvaluates()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "canine" } },
                { "canine", new List<string> { "dog" } },
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "One such [animal] is the [[animal]]";
            string expected = "One such canine is the dog";
            string actual = core.Parse(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #10
0
        public void SameTagTwiceWithMarkersCanHaveSeparateResults()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "dog", "cat" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[animal#1] [animal#2]";

            bool gotOne = false;
            for (int i = 0; i < 200; i++)
            {
                string actual = core.Parse(input);
                if (actual == "dog cat" || actual == "cat dog")
                {
                    gotOne = true;
                }
            }

            Assert.IsTrue(gotOne);
        }
Beispiel #11
0
        public void SameTagTwiceGetsSameResult()
        {
            var core = new Core();
            var sampleDictionary = new Dictionary<string, List<string>>
            {
                { "animal", new List<string> { "dog", "cat" } }
            };

            core.LoadThisGrammar(sampleDictionary);
            string input = "[animal] [animal]";

            string actual = core.Parse(input);

            Assert.IsTrue(actual == "dog dog" || actual == "cat cat");
        }