/// <summary> /// Builds a new life form. /// </summary> /// <param name="lifeFormType">The life form type to build.</param> /// <returns>A newly instantiated life form object.</returns> public static LifeFormBase Build(LifeForm lifeFormType) { LifeFormBase lifeForm = null; switch (lifeFormType) { case LifeForm.Empty: lifeForm = new Empty(); break; case LifeForm.Acorn: lifeForm = new Acorn(); break; case LifeForm.AircraftCarrier: lifeForm = new AircraftCarrier(); break; case LifeForm.FivePoint: lifeForm = new FivePoint(); break; default: lifeForm = new RandomPattern( rows: RANDOMPATTERNHEIGHT, cols: RANDOMPATTERNWIDTH); break; } return(lifeForm); }
public void RandomPatternPositionsAreInContainer() { RandomPattern pattern = ScriptableObject.CreateInstance <RandomPattern>(); Bounds bounds = testContainer.bounds; for (int i = 0; i < 50; i++) { Vector3 pos = pattern.GetPosition(testContainer, i, 50); if (!bounds.Contains(pos)) { Assert.Fail(); } } Assert.Pass(); }
/// <summary> /// Get random string (without '1', 'I', '0' and 'O' characters). /// </summary> /// /// <param name="length"> /// Length of the string. /// </param> /// /// <param name="randomPattern"> /// Pattern of the string. /// </param> /// /// <returns> /// The generated string. /// </returns> public static string GetRandomString(int length, RandomPattern randomPattern = RandomPattern.All) { if (length < 0) { length = 1; } var letters = new List <string> { "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; var numbers = new List <int> { 2, 3, 4, 5, 6, 7, 8, 9 }; var sbString = new StringBuilder(length); for (int i = 0; i < length; i++) { if (randomPattern == RandomPattern.OnlyLetters) { sbString.Append(letters[_random.Next(0, letters.Count - 1)]); } else if (randomPattern == RandomPattern.OnlyNumbers) { sbString.Append(_random.Next(0, numbers.Count - 1)); } else { int value = _random.Next(0, numbers.Count - 1); if (value % 2 == 0) { sbString.Append(letters[_random.Next(0, letters.Count - 1)]); } else { sbString.Append(numbers[value].ToString()); } } } return(sbString.ToString()); }
public void Constructor_WhenGivenDimensions_PreparesRandomPatternCorrectly() { // arrange int rows = 13; int cols = 44; // act var randomPattern = new RandomPattern(rows, cols); // assert Assert.AreEqual( expected: rows, actual: randomPattern.GetPattern().Length, message: "The number of rows were wrong."); Assert.IsTrue( randomPattern.GetPattern().All(x => x.Length == cols), message: "The number of columns were wrong somehow."); Assert.IsFalse( randomPattern.IsStable, message: "The pattern reports it's stable, which we can never know."); }