public override void Evaluate()
 {
   Console.WriteLine(Sentence);
   string userInput;
   bool isValid = false;
   do
   {
     userInput = Console.ReadLine();
     if ( userInput.ToLower() == "yes" )
     {
       isValid = true;
       Positive.Evaluate();
     }
     else
     if ( userInput.ToLower() == "no" )
     {
       isValid = true;
       Negative.Evaluate();
     }
     else
       Console.WriteLine("Yous answer is not supported, retry please: " +
                         Environment.NewLine + 
                         Sentence);
   }
   while ( !isValid );
 }
Ejemplo n.º 2
0
        public void MustEncloseOperandInParentheses_WhenOperandHasSamePriority_ReturnsFalse()
        {
            var operand    = new Positive(new Constant("1"));
            var expression = new Negative(operand);

            Assert.IsFalse(expression.MustEncloseOperandInParentheses);
        }
Ejemplo n.º 3
0
 public void PositiveTest()
 {
     Assert.Equal(
         $"+ {OP_0}",
         Positive.Do(op0).ToString()
         );
 }
Ejemplo n.º 4
0
 public void sLoad()
 {
     lblAnalysed.Text   = Analysed.ToString();
     lblNegative.Text   = Negative.ToString();
     lblPositive.Text   = Positive.ToString();
     lblTweetCount.Text = TweetCount.ToString();
 }
Ejemplo n.º 5
0
    public override bool Evaluate(Client client)
    {
        // Test a client using the primitive operation
        bool res = Test(client);

        // Select a branch to follow
        return(res ? Positive.Evaluate(client) : Negative.Evaluate(client));
    }
Ejemplo n.º 6
0
        public void Positive_WithStringA_ThrowsRuntimeBinderException()
        {
            var variables  = MakeVariables();
            var operand    = new Constant("A");
            var expression = new Positive(operand);

            var actual = expression.GetExpression(variables)
                         .Calculate();
        }
Ejemplo n.º 7
0
        private Complex VoltageDrop()
        {
            if (!Positive.IsConnected() || !Negative.IsConnected())
            {
                return(new Complex());
            }

            var V = Positive.Node.Voltage - Negative.Node.Voltage;

            return(V - Voltage);
        }
Ejemplo n.º 8
0
        public void Positive_WithString2_ReturnsInteger2()
        {
            var variables  = MakeVariables();
            var operand    = new Constant("2");
            var expression = new Positive(operand);

            var actual = expression.GetExpression(variables)
                         .Calculate();

            Assert.AreEqual(2, actual);
        }
Ejemplo n.º 9
0
        public void Positive_WithDouble2_ReturnsDouble2()
        {
            var variables  = MakeVariables();
            var operand    = new Constant(2.0);
            var expression = new Positive(operand);

            var actual = expression.GetExpression(variables)
                         .Calculate();

            Assert.AreEqual(2.0, actual);
        }
Ejemplo n.º 10
0
        /// <summary>
        ///     Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        ///     A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode( )
        {
            int hash = 13;

            hash = (hash * 7) + Positive.GetHashCode( );
            hash = (hash * 7) + Hours.GetHashCode( );
            hash = (hash * 7) + Minutes.GetHashCode( );
            hash = (hash * 7) + Seconds.GetHashCode( );

            return(hash);
        }
Ejemplo n.º 11
0
    public override ReturnType Evaluate(Client client)
    {
        bool result = Test(client);

        if (result)
        {
            return(Positive.Evaluate(client));
        }
        else
        {
            return(Negative.Evaluate(client));
        }
    }
