Пример #1
0
        /// <summary>
        /// Initializes an exception with the specified schema, message, and inner exception
        /// </summary>
        /// <param name="schema">The schema whose compilation caused the error</param>
        /// <param name="message">The message that describes the error</param>
        /// <param name="inner">The exception that is the cause of this exception</param>
        public CompilationException(GraspSchema schema, string message, Exception inner)
            : base(message, inner)
        {
            Contract.Requires(schema != null);

            Schema = schema;
        }
Пример #2
0
        /// <summary>
        /// Initializes an executable with the specified schema and calculator
        /// </summary>
        /// <param name="schema">The schema which generated this executable</param>
        /// <param name="calculator">The calculator which applies the schema's calculations to runtimes generated by this executable</param>
        public GraspExecutable(GraspSchema schema, ICalculator calculator)
        {
            Contract.Requires(schema != null);
            Contract.Requires(calculator != null);

            Schema = schema;
            Calculator = calculator;
        }
Пример #3
0
        internal GraspCompiler(GraspSchema schema)
        {
            _schema = schema;

            _calculations = schema.Calculations.Select(calculation => new CalculationSchema(calculation)).ToList();

            _variables = new HashSet<Variable>(schema.Variables.Concat(_calculations.Select(calculation => calculation.OutputVariable)));
        }
Пример #4
0
        protected override void Given()
        {
            _result = new Derived();

            _calculation = new Calculation(new Variable("Grasp", "Output", typeof(Base)), Expression.Constant(_result));

            _schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { _calculation });
        }
Пример #5
0
        protected override void Given()
        {
            _unknownVariable = new Variable("Grasp", "Unknown", typeof(int));

            _calculation = new Calculation(new Variable("Grasp", "Output", typeof(int)), Variable.Expression(_unknownVariable));

            _schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { _calculation });
        }
Пример #6
0
        protected override void Given()
        {
            _schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>());

            _calculator = A.Fake<ICalculator>();

            _runtime = new GraspRuntime(_schema, _calculator, Enumerable.Empty<VariableBinding>());
        }
Пример #7
0
        protected override void Given()
        {
            var implicitVariable = new Variable("Grasp", "Implicit", typeof(int));

            var calculation1 = new Calculation(implicitVariable, Expression.Constant(1));
            var calculation2 = new Calculation(new Variable("Grasp", "Output", typeof(int)), Variable.Expression(implicitVariable));

            _schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { calculation1, calculation2 });
        }
        /// <summary>
        /// Initializes an exception with the specified variable, calculation, and schema
        /// </summary>
        /// <param name="variable">The invalid variable</param>
        /// <param name="calculation">The calculation which references the invalid variable</param>
        /// <param name="schema">The schema which defines the valid variables</param>
        public InvalidCalculationVariableException(Variable variable, Calculation calculation, GraspSchema schema)
        {
            Contract.Requires(variable != null);
            Contract.Requires(calculation != null);
            Contract.Requires(schema != null);

            Variable = variable;
            Calculation = calculation;
            Schema = schema;
        }
Пример #9
0
        protected override void Given()
        {
            _variable = new Variable("Grasp", "Test", typeof(int));

            _schema = new GraspSchema(new[] { _variable }, Enumerable.Empty<Calculation>());

            _value = 1;

            _runtime = new GraspRuntime(_schema, A.Fake<ICalculator>(), new[] { new VariableBinding(_variable, _value) });
        }
        /// <summary>
        /// Initializes an exception with the specified variable, calculation, schema, message, and inner exception
        /// </summary>
        /// <param name="variable">The invalid variable</param>
        /// <param name="calculation">The calculation which references the invalid variable</param>
        /// <param name="schema">The schema which defines the valid variables</param>
        /// <param name="message">The message that describes the error</param>
        /// <param name="inner">The exception that is the cause of this exception</param>
        public InvalidCalculationVariableException(Variable variable, Calculation calculation, GraspSchema schema, string message, Exception inner)
            : base(message, inner)
        {
            Contract.Requires(variable != null);
            Contract.Requires(calculation != null);
            Contract.Requires(schema != null);

            Variable = variable;
            Calculation = calculation;
            Schema = schema;
        }
Пример #11
0
        protected override void Given()
        {
            _variables = new[] { new Variable("Grasp", "Test", typeof(int)), new Variable("Grasp", "Test2", typeof(int)) };

            _calculations = new[]
            {
                new Calculation(new Variable("Grasp", "TestOutput", typeof(int)), Expression.Constant(0)),
                new Calculation(new Variable("Grasp", "Test2Output", typeof(int)), Expression.Constant(1))
            };

            _schema = new GraspSchema(_variables, _calculations);

            _calculator = A.Fake<ICalculator>();
        }
Пример #12
0
        protected override void Given()
        {
            _variable = new Variable("Grasp", "Test", typeof(int));

            _schema = new GraspSchema(new[] { _variable }, Enumerable.Empty<Calculation>());

            _initialState = A.Fake<IRuntimeSnapshot>();

            _initialValue = 1;

            A.CallTo(() => _initialState.GetValue(_variable)).Returns(_initialValue);

            _executable = new GraspExecutable(_schema, A.Fake<ICalculator>());
        }
Пример #13
0
        protected override void Given()
        {
            _outputVariable = new Variable("Grasp", "Test", typeof(int));

            _value = 1;

            _function = runtime => _value;

            _calculator = new FunctionCalculator(_outputVariable, _function);

            var schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>());

            _runtime = new GraspRuntime(schema, _calculator, Enumerable.Empty<VariableBinding>());
        }
