public string GetPostFixNotation() { return($"{FirstParameter.GetInFixNotation()} {SecondParameter.GetInFixNotation()} log "); }
public string GetPreFixNotation() { return($"log {FirstParameter.GetInFixNotation()} {SecondParameter.GetInFixNotation()} "); }
public double Evaluate(Dictionary <string, double> input) { return(Math.Log(SecondParameter.Evaluate(input)) / Math.Log(FirstParameter.Evaluate(input))); }
public string GetInFixNotation() { return($"log({FirstParameter.GetInFixNotation()}, {SecondParameter.GetInFixNotation()}) "); }
public void enum_that_requires_casting_handling() { Get(d => d.Order == (SomeEnum?)1).Should().Be("(Order = @0)"); FirstParameter.Should().Be(SomeEnum.First); FirstParameter.Should().BeOfType <SomeEnum>(); }
public IExpressionNode DeepCopy() { return(new FunctionLog(FirstParameter.DeepCopy(), SecondParameter.DeepCopy())); }
public void string_contains() { Get(d => d.Title.Contains("''t")).Should().Be("Title like @0"); FirstParameter.Should().Be("%''t%"); }
public void id_greater_than_12_and_less_than_24() { Get(p => p.SomeId > 12 && p.SomeId < 24).Should().Be("((SomeId > @0) and (SomeId < @1))"); FirstParameter.Should().Be(12); Parameter(1).Should().Be(24); }
public void string_starts_with() { Get(d => d.Title.StartsWith("t")).Should().Be("Title like @0"); FirstParameter.Should().Be("t%"); }
public void string_ends_with() { Get(d => d.Title.EndsWith("t")).Should().Be("Title like @0"); FirstParameter.Should().Be("%t"); }
public void nullable_property_equality() { Get(p => p.Order == SomeEnum.Last).Should().Be("(Order = @0)"); FirstParameter.Should().Be(SomeEnum.Last); }
public void handle_nullable_boolean_property_false() { Get(d => !d.IsBla).Should().Be("IsBla=@0"); FirstParameter.Should().Be(false); }
public void id_and_isActive_is_explicitely_true() { Get(d => d.SomeId == 23 && d.IsActive == true).Should().Be("((SomeId = @0) and IsActive=@1)"); FirstParameter.Should().Be(23); Parameter(1).Should().Be(true); }
public static long Run(List <long> Program) { CurrentProgram = Program; IndexPointer = 0; while (true) { Console.WriteLine("IndexPointer: " + IndexPointer); char[] opcode = ProcessOpcode(Program[(int)IndexPointer]); if (new string(opcode, 3, 2) == "99") { Console.WriteLine("In the 99"); long output = Output.Last(); IndexPointer = -1; SaveMemory(); return(output); } long FirstParameter; long SecondParameter; switch (new string(opcode, 3, 2)) { case "01": FirstParameter = GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); SecondParameter = GetByIndex(IndexPointer + 2, GetMode(opcode, 1)); SetByIndex(IndexPointer + 3, FirstParameter + SecondParameter, GetMode(opcode, 0)); IndexPointer += 4; break; case "02": FirstParameter = GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); SecondParameter = GetByIndex(IndexPointer + 2, GetMode(opcode, 1)); SetByIndex(IndexPointer + 3, FirstParameter * SecondParameter, GetMode(opcode, 0)); IndexPointer += 4; break; case "03": SetByIndex(IndexPointer + 1, SystemId.First(), GetMode(opcode, 2)); SystemId.Dequeue(); IndexPointer += 2; break; case "04": Output.Add(GetByIndex(IndexPointer + 1, GetMode(opcode, 2))); IndexPointer += 2; SaveMemory(); return(Output.Last()); case "05": FirstParameter = GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); if (!FirstParameter.Equals(0)) { IndexPointer = (int)GetByIndex(IndexPointer + 2, GetMode(opcode, 1)); } else { IndexPointer += 3; } break; case "06": FirstParameter = GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); if (FirstParameter.Equals(0)) { IndexPointer = (int)GetByIndex(IndexPointer + 2, GetMode(opcode, 1)); } else { IndexPointer += 3; } break; case "07": FirstParameter = GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); SecondParameter = GetByIndex(IndexPointer + 2, GetMode(opcode, 1)); if (FirstParameter < SecondParameter) { SetByIndex(IndexPointer + 3, 1, GetMode(opcode, 0)); } else { SetByIndex(IndexPointer + 3, 0, GetMode(opcode, 0)); } IndexPointer += 4; break; case "08": FirstParameter = GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); SecondParameter = GetByIndex(IndexPointer + 2, GetMode(opcode, 1)); if (FirstParameter.Equals(SecondParameter)) { SetByIndex(IndexPointer + 3, 1, GetMode(opcode, 0)); } else { SetByIndex(IndexPointer + 3, 0, GetMode(opcode, 0)); } IndexPointer += 4; break; case "09": RelativeBase += (int)GetByIndex(IndexPointer + 1, GetMode(opcode, 2)); IndexPointer += 2; break; default: Console.WriteLine("opcode is out of range!"); throw new ArgumentOutOfRangeException(nameof(opcode), opcode, "Opcode is OutOfRange"); } } }
/// <summary> /// Generates a static binary function call expression. /// </summary> /// <param name="t">The type to call on.</param> /// <param name="functionName">Name of the function.</param> /// <param name="tolerance">The tolerance, should there be any. This argument can be <c>null</c> (<c>Nothing</c> in Visual Basic).</param> /// <returns> /// Expression. /// </returns> /// <exception cref="ArgumentException">The function name is invalid.</exception> protected Expression GenerateBinaryFunctionCallFirstParameterInstance(Type t, string functionName, Tolerance?tolerance) { if (string.IsNullOrWhiteSpace(functionName)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.FunctionCouldNotBeFound, functionName), nameof(functionName)); } Type firstParameterType = ParameterTypeFromParameter(FirstParameter); Type secondParameterType = ParameterTypeFromParameter(SecondParameter); MethodInfo?mi = t.GetMethodWithExactParameters(functionName, firstParameterType, secondParameterType); if (mi == null) { if ((firstParameterType == typeof(long) && secondParameterType == typeof(double)) || (firstParameterType == typeof(double) && secondParameterType == typeof(long))) { firstParameterType = typeof(double); secondParameterType = typeof(double); mi = t.GetMethodWithExactParameters(functionName, firstParameterType, secondParameterType); if (mi == null) { firstParameterType = typeof(long); secondParameterType = typeof(long); mi = t.GetMethodWithExactParameters(functionName, firstParameterType, secondParameterType); if (mi == null) { firstParameterType = typeof(int); secondParameterType = typeof(int); mi = t.GetMethodWithExactParameters(functionName, firstParameterType, secondParameterType) ?? throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.FunctionCouldNotBeFound, functionName), nameof(functionName)); } } } else { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.FunctionCouldNotBeFound, functionName), nameof(functionName)); } } Expression e1, e2; if (tolerance == null) { e1 = FirstParameter.GenerateExpression(); e2 = SecondParameter.GenerateExpression(); } else { e1 = FirstParameter.GenerateExpression(tolerance); e2 = SecondParameter.GenerateExpression(tolerance); } if (e1.Type != firstParameterType) { e1 = Expression.Convert(e1, firstParameterType); } if (e2.Type != secondParameterType) { e2 = Expression.Convert(e2, secondParameterType); } return(Expression.Call(e1, mi, e2)); }
public long Evaluate() { return(FirstParameter.Evaluate() * SecondParameter.Evaluate()); }
public bool ContainsVariable() { return(FirstParameter.ContainsVariable() || SecondParameter.ContainsVariable()); }
public void id_and_isActive_not_true() { Get(d => d.SomeId == 23 && !d.IsActive).Should().Be("((SomeId = @0) and IsActive=@1)"); FirstParameter.Should().Be(23); Parameter(1).Should().Be(false); }
public void enum_handling() { Get(d => d.Order == SomeEnum.First).Should().Be("(Order = @0)"); FirstParameter.Should().Be(SomeEnum.First); FirstParameter.Should().BeOfType <SomeEnum>(); }