Ejemplo n.º 1
0
        /**
         * Get a PTG for an integer from its string representation.
         * return Int or Number Ptg based on size of input
         */
        private static Ptg GetNumberPtgFromString(String number1, String number2, String exponent)
        {
            StringBuilder number = new StringBuilder();

            if (number2 == null)
            {
                number.Append(number1);

                if (exponent != null)
                {
                    number.Append('E');
                    number.Append(exponent);
                }

                String numberStr = number.ToString();
                int    intVal;
                try
                {
                    intVal = int.Parse(numberStr);
                }
                catch (Exception)
                {
                    return(new NumberPtg(numberStr));
                }
                if (IntPtg.IsInRange(intVal))
                {
                    return(new IntPtg(intVal));
                }
                return(new NumberPtg(numberStr));
            }

            if (number1 != null)
            {
                number.Append(number1);
            }

            number.Append('.');
            number.Append(number2);

            if (exponent != null)
            {
                number.Append('E');
                number.Append(exponent);
            }

            return(new NumberPtg(number.ToString()));
        }
Ejemplo n.º 2
0
        public void TestIfSingleCondition()
        {
            Ptg[] ptgs = ParseFormula("IF(1=1,10)");
            Assert.AreEqual(7, ptgs.Length);

            Assert.IsTrue((ptgs[3] is AttrPtg), "IF Attr Set correctly");
            AttrPtg ifFunc = (AttrPtg)ptgs[3];

            Assert.IsTrue(ifFunc.IsOptimizedIf, "It is1 not an if");

            Assert.IsTrue((ptgs[4] is IntPtg), "Single Value is1 not an IntPtg");
            IntPtg intPtg = (IntPtg)ptgs[4];

            Assert.AreEqual((short)10, intPtg.Value, "Result");

            Assert.IsTrue((ptgs[6] is FuncVarPtg), "Ptg is1 not a Variable Function");
            FuncVarPtg funcPtg = (FuncVarPtg)ptgs[6];

            Assert.AreEqual(2, funcPtg.NumberOfOperands, "Arguments");
        }