public void Pitagora() { Interpreter.AddVariable("a", 3); Interpreter.AddVariable("b", 4); AreEqual(5, Interpreter.Evaluate("sqrt(pow(a, 2) + pow(b, 2))")); }
public override void Setup() { base.Setup(); Interpreter.AddVariable(FirstInstanceName, new Kickup(), int.MaxValue); Interpreter.AddVariable(StringInstanceNameAndValue, StringInstanceNameAndValue, int.MaxValue); Interpreter.AddType(typeof(Podobranchia), int.MaxValue); }
public void ReAddingVariableWithSameName() { const string variableName = "show"; Interpreter.AddVariable(variableName, 1); Interpreter.AddVariable(variableName, 2); }
public void OddEvenIdentities() { Interpreter.AddVariable("x", 1.2423); AreEqual(Interpreter.Evaluate("sin(negate(x))"), Interpreter.Evaluate("negate(sin(x))")); AreEqual(Interpreter.Evaluate("cos(negate(x))"), Interpreter.Evaluate("cos(x)")); AreEqual(Interpreter.Evaluate("tan(negate(x))"), Interpreter.Evaluate("negate(tan(x))")); }
public override void Setup() { base.Setup(); _target = new Kickup(); Interpreter.AddVariable(FirstInstanceName, _target, int.MaxValue); Interpreter.AddVariable(SecondInstanceName, _target, int.MaxValue); Interpreter.AddType(typeof (Podobranchia), int.MaxValue); }
public void CaretAtEndOfTargetValue_OverwriteFollowingInputUponAutocomplete() { Interpreter.AddVariable("variable", new object()); Input.Value = "va gibberish"; Input.CaretIndex = 2; Interpreter.Autocomplete(Input, true); Assert.AreEqual("variable", Input.Value); }
public void CaretAtBeginningOfInput_OverwriteInput() { Interpreter.AddVariable("variable", new object()); Input.Value = "gibberish"; Input.CaretIndex = 0; Interpreter.Autocomplete(Input, true); Assert.AreEqual("variable", Input.Value); }
/////////////////////////////////////////////////////////////////////// #region IState Members (Optional) /// <summary> /// Optionally initializes any state information required by the /// command. /// </summary> /// <param name="interpreter"> /// The interpreter context we are executing in. /// </param> /// <param name="clientData"> /// The extra data supplied when this command was initially created, if /// any. /// </param> /// <param name="result"> /// Upon success, this must contain the result of the command. /// Upon failure, this must contain an appropriate error message. /// </param> /// <returns> /// ReturnCode.Ok on success, ReturnCode.Error on failure. /// </returns> public override ReturnCode Initialize( Interpreter interpreter, /* in */ IClientData clientData, /* in */ ref Result result /* out */ ) { // // NOTE: We require a valid interpreter context. // if (interpreter == null) { result = "invalid interpreter"; return(ReturnCode.Error); } // // NOTE: Does the variable we are interested in already exist? // If so, skip adding it; unfortunately, this means that // we cannot add the variable trace. // VariableFlags varFlags = VariableFlags.GlobalOnly; string varName = GetType().Name; if (interpreter.DoesVariableExist( varFlags, varName) != ReturnCode.Ok) { // // NOTE: Grab the plugin that owns us. // IPlugin plugin = this.Plugin; // // NOTE: Add a variable that has our custom variable trace // callback. // TraceList traces = new TraceList( clientData, TraceFlags.None, plugin, new TraceCallback[] { PluginTraceCallback } ); if (interpreter.AddVariable( varFlags, varName, traces, true, ref result) == ReturnCode.Ok) { addedVariable = true; } else { return(ReturnCode.Error); } } return(base.Initialize(interpreter, clientData, ref result)); }
public void ArrayUnderlyingTypeLoaded() { var target = new int[0]; Interpreter.AddVariable("target", target); Input.Value = "In"; Input.CaretIndex = Input.Length; Interpreter.Autocomplete(Input, true); Assert.AreEqual("Int32", Input.Value); }
public void ArrayIndexerAutocomplete() { var target = new int[0]; Interpreter.AddVariable("target", target); Input.Value = "target[0]."; Input.CaretIndex = Input.Length; Interpreter.Autocomplete(Input, true); Assert.AreEqual("target[0].CompareTo", Input.Value); }
public void ListIndexerAutocomplete() { var target = new List <int>(); Interpreter.AddVariable("target", target); Input.Value = "target[0]."; Input.CaretIndex = Input.Length; Interpreter.Autocomplete(Input, true); Assert.Ignore("Need to find a solution to reflect generic collections (other than Array) element type."); Assert.AreEqual("target[0].CompareTo", Input.Value); }
public void DerivedInstanceAssignableToBaseInstanceType() { var baseVar = new Base(); var derivedVar = new Derived(); Interpreter.AddVariable("base", baseVar); Interpreter.AddVariable("derived", derivedVar); Input.Value = "base="; Input.CaretIndex = Input.Length; Interpreter.Autocomplete(Input, true); // =base Interpreter.Autocomplete(Input, true); // =derived Assert.AreEqual("base=derived", Input.Value); }
public void TriangleArea() { var a = 3.2; var b = 4; var c = 5; var semiperimeter = (a + b + c) / 2; Interpreter.AddVariable("semiperimeter", semiperimeter); Interpreter.AddVariable("a", a); Interpreter.AddVariable("b", b); Interpreter.AddVariable("c", c); AreEqual(Math.Sqrt(semiperimeter * (semiperimeter - a) * (semiperimeter - b) * (semiperimeter - c)), Interpreter.Evaluate("sqrt(semiperimeter * (semiperimeter - a) * (semiperimeter - b) * (semiperimeter - c))")); }
public void InstanceArrayDoubleIndexerAutocomplete() { var target = new A { C = new[] { new int[0] } }; Interpreter.AddVariable("target", target); Input.Value = "target.C[0][0]."; Input.CaretIndex = Input.Length; Interpreter.Autocomplete(Input, true); Assert.Ignore("More than single indexer access autocompletion not implemented."); Assert.AreEqual("target.C[0][0].CompareTo", Input.Value); }
public void ExpressionWithVariable() { Interpreter.AddVariable("x", 9); AreEqual(4 + Math.Pow(9, 2), Interpreter.Evaluate("4 + pow(x, 2)")); }
public void VariableNameCollidesWithFunctionName() { Interpreter.AddVariable(nameof(Math.Pow).ToLower(), 2); }
public override void Setup() { base.Setup(); Interpreter.AddVariable(FirstInstanceName, new Kickup(), int.MaxValue); }