Ejemplo n.º 12
0
        private Complex OhmsLaw()
        {
            if (!Positive.IsConnected() || !Negative.IsConnected())
            {
                return(new Complex());
            }

            var V = Positive.Node.Voltage - Negative.Node.Voltage;
            var I = Positive.Current;
            var R = Resistance;

            return(V - R * I);
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        /// <summary>
        /// Evaluates the decision query
        /// </summary>
        /// <param name="input">The input</param>
        /// <returns>The output</returns>
        public override TOut Evaluate(TIn input)
        {
            AssertCanEvaluate();
            var result = GetResult(input);

            if (result)
            {
                return(Positive.Evaluate(input));
            }
            else
            {
                return(Negative.Evaluate(input));
            }
        }
Ejemplo n.º 14
0
        public async override Task <bool> Evaluate(Zahtjev z)
        {
            var l = await Test(z);

            listaUtakmica = new List <Utakmica>(l);
            if (l.Count > 0)
            {
                return(await Positive.Evaluate(z));
            }
            else
            {
                return(await Negative.Evaluate(z));
            }
        }
Ejemplo n.º 15
0
        public override ParkingRateCode Evaluate(Patron patron)
        {
            var result = Test(patron);

            Console.WriteLine("  - {0}? {1}", Title, result ? "yes" : "no");

            if (result == true)
            {
                return(Positive.Evaluate(patron));
            }
            else
            {
                return(Negative.Evaluate(patron));
            }
        }
Ejemplo n.º 16
0
            public override void Evaluate(Client client)
            {
                // Test a client using the primitive operation
                bool res = Test(client);

                Console.WriteLine("  - {0}? {1}", Title, res ? "yes" : "no");
                // Select a branch to follow
                if (res)
                {
                    Positive.Evaluate(client);
                }
                else
                {
                    Negative.Evaluate(client);
                }
            }
Ejemplo n.º 17
0
        /// <inheritdoc />
        public override DecisionResultWithPath <TOut> EvaluateWithPath(TIn input, DecisionPath decisionPath)
        {
            AssertCanEvaluate();

            var result = GetResult(input);

            decisionPath.AddStep(result);

            if (result)
            {
                return(Positive.EvaluateWithPath(input, decisionPath));
            }
            else
            {
                return(Negative.EvaluateWithPath(input, decisionPath));
            }
        }
Ejemplo n.º 18
0
        public static List <int> FindAllPositiveAnon(int[] mass, Positive pos)
        {
            if (mass == null || pos == null)
            {
                throw new ArgumentNullException();
            }
            List <int> result = new List <int>();

            for (int i = 0; i < mass.Length; i++)
            {
                if (pos(mass[i]))
                {
                    result.Add(mass[i]);
                }
            }
            return(result);
        }
Ejemplo n.º 19
0
 public string Visit(Positive node)
 {
     return("");
 }
Ejemplo n.º 20
0
 public FaceOff()
 {
     negative = new Negative();
     positive = new Positive();
 }
Ejemplo n.º 21
0
 public void Visit(Positive node)
 {
     VisitChildren(node);
 }
 public void CheckBinds(out bool pos, out bool neg)
 {
     pos = Positive.Axis(GamepadIndex, Threshold) > 0f;
     neg = Negative.Axis(GamepadIndex, Threshold) > 0f;
 }
Ejemplo n.º 23
0
    public static Int32 Parse(List<Token> src, Int32 begin, out Expr expr)
    {
        //expr = null;

        Int32 current;
        Int32 saved;

        if (Parser.IsKeyword(src[begin], KeywordVal.SIZEOF)) {
            // 1. sizeof
            current = begin + 1;

            // 1.1. try to match type_name
            saved = current;
            TypeName type_name;
            current = ParseTypeName(src, current, out type_name);
            if (current != -1) {
                // 1.1. -- successful match
                expr = new SizeofType(type_name);
                return current;
            }

            // 1.2. type_name match failed, try unary_expression
            current = saved;
            current = _unary_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            // 1.2. -- successful match
            expr = new SizeofExpr(expr);
            return current;

        } // sizeof

        // 2. postfix_expression
        current = _postfix_expression.Parse(src, begin, out expr);
        if (current != -1) {
            // successful match
            return current;
        }

        // now only operators are left
        if (src[begin].type != TokenType.OPERATOR) {
            return -1;
        }

        current = begin;
        OperatorVal val = ((TokenOperator)src[begin]).val;
        switch (val) {
        case OperatorVal.INC:
            // '++'
            current++;

            current = _unary_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new PreIncrement(expr);
            return current;

        case OperatorVal.DEC:
            // '--'
            current++;

            current = _unary_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new PreDecrement(expr);
            return current;

        case OperatorVal.BITAND:
            // '&' (reference)
            current++;

            current = _cast_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new Reference(expr);
            return current;

        case OperatorVal.MULT:
            // '*' (dereference)
            current++;

            current = _cast_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new Dereference(expr);
            return current;

        case OperatorVal.ADD:
            // '+' (positive)
            current++;

            current = _cast_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new Positive(expr);
            return current;

        case OperatorVal.SUB:
            // '-' (negative)
            current++;

            current = _cast_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new Negative(expr);
            return current;

        case OperatorVal.TILDE:
            // '~' (bitwise not)
            current++;

            current = _cast_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new BitwiseNot(expr);
            return current;

        case OperatorVal.NOT:
            // '!' (logical not)
            current++;

            current = _cast_expression.Parse(src, current, out expr);
            if (current == -1) {
                expr = null;
                return -1;
            }

            expr = new LogicalNot(expr);
            return current;

        default:

            // no match
            return -1;

        } // case (val)
    }
Ejemplo n.º 24
0
 public override string Evaluate()
 {
     return(Answer ? Positive.Evaluate() : Negative.Evaluate());
 }
Ejemplo n.º 25
0
        public Node ExpressionUnary()
        {
            bool hasModifier = false;
            var  modifier    = new Node();

            if (firstOfModifier.Contains(CurrentToken))
            {
                hasModifier = true;
                switch (CurrentToken)
                {
                case TokenType.SUM:
                    modifier = new Positive()
                    {
                        AnchorToken = Expect(TokenType.SUM)
                    };
                    break;

                case TokenType.NOT:
                    modifier = new Negative()
                    {
                        AnchorToken = Expect(TokenType.NOT)
                    };
                    break;

                case TokenType.SUB:
                    modifier = new Not()
                    {
                        AnchorToken = Expect(TokenType.SUB)
                    };
                    break;

                default:
                    break;
                }
            }
            switch (CurrentToken)
            {
            case TokenType.IDENTIFIER:
                var ret = ExpressionIdentifierOrFunctionCall();
                if (hasModifier)
                {
                    modifier.Add(ret);
                    ret = modifier;
                }
                return(ret);

            case TokenType.PARENTHESIS_OPEN:
                throw new SyntaxError(TokenType.PARENTHESIS_OPEN, tokenStream.Current);

            case TokenType.ARR_BEGIN:
                if (hasModifier)
                {
                    throw new SyntaxError(modifier.AnchorToken.Category, modifier.AnchorToken);
                }
                return(Array());

            case TokenType.VAR_CHAR:
            case TokenType.VAR_INT:
            case TokenType.VAR_STRING:
                var retu = Literal();
                if (hasModifier)
                {
                    modifier.Add(retu);
                    retu = modifier;
                }
                return(retu);

            case TokenType.TRUE:
                var tru = True();
                if (hasModifier)
                {
                    modifier.Add(tru);
                    tru = modifier;
                }
                return(tru);

            default:
                throw new SyntaxError(firstOfSimpleExpression, tokenStream.Current);
            }
        }
Ejemplo n.º 26
0
 public override TV Evaluate(T activity)
 {
     return(Test(activity) ? Positive.Evaluate(activity) : Negative.Evaluate(activity));
 }
Ejemplo n.º 27
0
        private IType Visit(Positive node)
        {
            IType operand = Visit((dynamic)node.Operand);

            return(operand.Positive());
        }
Ejemplo n.º 28
0
        static void Main()
        {
            int[]      massive = new int[] { -1, 2, 5, -3, 5, -6, -2, 7, 8 };
            List <int> result1 = new List <int>();
            List <int> result2 = new List <int>();
            List <int> result3 = new List <int>();
            List <int> result4 = new List <int>();

            result1 = FindAllPositive(massive);
            result2 = FindAllPositiveDelegate(massive, IsPositive);
            Console.WriteLine("Result for simple void:");
            foreach (var item in result1)
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine("");
            Console.WriteLine("Result for void delegate:");
            foreach (var item in result2)
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine("");
            Positive pos_anon = delegate(int a)
            {
                if (a > 0)
                {
                    return(true);
                }
                return(false);
            };

            result3 = FindAllPositiveAnon(massive, pos_anon);
            Console.WriteLine("Result for anon void:");
            foreach (var item in result3)
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine("");
            Positive pos_lambda = (a) =>
            {
                if (a > 0)
                {
                    return(true);
                }
                return(false);
            };

            result4 = FindAllPositiveAnon(massive, pos_lambda);
            Console.WriteLine("Result for lambda void:");
            foreach (var item in result4)
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine("");
            Console.WriteLine("Result for LINQ void:");
            foreach (var item in FindAllPositiveLinq(massive))
            {
                Console.Write("{0} ", item);
            }
            Console.WriteLine("");
        }
Ejemplo n.º 29
0
 protected override int GetHashCodeCore() => UserId.GetHashCode() + Positive.GetHashCode();
Ejemplo n.º 30
0
 protected override bool EqualsCore(Vote other)
 => UserId.Equals(other.UserId) && Positive.Equals(other.Positive);