Esempio n. 1
0
        /**
         * When the second argument Is a string, many things are possible
         */
        private static I_MatchPredicate CreateGeneralMatchPredicate(StringEval stringEval)
        {
            String value = stringEval.StringValue;
            CmpOp  optr  = CmpOp.GetOperator(value);

            value = value.Substring(optr.Length);

            bool?boolVal = ParseBoolean(value);

            if (boolVal != null)
            {
                return(new BooleanMatcher(boolVal == true?true:false, optr));
            }


            Double doubleVal = OperandResolver.ParseDouble(value);

            if (!double.IsNaN(doubleVal))
            {
                return(new NumberMatcher(doubleVal, optr));
            }

            //else - just a plain string with no interpretation.
            return(new StringMatcher(value, optr));
        }
Esempio n. 2
0
        public void TestTextWithDeciamlFormatSecondArg()
        {
            ValueEval numArg    = new NumberEval(321321.321);
            ValueEval formatArg = new StringEval("#,###.00000");

            ValueEval[] args   = { numArg, formatArg };
            ValueEval   result = TextFunction.TEXT.Evaluate(args, -1, (short)-1);

            //char groupSeparator = new DecimalFormatSymbols(Locale.GetDefault()).GetGroupingSeparator();
            //char decimalSeparator = new DecimalFormatSymbols(Locale.GetDefault()).GetDecimalSeparator();

            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture;
            string groupSeparator   = ci.NumberFormat.NumberGroupSeparator;
            string decimalSeparator = ci.NumberFormat.NumberDecimalSeparator;;

            ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");

            Assert.AreEqual(testResult.ToString(), result.ToString());
            numArg     = new NumberEval(321.321);
            formatArg  = new StringEval("00000.00000");
            args[0]    = numArg;
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("00321" + decimalSeparator + "32100");
            Assert.AreEqual(testResult.ToString(), result.ToString());

            formatArg  = new StringEval("$#.#");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("$321" + decimalSeparator + "3");
            Assert.AreEqual(testResult.ToString(), result.ToString());
        }
Esempio n. 3
0
            public bool Matches(ValueEval x)
            {
                double testValue;

                if (x is StringEval)
                {
                    // if the tarGet(x) Is a string, but Parses as a number
                    // it may still Count as a match
                    StringEval se  = (StringEval)x;
                    double     val = OperandResolver.ParseDouble(se.StringValue);
                    if (double.IsNaN(val))
                    {
                        // x Is text that Is not a number
                        return(false);
                    }
                    testValue = val;
                }
                else if (x is NumberEval)
                {
                    NumberEval ne = (NumberEval)x;
                    testValue = ne.NumberValue;
                }
                else
                {
                    return(false);
                }
                return(_operator.Evaluate(testValue.CompareTo(_value)));
            }
Esempio n. 4
0
        public ActionResult Create(string word, string sentence)
        {
            StringEval stringEval = new StringEval(word, sentence);

            stringEval.StringCleaner();
            return(View("Show", stringEval));
        }
Esempio n. 5
0
        private static double EvaluateMatchTypeArg(ValueEval arg, int srcCellRow, int srcCellCol)
        {
            ValueEval match_type = OperandResolver.GetSingleValue(arg, srcCellRow, srcCellCol);

            if (match_type is ErrorEval)
            {
                throw new EvaluationException((ErrorEval)match_type);
            }
            if (match_type is NumericValueEval)
            {
                NumericValueEval ne = (NumericValueEval)match_type;
                return(ne.NumberValue);
            }
            if (match_type is StringEval)
            {
                StringEval se = (StringEval)match_type;
                double     d  = OperandResolver.ParseDouble(se.StringValue);
                if (double.IsNaN(d))
                {
                    // plain string
                    throw new EvaluationException(ErrorEval.VALUE_INVALID);
                }
                // if the string Parses as a number, it Is OK
                return(d);
            }
            throw new Exception("Unexpected match_type type (" + match_type.GetType().Name + ")");
        }
