コード例 #1
0
ファイル: FunctionLog.cs プロジェクト: RD211/DerivationSimple
 public string GetPostFixNotation()
 {
     return($"{FirstParameter.GetInFixNotation()} {SecondParameter.GetInFixNotation()} log ");
 }
コード例 #2
0
ファイル: FunctionLog.cs プロジェクト: RD211/DerivationSimple
 public string GetPreFixNotation()
 {
     return($"log {FirstParameter.GetInFixNotation()} {SecondParameter.GetInFixNotation()} ");
 }
コード例 #3
0
ファイル: FunctionLog.cs プロジェクト: RD211/DerivationSimple
 public double Evaluate(Dictionary <string, double> input)
 {
     return(Math.Log(SecondParameter.Evaluate(input)) / Math.Log(FirstParameter.Evaluate(input)));
 }
コード例 #4
0
ファイル: FunctionLog.cs プロジェクト: RD211/DerivationSimple
 public string GetInFixNotation()
 {
     return($"log({FirstParameter.GetInFixNotation()}, {SecondParameter.GetInFixNotation()}) ");
 }
コード例 #5
0
 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>();
 }
コード例 #6
0
ファイル: FunctionLog.cs プロジェクト: RD211/DerivationSimple
 public IExpressionNode DeepCopy()
 {
     return(new FunctionLog(FirstParameter.DeepCopy(), SecondParameter.DeepCopy()));
 }
コード例 #7
0
 public void string_contains()
 {
     Get(d => d.Title.Contains("''t")).Should().Be("Title like @0");
     FirstParameter.Should().Be("%''t%");
 }
コード例 #8
0
 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);
 }
コード例 #9
0
 public void string_starts_with()
 {
     Get(d => d.Title.StartsWith("t")).Should().Be("Title like @0");
     FirstParameter.Should().Be("t%");
 }
コード例 #10
0
 public void string_ends_with()
 {
     Get(d => d.Title.EndsWith("t")).Should().Be("Title like @0");
     FirstParameter.Should().Be("%t");
 }
コード例 #11
0
 public void nullable_property_equality()
 {
     Get(p => p.Order == SomeEnum.Last).Should().Be("(Order = @0)");
     FirstParameter.Should().Be(SomeEnum.Last);
 }
コード例 #12
0
 public void handle_nullable_boolean_property_false()
 {
     Get(d => !d.IsBla).Should().Be("IsBla=@0");
     FirstParameter.Should().Be(false);
 }
コード例 #13
0
 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);
 }
コード例 #14
0
    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");
            }
        }
    }
コード例 #15
0
    /// <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));
    }
コード例 #16
0
ファイル: Challenge1.cs プロジェクト: dschemp/adventOfCode
 public long Evaluate()
 {
     return(FirstParameter.Evaluate() * SecondParameter.Evaluate());
 }
コード例 #17
0
ファイル: FunctionLog.cs プロジェクト: RD211/DerivationSimple
 public bool ContainsVariable()
 {
     return(FirstParameter.ContainsVariable() || SecondParameter.ContainsVariable());
 }
コード例 #18
0
 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);
 }
コード例 #19
0
 public void enum_handling()
 {
     Get(d => d.Order == SomeEnum.First).Should().Be("(Order = @0)");
     FirstParameter.Should().Be(SomeEnum.First);
     FirstParameter.Should().BeOfType <SomeEnum>();
 }