Ejemplo n.º 1
0
        public void ConstraintInfoTest()
        {
            IBooleanOperator trueExpression = new GreaterThanOperator(Three, Two);
            var trueTree      = new BooleanExpressionTree("true", trueExpression);
            var constraintOne = new ConstraintInfo(trueTree);

            Console.Write("Created constraint: ");
            Console.WriteLine(constraintOne);
            Console.WriteLine("ConstraintInfoTest: testing name of anonymous constraint...");
            Expect(constraintOne.Name == string.Empty);
            Console.WriteLine("ConstraintInfoTest: testing Predicate property (constraintOne)...");
            Expect(constraintOne.Predicate == trueTree);

            const string     constraintName  = "ConstraintTwo";
            IBooleanOperator falseExpression = new LessThanOperator(Three, Two);
            var falseTree     = new BooleanExpressionTree("false", falseExpression);
            var constraintTwo = new ConstraintInfo(constraintName, falseTree);

            Console.Write("Created constraint: ");
            Console.WriteLine(constraintTwo);
            Console.WriteLine("ConstraintInfoTest: testing Name of named constraint...");
            Expect(constraintTwo.Name == constraintName);
            Console.WriteLine("ConstraintInfoTest: testing Predicate property (constraintTwo)...");
            Expect(constraintTwo.Predicate == falseTree);
        }
Ejemplo n.º 2
0
        public void BooleanExpressionTreeTest()
        {
            const string     name       = "bit";
            IBooleanOperator expression = new GreaterThanOperator(Three, Two);
            var bet = new BooleanExpressionTree(name, expression);

            Console.Write("Created new BooleanExpressionTree: ");
            Console.WriteLine(bet);
            Console.WriteLine("BooleanExpressionTreeTest: test Name property...");
            Expect(bet.Name == name);
            Console.WriteLine("BooleanExpressionTreeTest: test expression and ResolveReferences()...");
            IDictionary <string, IBoolean> bmap = new Dictionary <string, IBoolean>();
            IBoolean predicate = bet.ResolveReferences(bmap, null);

            Expect(predicate.Value == true);
            Console.WriteLine("BooleanExpressionTreeTest: testing map size (1)...");
            Expect(bmap.Count == 1);
            Console.WriteLine("BooleanExpressionTreeTest: testing map contents...");
            Expect(bmap[name] == predicate);
        }
Ejemplo n.º 3
0
 public Predicate(BooleanExpressionTree expressionTree, IDictionary <string, IBoolean> bmap, IDictionary <string, IValue> nmap)
 {
     _tree       = expressionTree;
     _expression = expressionTree.ResolveReferences(bmap, nmap);
 }
Ejemplo n.º 4
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);
        }