Esempio n. 6
0
            public override bool Matches(ValueEval x)
            {
                int testValue;

                if (x is StringEval)
                {
#if !HIDE_UNREACHABLE_CODE
                    if (true)
                    { // change to false to observe more intuitive behaviour
                        // Note - Unlike with numbers, it seems that COUNTIF never matches
                        // boolean values when the target(x) is a string
                        return(false);
                    }
                    StringEval se  = (StringEval)x;
                    Boolean?   val = ParseBoolean(se.StringValue);
                    if (val == null)
                    {
                        // x is text that is not a boolean
                        return(false);
                    }
                    testValue = BoolToInt(val.Value);
#else
                    return(false);
#endif
                }
                else if ((x is BoolEval))
                {
                    BoolEval be = (BoolEval)x;
                    testValue = BoolToInt(be.BooleanValue);
                }
                else if ((x is BlankEval))
                {
                    switch (Code)
                    {
                    case CmpOp.NE:
                        // Excel counts blank values in range as not equal to any value. See Bugzilla 51498
                        return(true);

                    default:
                        return(false);
                    }
                }
                else if ((x is NumberEval))
                {
                    switch (Code)
                    {
                    case CmpOp.NE:
                        // not-equals comparison of a number to boolean always returnes false
                        return(true);

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
                return(Evaluate(testValue - _value));
            }
Esempio n. 7
0
            public bool Matches(ValueEval x)
            {
                int testValue = 0;

                if (x is StringEval)
                {
                    if (true)
                    { // Change to false to observe more intuitive behaviour
                        // Note - Unlike with numbers, it seems that COUNTA never Matches
                        // bool values when the tarGet(x) Is a string
                        return(false);
                    }
                    StringEval se  = (StringEval)x;
                    bool?      val = ParseBoolean(se.StringValue);

                    if (val == null)
                    {
                        // x is text that is not a boolean
                        return(false);
                    }
                    testValue = BoolToInt(val);
                }
                else if (x is BoolEval)
                {
                    BoolEval be = (BoolEval)x;
                    testValue = BoolToInt(be.BooleanValue);
                }
                else
                {
                    return(false);
                }
                return(_operator.Evaluate(testValue - _value));
            }
Esempio n. 8
0
        private void checkProper(String input, String expected)
        {
            ValueEval strArg = new StringEval(input);
            ValueEval ret    = TextFunction.PROPER.Evaluate(new ValueEval[] { strArg }, 0, 0);

            Assert.AreEqual(expected, ((StringEval)ret).StringValue);
        }
Esempio n. 9
0
        private static double EvaluateDoubleArg(ValueEval eval, int srcCellRow, int srcCellCol)
        {
            ValueEval ve = OperandResolver.GetSingleValue(eval, srcCellRow, srcCellCol);

            if (ve is NumericValueEval)
            {
                return(((NumericValueEval)ve).NumberValue);
            }
            if (ve is StringEval)
            {
                StringEval se = (StringEval)ve;
                double     d  = OperandResolver.ParseDouble(se.StringValue);
                if (double.IsNaN(d))
                {
                    throw new EvalEx(ErrorEval.VALUE_INVALID);
                }
                return(d);
            }
            if (ve is BoolEval)
            {
                // in the context of OFFSet, bools resolve to 0 and 1.
                if (((BoolEval)ve).BooleanValue)
                {
                    return(1);
                }
                return(0);
            }
            throw new Exception("Unexpected eval type (" + ve.GetType().Name + ")");
        }
Esempio n. 10
0
        /**
         * When the second argument is a string, many things are possible
         */
        private static IMatchPredicate CreateGeneralMatchPredicate(StringEval stringEval)
        {
            String value     = stringEval.StringValue;
            CmpOp  operator1 = CmpOp.GetOperator(value);

            value = value.Substring(operator1.Length);

            bool?booleanVal = ParseBoolean(value);

            if (booleanVal != null)
            {
                return(new BooleanMatcher(booleanVal.Value, operator1));
            }

            Double doubleVal = OperandResolver.ParseDouble(value);

            if (!double.IsNaN(doubleVal))
            {
                return(new NumberMatcher(doubleVal, operator1));
            }
            ErrorEval ee = ParseError(value);

            if (ee != null)
            {
                return(new ErrorMatcher(ee.ErrorCode, operator1));
            }

            //else - just a plain string with no interpretation.
            return(new StringMatcher(value, operator1));
        }
Esempio n. 11
0
        /**
         * Returns a CellValue wrapper around the supplied ValueEval instance.
         */
        protected override CellValue EvaluateFormulaCellValue(ICell cell)
        {
            IEvaluationCell evalCell = ToEvaluationCell(cell);
            ValueEval       eval     = _bookEvaluator.Evaluate(evalCell);

            if (eval is NumberEval)
            {
                NumberEval ne = (NumberEval)eval;
                return(new CellValue(ne.NumberValue));
            }
            if (eval is BoolEval)
            {
                BoolEval be = (BoolEval)eval;
                return(CellValue.ValueOf(be.BooleanValue));
            }
            if (eval is StringEval)
            {
                StringEval ne = (StringEval)eval;
                return(new CellValue(ne.StringValue));
            }
            if (eval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)eval).ErrorCode));
            }
            throw new Exception("Unexpected eval class (" + eval.GetType().Name + ")");
        }
