Ejemplo n.º 1
0
        public void ReactionIsLocalTest()
        {
            var          builder  = new ReactionInfo.ReactionBuilder();
            ReactionInfo reaction = builder.Reaction;

            var reactantA = new SpeciesDescription("reactantA", new LocaleInfo("locale1"));

            var productA = new SpeciesDescription("productA", reactantA.Locale);

            builder.AddReactant(reactantA);
            builder.AddProduct(productA);

            Console.WriteLine("Checking for reaction.IsLocal with reactants and products in same locale...");
            Expect(reaction.IsLocal);
            Expect(!reaction.IsDiffusion);

            builder  = new ReactionInfo.ReactionBuilder();
            reaction = builder.Reaction;

            var productB = new SpeciesDescription("productB", new LocaleInfo("locale2"));

            builder.AddReactant(reactantA);
            builder.AddProduct(productB);

            Console.WriteLine("Checking for !reaction.IsLocal with reactants and products from different locales...");
            Expect(!reaction.IsLocal);
            Expect(reaction.IsDiffusion);

            Console.WriteLine("");
        }
Ejemplo n.º 2
0
        public void MixedLocaleproductTest()
        {
            var builder = new ReactionInfo.ReactionBuilder();

            var species1 = new SpeciesDescription("A-Species", new LocaleInfo("compartment-A"));

            builder.AddProduct(species1);

            Console.WriteLine("Checking for ArgumentException() with products from difference locales...");
            Console.WriteLine("");

            var species2 = new SpeciesDescription("B-Species", new LocaleInfo("compartment-B"));

            builder.AddProduct(species2);
        }
Ejemplo n.º 3
0
        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("");
        }
Ejemplo n.º 4
0
        private static Reaction CreateReaction(SpeciesDescription info1, Species reactant1, SpeciesDescription info2, Species reactant2, SpeciesDescription info3, Species product1, double rate)
        {
            var builder = new ReactionInfo.ReactionBuilder("theReaction");

            builder.AddReactant(info1);
            builder.AddReactant(info2);
            builder.AddProduct(info3);
            builder.SetRate(new NumericExpressionTree(new Constant(rate)));

            var reactionInfo = builder.Reaction;
            var speciesMap   = new Dictionary <SpeciesDescription, Species>(3)
            {
                { info1, reactant1 }, { info2, reactant2 }, { info3, product1 }
            };
            var symbolMap = new Dictionary <string, IValue>();
            var reaction  = new Reaction(reactionInfo, speciesMap, symbolMap);

            return(reaction);
        }
Ejemplo n.º 5
0
        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);
        }