コード例 #1
0
        public void ExpandVariableTestOptionalNumber()
        {
            string declaration = "%o%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            string expected = null;
            string actual   = target.Expand().First().ToSmartStringOrNull();

            Assert.AreEqual(expected, actual);

            expected = "1";
            actual   = target.Expand().First().ToSmartStringOrNull();
            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void ExpandVariableTestNumber()
        {
            string declaration = "%n%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            int expected = 1;
            int actual   = (int)target.Expand().First();

            Assert.AreEqual(expected, actual);

            expected = 2;
            actual   = (int)target.Expand().First();
            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void ExpandVariableTestDate()
        {
            string declaration = "%date%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            DateTime expectedDt = DateTime.Now;
            DateTime actualDt   = (DateTime)target.Expand().First();

            Assert.IsTrue((actualDt.ToShortDateString() == expectedDt.ToShortDateString()) && (actualDt.ToShortTimeString() == expectedDt.ToShortTimeString()));
        }
コード例 #4
0
        public void ExpandVariableTestRandomString()
        {
            string declaration = "%randstring:10%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            string actual = (string)target.Expand().First();

            if (actual.Length != 10)
            {
                Assert.Fail("The string was not of the expected length");
            }
        }
コード例 #5
0
        public void ExpandVariableTestRandomNumber()
        {
            string declaration = "%randnum%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            long actual = (long)target.Expand().First();

            if (actual == 0)
            {
                Assert.Fail("The value was not created");
            }
        }
コード例 #6
0
        public void ExpandVariableTestRandomAlphaLCaseString()
        {
            string declaration = "%randstringalphalcase:10%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            string actual = (string)target.Expand().First();

            if (actual.Length != 10)
            {
                Assert.Fail("The string was not of the expected length");
            }

            if (!actual.All(char.IsLower))
            {
                Assert.Fail("The string contained non-lowercase letters");
            }
        }
コード例 #7
0
        public void ExpandVariableTestRandomStringTestClash2()
        {
            string declaration = "%randstring:10%";
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            string           actual;
            HashSet <string> values = new HashSet <string>();

            for (int i = 0; i < 1000000; i++)
            {
                actual = (string)target.Expand().First();

                if (!values.Add(actual))
                {
                    Assert.Fail("Duplicate value detected");
                }
            }
        }
コード例 #8
0
        public void ExpandVariableTestClash <T>(string declaration)
        {
            VariableDeclarationParser parser = new VariableDeclarationParser(declaration);
            VariableDeclaration       target = parser.GetVariableDeclaration();
            HashSet <T> values = new HashSet <T>();

            int clashCount = 0;
            int runs       = 1000000;

            for (int i = 0; i < runs; i++)
            {
                T actual = (T)target.Expand().First();

                if (!values.Add(actual))
                {
                    clashCount++;
                }
            }

            if (clashCount > 0)
            {
                Assert.Fail($"Duplicate values created in {clashCount} out of {runs} runs");
            }
        }