Esempio n. 12
0
 private String FormatValue(Object value)
 {
     if (value is Ptg[])
     {
         Ptg[] ptgs = (Ptg[])value;
         return(HSSFFormulaParser.ToFormulaString(_book, ptgs));
     }
     if (value is NumberEval)
     {
         NumberEval ne = (NumberEval)value;
         return(ne.StringValue);
     }
     if (value is StringEval)
     {
         StringEval se = (StringEval)value;
         return("'" + se.StringValue + "'");
     }
     if (value is BoolEval)
     {
         BoolEval be = (BoolEval)value;
         return(be.StringValue);
     }
     if (value == BlankEval.instance)
     {
         return("#BLANK#");
     }
     if (value is ErrorEval)
     {
         ErrorEval ee = (ErrorEval)value;
         return(ErrorEval.GetText(ee.ErrorCode));
     }
     throw new ArgumentException("Unexpected value class ("
                                 + value.GetType().Name + ")");
 }
Esempio n. 13
0
        /**
         * Returns a CellValue wrapper around the supplied ValueEval instance.
         */
        private CellValue EvaluateFormulaCellValue(ICell cell)
        {
            if (!(cell is XSSFCell))
            {
                throw new ArgumentException("Unexpected type of cell: " + cell.GetType() + "." +
                                            " Only XSSFCells can be Evaluated.");
            }

            ValueEval eval = _bookEvaluator.Evaluate(new XSSFEvaluationCell((XSSFCell)cell));

            if (eval is NumberEval)
            {
                NumberEval ne = (NumberEval)eval;
                return(new CellValue(ne.NumberValue));
            }
            if (eval is BoolEval)
            {
                BoolEval be = (BoolEval)eval;
                return(CellValue.ValueOf(be.BooleanValue));
            }
            if (eval is StringEval)
            {
                StringEval ne = (StringEval)eval;
                return(new CellValue(ne.StringValue));
            }
            if (eval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)eval).ErrorCode));
            }
            throw new Exception("Unexpected eval class (" + eval.GetType().Name + ")");
        }
Esempio n. 14
0
        /**
         * Returns a CellValue wrapper around the supplied ValueEval instance.
         * @param eval
         */
        private CellValue EvaluateFormulaCellValue(ICell cell)
        {
            ValueEval eval = _bookEvaluator.Evaluate(new HSSFEvaluationCell((HSSFCell)cell));

            if (eval is NumberEval)
            {
                NumberEval ne = (NumberEval)eval;
                return(new CellValue(ne.NumberValue));
            }
            if (eval is BoolEval)
            {
                BoolEval be = (BoolEval)eval;
                return(CellValue.ValueOf(be.BooleanValue));
            }
            if (eval is StringEval)
            {
                StringEval ne = (StringEval)eval;
                return(new CellValue(ne.StringValue));
            }
            if (eval is ErrorEval)
            {
                return(CellValue.GetError(((ErrorEval)eval).ErrorCode));
            }
            throw new InvalidOperationException("Unexpected eval class (" + eval.GetType().Name + ")");
        }
Esempio n. 15
0
 public StringLookupComparer(StringEval se, bool matchExact, bool isMatchFunction)
     : base(se)
 {
     _value           = se.StringValue;
     _wildCardPattern = Countif.StringMatcher.GetWildCardPattern(_value);
     _matchExact      = matchExact;
     _isMatchFunction = isMatchFunction;
 }
