Exemple #1
0
        private static double CheckArgs(MathValue[] values)
        {
            if (values.Length < 1)
                throw new MathException("Need 1 argument");

            var arg = values[0] as MathNumber;
            if (arg == null)
                throw new MathException("Argument is not a number");

            return arg.ToNumber();
        }
Exemple #2
0
        private static Tuple<double, double> CheckArgs2(MathValue[] values)
        {
            if (values.Length < 1)
                throw new MathException("Need 1 argument");

            var arg1 = values[0] as MathNumber;
            if (arg1 == null)
                throw new MathException("Argument 1 is not a number");

            var arg2 = values[1] as MathNumber;
            if (arg2 == null)
                throw new MathException("Argument 2 is not a number");

            return Tuple.Create(arg1.ToNumber(), arg2.ToNumber());
        }
Exemple #3
0
        public void MathValueTest()
        {
            ProfileParameter rpm = new ProfileParameter();

            rpm.Name                  = "Engine Speed";
            rpm.Conversion            = new Conversion();
            rpm.Conversion.Name       = "RPM";
            rpm.Conversion.Expression = "x";

            ProfileParameter maf = new ProfileParameter();

            maf.Name                  = "Mass Air Flow";
            maf.Conversion            = new Conversion();
            maf.Conversion.Name       = "g/s";
            maf.Conversion.Expression = "x";

            MathValue load = new MathValue();

            load.XParameter  = rpm.Name;
            load.XConversion = rpm.Conversion.Name;
            load.YParameter  = maf.Name;
            load.YConversion = maf.Conversion.Name;
            load.Format      = "0.00";
            load.Formula     = "(y*60)/x";

            LogProfile profile = new LogProfile();

            profile.ParameterGroups.Add(new ParameterGroup());
            profile.ParameterGroups[0].Parameters.Add(rpm);
            profile.ParameterGroups[0].Parameters.Add(maf);

            //MockDevice mockDevice = new MockDevice();
            //MockLogger mockLogger = new MockLogger();
            //Vehicle vehicle = new Vehicle(
            //    new MockDevice(),
            //    new Protocol(),
            //    mockLogger,
            //    new ToolPresentNotifier(mockDevice, mockLogger));
            //Logger logger = new Logger(vehicle, profile, mathValueConfiguration);

            //MathValueConfigurationLoader loader = new MathValueConfigurationLoader();
            //loader.Initialize();
            MathValueConfiguration mathValueConfiguration = new MathValueConfiguration();

            mathValueConfiguration.MathValues = new List <MathValue>();
            mathValueConfiguration.MathValues.Add(load);

            DpidValues dpidValues = new DpidValues();

            dpidValues.Add(rpm, new ParameterValue()
            {
                RawValue = 1000
            });
            dpidValues.Add(maf, new ParameterValue()
            {
                RawValue = 100
            });

            MathValueProcessor   processor  = new MathValueProcessor(profile, mathValueConfiguration);
            IEnumerable <string> mathValues = processor.GetMathValues(dpidValues);

            Assert.AreEqual(1, mathValues.Count(), "Number of math values.");
            string loadValue = mathValues.First();

            Assert.AreEqual("6.00", loadValue, "Load value.");
        }
Exemple #4
0
 public static IMathContextBuilder WithTerm(this IMathContextBuilder builder, string term, MathValue mathValue)
 {
     return(builder.WithTerm(term, new StaticValueProvider(mathValue)));
 }
Exemple #5
0
 public Operation(MathValue a, MathValue b) : base(a, b, OperationType.Sum)
 {
 }
Exemple #6
0
 public Operation(MathValue a, MathValue b, OperationType type) : base()
 {
     A      = a;
     B      = b;
     OpType = type;
 }
Exemple #7
0
        internal static Value ParseImpl(ParserStream stream, IPosition forPosition, bool allowSelectorIncludes)
        {
            Value ret = null;

            while (stream.HasMore())
            {
                var c = stream.Peek();

                if (char.IsWhiteSpace(c))
                {
                    stream.AdvancePastWhiteSpace();
                    continue;
                }

                if (ret != null)
                {
                    if (c.In('+', '-', '*', '/', '%'))
                    {
                        ret = ParseMathValue(c, ret, stream, forPosition);
                        continue;
                    }

                    if (c == '?')
                    {
                        stream.Advance(); // skip ?
                        if (stream.HasMore() && stream.Peek() == '?')
                        {
                            if (ret == null)
                            {
                                Current.RecordError(ErrorType.Parser, forPosition, "Expected value, found '??'");
                                throw new StoppedParsingException();
                            }

                            stream.Advance(); // skip second ?
                            var rhs = ParseImpl(stream, forPosition, allowSelectorIncludes);
                            ret = new MathValue(ret, Operator.Take_Exists, rhs);
                            continue;
                        }

                        ret = new LeftExistsValue(ret);
                        continue;
                    }
                }

                if (char.IsDigit(c) || c == '.' || c == '-')
                {
                    ret = Combine(ret, ParseNumber(stream, forPosition));
                    continue;
                }

                if (c == '(')
                {
                    ret = Combine(ret, ParseGroup(stream, forPosition));
                    continue;
                }

                if (c.In('\'', '"'))
                {
                    ret = Combine(ret, ParseQuotedString(c, stream, forPosition));
                    continue;
                }

                if (c == '#')
                {
                    ret = Combine(ret, ParseHashColor(stream, forPosition));
                    continue;
                }

                if (c == '@')
                {
                    ret = Combine(ret, ParseFuncValue(stream, forPosition, allowSelectorIncludes));
                    continue;
                }

                ret = Combine(ret, ParseString(stream, forPosition));
            }

            return(ret);
        }
 /// <summary>
 /// <para></para>
 /// </summary>
 /// <param name="value"></param>
 public StaticValueProvider(bool value)
 {
     Value = new MathValue(value);
 }
 /// <summary>
 /// <para></para>
 /// </summary>
 /// <param name="value"></param>
 public StaticValueProvider(float value)
 {
     Value = new MathValue(value, false);
 }
 /// <summary>
 /// <para></para>
 /// </summary>
 /// <param name="value"></param>
 public StaticValueProvider(MathValue value)
 {
     Value = value;
 }