public void ProcessSpeciesTestOneSpecies() { ModelInfo.ModelBuilder modelInfoEx = new ModelInfo.ModelBuilder("model"); var species = new SpeciesDescription("testSpecies", 10); modelInfoEx.AddSpecies(species); ModelInfo modelInfo = modelInfoEx.Model; Model model = new Model(modelInfo); MpModelBuilder modelbuilder = new MpModelBuilder(); MethodInfo processSpeciesMethod = ReflectionUtility.GetHiddenMethod("ProcessSpecies", modelbuilder); IDictionary <string, IValue> nmap; IDictionary <string, IBoolean> bmap; IDictionary <string, IUpdateable> umap; IDictionary <SpeciesDescription, Species> speciesMap = InitializeMaps(out nmap, out bmap, out umap); var newSpecies = new SpeciesMP(species, nmap); //Inputs to invoke hidden method ProcessSpecies (needs to be an array of objects) var inputArray1 = new object[2]; inputArray1[0] = model; inputArray1[1] = modelInfo; //Test to make sure that the model has local variables that are null var compareSpeciesMap = ReflectionUtility.GetHiddenField <IDictionary <SpeciesDescription, Species> >("_speciesMap", modelbuilder); var compareNmap = ReflectionUtility.GetHiddenField <IDictionary <string, IValue> >("_nmap", modelbuilder); var compareBmap = ReflectionUtility.GetHiddenField <IDictionary <string, IBoolean> >("_bmap", modelbuilder); var compareUMap = ReflectionUtility.GetHiddenField <IDictionary <string, IUpdateable> >("_umap", modelbuilder); Assert.AreEqual(speciesMap, compareSpeciesMap); Assert.AreEqual(nmap, compareNmap); Assert.AreEqual(bmap, compareBmap); Assert.AreEqual(umap, compareUMap); processSpeciesMethod.Invoke(modelbuilder, inputArray1); //Begin Assertions about the species that was added to the model Assert.AreEqual("testSpecies", model.Species[0].Name); Assert.AreEqual(species, model.Species[0].Description); Assert.AreEqual(1, model.Species.Count); //Assert tests about size. compareSpeciesMap = ReflectionUtility.GetHiddenField <IDictionary <SpeciesDescription, Species> >("_speciesMap", modelbuilder); compareNmap = ReflectionUtility.GetHiddenField <IDictionary <string, IValue> >("_nmap", modelbuilder); compareUMap = ReflectionUtility.GetHiddenField <IDictionary <string, IUpdateable> >("_umap", modelbuilder); Assert.AreEqual(1, compareSpeciesMap.Count); Assert.AreEqual(1, compareNmap.Count); Assert.AreEqual(1, compareUMap.Count); //Assert tests about what was actually added to the dictionary. var testSpecies = (SpeciesMP)compareNmap["testSpecies"]; Assert.AreEqual(testSpecies.Description, newSpecies.Description); Assert.AreEqual(testSpecies.Locale, newSpecies.Locale); Assert.AreEqual(testSpecies.Name, newSpecies.Name); }
public void ModelInfoTest() { const string modelName = "test model"; var builder = new ModelInfo.ModelBuilder(modelName); const string constraintName = "test constraint"; const string constraintPredicateName = "constraint predicate"; var constraintExpression = new EqualToOperator(Two, Two); var constraintPredicate = new BooleanExpressionTree(constraintPredicateName, constraintExpression); var constraint = new ConstraintInfo(constraintName, constraintPredicate); builder.AddConstraint(constraint); /* * const string eventName = "test event"; * const string eventPredicateName = "event predicate"; * var eventExpression = new GreaterThanOperator(Three, Two); * var eventPredicate = new BooleanExpressionTree(eventPredicateName, eventExpression); * int eventCount = 0; * var testEvent = new EventInfo(eventName, eventPredicate, () => { eventCount++; }); * builder.AddEvent(testEvent); */ const string expressionName = "test expression"; var expression = new AddOperator(Three, Two); var expressionTree = new NumericExpressionTree(expressionName, expression); builder.AddExpression(expressionTree); const string localeName = "test locale"; var locale = new LocaleInfo(localeName); builder.AddLocale(locale); const string observableName = "test observable"; const string observableExpressionName = "observable expression"; var rootOperator = new PowerOperator(Two, Three); var observableExpressionTree = new NumericExpressionTree(observableExpressionName, rootOperator); var observable = new ObservableInfo(observableName, observableExpressionTree); builder.AddObservable(observable); const string parameterName = "test parameter"; var parameter = new ParameterInfo(parameterName, 3.14159265f); builder.AddParameter(parameter); const string predicateName = "test predicate"; var predicateExpression = new LessThanOperator(Two, Three); var predicate = new BooleanExpressionTree(predicateName, predicateExpression); builder.AddPredicate(predicate); const string speciesName = "reactant"; var reactant = new SpeciesDescription(speciesName, 2012, locale); builder.AddSpecies(reactant); const string reactionName = "test reaction"; var rBuilder = new ReactionInfo.ReactionBuilder(reactionName); rBuilder.AddReactant(reactant); var rateExpression = new MultiplyOperator(Ten, new SymbolReference(speciesName)); var reactionRate = new NumericExpressionTree(null, rateExpression); rBuilder.SetRate(reactionRate); var reaction = rBuilder.Reaction; builder.AddReaction(reaction); var modelInfo = builder.Model; Console.WriteLine("ModelInfoTests: checking model name..."); Expect(modelInfo.Name == modelName); Console.WriteLine("ModelInfoTests: checking constraint count (1)..."); Expect(modelInfo.Constraints.Count() == 1); Console.WriteLine("ModelInfoTests: checking constraint..."); Expect(modelInfo.Constraints.First() == constraint); /* * Console.WriteLine("ModelInfoTests: checking event count (1)..."); * Expect(modelInfo.Events.Count() == 1); * Console.WriteLine("ModelInfoTests: checking event..."); * Expect(modelInfo.Events.First() == testEvent); */ Console.WriteLine("ModelInfoTests: checking expression count (3)..."); Expect(modelInfo.Expressions.Count() == 3); Console.WriteLine("ModelInfoTests: checking expressions..."); var expressions = modelInfo.Expressions.Where(net => net.Name == expressionName).ToList(); Expect(expressions.Count == 1); Expect(expressions[0] == expressionTree); Console.WriteLine("ModelInfoTests: checking locale count (1)..."); Expect(modelInfo.Locales.Count() == 1); Console.WriteLine("ModelInfoTests: checking locale..."); Expect(modelInfo.Locales.First() == locale); Console.WriteLine("ModelInfoTests: checking observable count (1)..."); Expect(modelInfo.Observables.Count() == 1); Console.WriteLine("ModelInfoTests: checking observable..."); Expect(modelInfo.Observables.First() == observable); Console.WriteLine("ModelInfoTests: checking parameter count (1)..."); Expect(modelInfo.Parameters.Count() == 1); Console.WriteLine("ModelInfoTests: checking parameter..."); Expect(modelInfo.Parameters.First() == parameter); /* * Console.WriteLine("ModelInfoTests: checking predicate count (3)..."); * Expect(modelInfo.Predicates.Count() == 3); */ Console.WriteLine("ModelInfoTests: checking predicate count (2)..."); Expect(modelInfo.Predicates.Count() == 2); Console.WriteLine("ModelInfoTests: checking predicate..."); var predicates = modelInfo.Predicates.Where(pi => pi.Name == predicateName).ToList(); Expect(predicates.Count == 1); Expect(predicates[0] == predicate); Console.WriteLine("ModelInfoTests: checking reaction count (1)..."); Expect(modelInfo.Reactions.Count() == 1); Console.WriteLine("ModelInfoTests: checking reaction..."); Expect(modelInfo.Reactions.First() == reaction); Console.WriteLine("ModelInfoTests: checking species count (1)..."); Expect(modelInfo.Species.Count() == 1); Console.WriteLine("ModelInfoTests: checking species..."); Expect(modelInfo.Species.First() == reactant); }