Esempio n. 16
0
        private static void ConfirmText(String text)
        {
            ValueEval  arg  = new StringEval(text);
            ValueEval  eval = invokeT(arg);
            StringEval se   = (StringEval)eval;

            Assert.AreEqual(text, se.StringValue);
        }
Esempio n. 17
0
        /**
         * Uses {@link ConcatEval} to force number-to-text conversion
         */
        private static void ConfirmTextRendering(String expRendering, double d)
        {
            ValueEval[] args   = { StringEval.EMPTY_INSTANCE, new NumberEval(d), };
            StringEval  se     = (StringEval)EvalInstances.Concat.Evaluate(args, -1, (short)-1);
            String      result = se.StringValue;

            Assert.AreEqual(expRendering, result);
        }
Esempio n. 18
0
        public void StringEval_IsEqualToItself_True()
        {
            // Arrange
            // Act
            StringEval newStringEval = new StringEval("word", "");

            // Assert
            Assert.AreEqual(typeof(StringEval), newStringEval.GetType());
        }
Esempio n. 19
0
        public void TestTRuncWithStringArg()
        {
            ValueEval strArg = new StringEval("abc");

            ValueEval[] args   = { strArg, new NumberEval(2) };
            ValueEval   result = NumericFunction.TRUNC.Evaluate(args, -1, (short)-1);

            Assert.AreEqual(ErrorEval.VALUE_INVALID, result);
        }
Esempio n. 20
0
        public void TestRoundupWithStringArg()
        {
            ValueEval strArg = new StringEval("abc");

            ValueEval[] args   = { strArg, new NumberEval(2), };
            ValueEval   result = new Roundup().Evaluate(args, -1, (short)-1);

            Assert.AreEqual(ErrorEval.VALUE_INVALID, result);
        }