Пример #14
0
        protected override void Given()
        {
            _left = 1;
            _right = 2;

            _outputVariable = new Variable("Grasp", "Output", typeof(int));

            var calculation = new Calculation(_outputVariable, Expression.Add(Expression.Constant(_left), Expression.Constant(_right)));

            var schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { calculation });

            var executable = schema.Compile();

            _runtime = executable.GetRuntime(A.Fake<IRuntimeSnapshot>());
        }
Пример #15
0
        protected override void Given()
        {
            // A = B
            // B = C
            // C = A
            //
            // Cycle: A -> B -> C -> A

            var variableA = new Variable("Grasp", "A", typeof(int));
            var variableB = new Variable("Grasp", "B", typeof(int));
            var variableC = new Variable("Grasp", "C", typeof(int));

            _calculationA = new Calculation(variableA, Variable.Expression(variableB));
            _calculationB = new Calculation(variableB, Variable.Expression(variableC));
            _calculationC = new Calculation(variableC, Variable.Expression(variableA));

            _schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { _calculationA, _calculationB, _calculationC });
        }
Пример #16
0
        protected override void Given()
        {
            _left1 = 1;
            _right1 = 2;

            _left2 = 10;

            _outputVariable1 = new Variable("Grasp", "Output1", typeof(int));
            _outputVariable2 = new Variable("Grasp", "Output2", typeof(int));

            var calculation1 = new Calculation(_outputVariable1, Expression.Add(Expression.Constant(_left1), Expression.Constant(_right1)));
            var calculation2 = new Calculation(_outputVariable2, Expression.Add(Expression.Constant(_left2), Variable.Expression(_outputVariable1)));

            var schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { calculation1, calculation2 });

            var executable = schema.Compile();

            _runtime = executable.GetRuntime(A.Fake<IRuntimeSnapshot>());
        }
Пример #17
0
        protected override void Given()
        {
            _outputVariable1 = new Variable("Grasp", "Test1", typeof(int));
            _outputVariable2 = new Variable("Grasp", "Test2", typeof(int));

            _value1 = 1;
            _value2 = 2;

            _function1 = runtime => _value1;
            _function2 = runtime => _value2;

            _calculator1 = new FunctionCalculator(_outputVariable1, _function1);
            _calculator2 = new FunctionCalculator(_outputVariable2, _function2);

            _compositeCalculator = new CompositeCalculator(_calculator1, _calculator2);

            var schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>());

            _runtime = new GraspRuntime(schema, _compositeCalculator, Enumerable.Empty<VariableBinding>());
        }
        protected override void Given()
        {
            _leftValue = 1;
            _right = 2;

            var left = new Variable("Grasp", "Left", typeof(int));

            _outputVariable = new Variable("Grasp", "Output", typeof(int));

            var calculation = new Calculation(_outputVariable, Expression.Add(Variable.Expression(left), Expression.Constant(_right)));

            var schema = new GraspSchema(new[] { left }, new[] { calculation });

            var executable = schema.Compile();

            var initialState = A.Fake<IRuntimeSnapshot>();

            A.CallTo(() => initialState.GetValue(left)).Returns(_leftValue);

            _runtime = executable.GetRuntime(initialState);
        }
Пример #19
0
        protected override void Given()
        {
            var calculation = new Calculation(new Variable("Grasp", "Output", typeof(int)), new InvalidExpression());

            _schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { calculation });
        }
Пример #20
0
        /// <summary>
        /// Initializes an exception with the specified schema
        /// </summary>
        /// <param name="schema">The schema whose compilation caused the error</param>
        public CompilationException(GraspSchema schema)
        {
            Contract.Requires(schema != null);

            Schema = schema;
        }
Пример #21
0
        protected override void Given()
        {
            // A = B + C
            // B = D + E
            // C = F - 1
            // D = 2
            // E = C + 1
            // F = E * 2
            //
            // Cycle: E -> C -> F -> E
            //
            // Path from root: A -> B -> E -> C -> F -> E

            var variableA = new Variable("Grasp", "A", typeof(int));
            var variableB = new Variable("Grasp", "B", typeof(int));
            var variableC = new Variable("Grasp", "C", typeof(int));
            var variableD = new Variable("Grasp", "D", typeof(int));
            var variableE = new Variable("Grasp", "E", typeof(int));
            var variableF = new Variable("Grasp", "F", typeof(int));

            _calculationA = new Calculation(variableA, Expression.Add(Variable.Expression(variableB), Variable.Expression(variableC)));
            _calculationB = new Calculation(variableB, Expression.Add(Variable.Expression(variableD), Variable.Expression(variableE)));
            _calculationC = new Calculation(variableC, Expression.Subtract(Variable.Expression(variableF), Expression.Constant(1)));
            _calculationD = new Calculation(variableD, Expression.Constant(2));
            _calculationE = new Calculation(variableE, Expression.Add(Variable.Expression(variableC), Expression.Constant(1)));
            _calculationF = new Calculation(variableF, Expression.Multiply(Variable.Expression(variableE), Expression.Constant(2)));

            _schema = new GraspSchema(Enumerable.Empty<Variable>(), new[] { _calculationA, _calculationB, _calculationC, _calculationD, _calculationE, _calculationF });
        }
Пример #22
0
        protected override void Given()
        {
            _schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>());

            _calculator = A.Fake<ICalculator>();
        }