public void ObservableInfoTest() { var operatorOne = new MultiplyOperator(TwentyOne, Two); var expressionOne = new NumericExpressionTree(null, operatorOne); var observableOne = new ObservableInfo(expressionOne); Console.Write("Created new observable: "); Console.WriteLine(observableOne); Console.WriteLine("ObservableTest: testing anonymous observable Name property..."); Expect(observableOne.Name == string.Empty); Console.WriteLine("ObservableTest: testing Expression property (observableOne)..."); Expect(observableOne.Expression == expressionOne); const string observableName = "observableTwo"; var operatorTwo = new AddOperator(Two, Three); var expressionTwo = new NumericExpressionTree(null, operatorTwo); var observableTwo = new ObservableInfo(observableName, expressionTwo); Console.Write("Created new ObservableInfo: "); Console.WriteLine(observableTwo); Console.WriteLine("ObservableTest: testing Name property..."); Expect(observableTwo.Name == observableName); Console.WriteLine("ObservableTest: testing Expression property (observableTwo)..."); Expect(observableTwo.Expression == expressionTwo); }
public void ReactionInfoTest() { // Add a reactant, reactant shows up in Reactants list var builder = new ReactionInfo.ReactionBuilder(); ReactionInfo reaction = builder.Reaction; var reactant = new SpeciesDescription("reactant", 2012); builder.AddReactant(reactant); Console.WriteLine("Checking for reactant added to reaction with ReactionBuilder..."); Expect(reaction.Reactants.First() == reactant); // Add a product, product shows up in Products list var product = new SpeciesDescription("product", 2112); builder.AddProduct(product); Console.WriteLine("Checking for product added to reaction with ReactionBuilder..."); Expect(reaction.Products.First() == product); // Set rate, reaction rate is set. var expression = new NumericExpressionTree(string.Empty, new MultiplyOperator(new SymbolReference("reactant"), new SymbolReference("product"))); builder.SetRate(expression); Console.WriteLine("Checking for reaction rate set from ReactionBuilder..."); Expect(reaction.RateExpression == expression); Console.WriteLine("Checking !reaction.HasDelay (before calling builder.SetDelay())..."); Expect(!reaction.HasDelay); var delay = new NumericExpressionTree(string.Empty, new Constant(3.14159265f)); builder.SetDelay(delay); Console.WriteLine("Checking reaction.HasDelay (after calling builder.SetDelay())..."); Expect(reaction.HasDelay); Console.WriteLine("Checking reaction for correct delay..."); Expect(reaction.DelayExpression == delay); Console.WriteLine(""); }
public void NumericExpressionTreeTest() { const string name = "net"; var expression = new MultiplyOperator(Two, TwentyOne); var net = new NumericExpressionTree(name, expression); Console.Write("Created new NumericExpressionTree: "); Console.WriteLine(net); Console.WriteLine("NumericExpressionTreeTest: test Name property..."); Expect(net.Name == name); Console.WriteLine("NumericExpressionTreeTest: test expression and ResolveReferences()..."); IDictionary <string, IValue> nmap = new Dictionary <string, IValue>(); IValue value = net.ResolveReferences(nmap); Expect(value.Value == 42.0f); Console.WriteLine("NumericExpressionTreeTest: testing map size (1)..."); Expect(nmap.Count == 1); Console.WriteLine("NumericExpressionTreeTest: testing map contents..."); Expect(nmap[name] == value); }
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); }
public Expression(NumericExpressionTree expressionTree, IDictionary <string, IValue> map) { _tree = expressionTree; _expression = expressionTree.ResolveReferences(map); }