public void SiblingsTest() { IModel clock = Apsim.Child(simulation, typeof(Clock)); List <IModel> allSiblings = Apsim.Siblings(clock); Assert.AreEqual(allSiblings.Count, 5); }
/// <summary> /// Give the specified model a unique name /// </summary> /// <param name="modelToCheck">The model to check the name of</param> private static void EnsureNameIsUnique(IModel modelToCheck) { string originalName = modelToCheck.Name; string newName = originalName; int counter = 0; List <IModel> siblings = Apsim.Siblings(modelToCheck); IModel child = siblings.Find(m => m.Name == newName); while (child != null && child != modelToCheck && counter < 10000) { counter++; newName = originalName + counter.ToString(); child = siblings.Find(m => m.Name == newName); } if (counter == 1000) { throw new Exception("Cannot create a unique name for model: " + originalName); } modelToCheck.Name = newName; }