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); }
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); }
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())); }
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"); } }
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"); } }
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"); } }
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"); } } }
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"); } }