Esempio n. 21
0
            public override bool Matches(ValueEval x)
            {
                double testValue;

                if (x is StringEval)
                {
                    // if the target(x) is a string, but parses as a number
                    // it may still count as a match, only for the equality operator
                    switch (Code)
                    {
                    case CmpOp.EQ:
                    case CmpOp.NONE:
                        break;

                    case CmpOp.NE:
                        // Always matches (inconsistent with above two cases).
                        // for example '<>123' matches '123', '4', 'abc', etc
                        return(true);

                    default:
                        // never matches (also inconsistent with above three cases).
                        // for example '>5' does not match '6',
                        return(false);
                    }
                    StringEval se  = (StringEval)x;
                    Double     val = OperandResolver.ParseDouble(se.StringValue);
                    if (double.IsNaN(val))
                    {
                        // x is text that is not a number
                        return(false);
                    }
                    return(_value == val);
                }
                else if ((x is NumberEval))
                {
                    NumberEval ne = (NumberEval)x;
                    testValue = ne.NumberValue;
                }
                else if ((x is BlankEval))
                {
                    switch (Code)
                    {
                    case CmpOp.NE:
                        // Excel counts blank values in range as not equal to any value. See Bugzilla 51498
                        return(true);

                    default:
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
                return(Evaluate(testValue.CompareTo(_value)));
            }
Esempio n. 22
0
        public void TestCriteriaPredicateNe_Bug46647()
        {
            IMatchPredicate mp = Countif.CreateCriteriaPredicate(new StringEval("<>aa"), 0, 0);

            Assert.IsNotNull(mp);
            StringEval seA = new StringEval("aa"); // this should not match the criteria '<>aa'
            StringEval seB = new StringEval("bb"); // this should match

            if (mp.Matches(seA) && !mp.Matches(seB))
            {
                throw new AssertionException("Identified bug 46647");
            }
            Assert.IsFalse(mp.Matches(seA));
            Assert.IsTrue(mp.Matches(seB));

            // general Tests for not-equal (<>) operator
            AreaEval range;

            ValueEval[] values;

            values = new ValueEval[] {
                new StringEval("aa"),
                new StringEval("def"),
                new StringEval("aa"),
                new StringEval("ghi"),
                new StringEval("aa"),
                new StringEval("aa"),
            };

            range = EvalFactory.CreateAreaEval("A1:A6", values);
            ConfirmCountIf(2, range, new StringEval("<>aa"));

            values = new ValueEval[] {
                new StringEval("ab"),
                new StringEval("aabb"),
                new StringEval("aa"),                 // match
                new StringEval("abb"),
                new StringEval("aab"),
                new StringEval("ba"),                 // match
            };

            range = EvalFactory.CreateAreaEval("A1:A6", values);
            ConfirmCountIf(2, range, new StringEval("<>a*b"));


            values = new ValueEval[] {
                new NumberEval(222),
                new NumberEval(222),
                new NumberEval(111),
                new StringEval("aa"),
                new StringEval("111"),
            };

            range = EvalFactory.CreateAreaEval("A1:A5", values);
            ConfirmCountIf(4, range, new StringEval("<>111"));
        }
Esempio n. 23
0
        public void TestTextWithStringFirstArg()
        {
            ValueEval strArg    = new StringEval("abc");
            ValueEval formatArg = new StringEval("abc");

            ValueEval[] args   = { strArg, formatArg };
            ValueEval   result = TextFunction.TEXT.Evaluate(args, -1, (short)-1);

            Assert.AreEqual(ErrorEval.VALUE_INVALID, result);
        }
Esempio n. 24
0
        public void StringEval_CanEvaulateStringMatch_True()
        {
            // Arrange
            StringEval newStringEval = new StringEval("word", "");
            // Act
            string result = newStringEval.Word;

            // Assert
            Assert.AreEqual("word", result);
        }
Esempio n. 25
0
        public void IsStringInField_CanEvaulateStringMatchInField_True()
        {
            // Arrange
            StringEval newStringEval = new StringEval("word", "there is a word in here");
            // Act
            bool doesContain = newStringEval.IsStringInField();

            // Assert
            Assert.AreEqual(true, doesContain);
        }
Esempio n. 26
0
        public void RepeatCounter_TallySpecificWordInstances_Int()
        {
            // Arrange
            StringEval newStringEval = new StringEval("word", "this sentence uses a word thing or two");

            // Act

            // Assert
            Assert.AreEqual(1, newStringEval.RepeatCounter());
        }
Esempio n. 27
0
        public void StringCleaner_RemovesPunctuation_True()
        {
            // Arrange
            StringEval newStringEval = new StringEval("word", "this sentence uses a word, or two");

            // Act
            Assert.AreEqual("this sentence uses a word or two", newStringEval.StringCleaner());
            // Assert
            Assert.AreEqual(1, newStringEval.RepeatCounter());
        }
Esempio n. 28
0
            public ValueEval Evaluate(ValueEval[] args, OperationEvaluationContext ec)
            {
                if (args.Length != 1 || !(args[0] is StringEval))
                {
                    return(ErrorEval.VALUE_INVALID);
                }
                StringEval input = (StringEval)args[0];

                return(new StringEval(input.StringValue + "abc2"));
            }
Esempio n. 29
0
        public void TestReturnWorkdaysWhenStartIsWeekendSubtractingDays()
        {
            String     startDate       = "2013/10/06";
            int        days            = -1;
            String     expectedWorkDay = "2013/10/04";
            StringEval stringEval      = new StringEval(startDate);
            double     numberValue     = ((NumberEval)WorkdayFunction.instance.Evaluate(new ValueEval[] {
                stringEval, new NumberEval(days)
            }, EC)).NumberValue;

            Assert.AreEqual(expectedWorkDay, formatter.Format(DateUtil.GetJavaDate(numberValue)));
        }
Esempio n. 30
0
        public void TestReturnWorkdaysSpanningAWeekendAddingDays()
        {
            String     startDate       = "2013/09/27";
            int        days            = 1;
            String     expectedWorkDay = "2013/09/30";
            StringEval stringEval      = new StringEval(startDate);
            double     numberValue     = ((NumberEval)WorkdayFunction.instance.Evaluate(new ValueEval[] {
                stringEval, new NumberEval(days)
            }, EC)).NumberValue;

            Assert.AreEqual(expectedWorkDay, formatter.Format(DateUtil.GetJavaDate(numberValue)));
        }