⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evaluatorfactorytest.java

📁 jboss规则引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                {new Double( 42 ), ">=", new Double( 41 ), Boolean.TRUE}, 
                {new Double( 42 ), ">=", new Double( 42 ), Boolean.TRUE},
                {new Double( 42 ), ">=", new Double( 100 ), Boolean.FALSE}, 
                {new Double( 42 ), "<", new Double( 1 ), Boolean.FALSE}, 
                {new Double( 42 ), "==", null, Boolean.FALSE}, 
                {new Double( 42 ), "!=", null, Boolean.TRUE}, 
                {null, "==", null, Boolean.TRUE}, 
                {null, "==", new Double( 42 ), Boolean.FALSE},
                {null, "!=", null, Boolean.FALSE}, 
                {null, "!=", new Double( 42 ), Boolean.TRUE}};

        runEvaluatorTest( data,
                          Evaluator.DOUBLE_TYPE );
    }

    public void testFloat() {
        final Object[][] data = {
                {new Float( 42 ), "==", new Float( 42 ), Boolean.TRUE}, 
                {new Float( 42 ), "<", new Float( 43 ), Boolean.TRUE}, 
                {new Float( 42 ), ">=", new Float( 41 ), Boolean.TRUE},
                {new Float( 42 ), "!=", new Float( 41 ), Boolean.TRUE}, 
                {new Float( 42 ), ">", new Float( 41 ), Boolean.TRUE}, 
                {new Float( 42 ), ">=", new Float( 41 ), Boolean.TRUE}, 
                {new Float( 42 ), ">=", new Float( 42 ), Boolean.TRUE},
                {new Float( 42 ), ">=", new Float( 100 ), Boolean.FALSE}, 
                {new Float( 42 ), "<", new Float( 1 ), Boolean.FALSE}, 
                {new Float( 42 ), "==", null, Boolean.FALSE}, 
                {new Float( 42 ), "!=", null, Boolean.TRUE}, 
                {null, "==", null, Boolean.TRUE}, 
                {null, "==", new Float( 42 ), Boolean.FALSE},
                {null, "!=", null, Boolean.FALSE}, 
                {null, "!=", new Float( 42 ), Boolean.TRUE}};

        runEvaluatorTest( data,
                          Evaluator.FLOAT_TYPE );
    }

    public void testLong() {
        final Object[][] data = {
                {new Long( 42 ), "==", new Long( 42 ), Boolean.TRUE}, 
                {new Long( 42 ), "<", new Long( 43 ), Boolean.TRUE}, 
                {new Long( 42 ), ">=", new Long( 41 ), Boolean.TRUE}, 
                {new Long( 42 ), "!=", new Long( 41 ), Boolean.TRUE},
                {new Long( 42 ), ">", new Long( 41 ), Boolean.TRUE}, 
                {new Long( 42 ), ">=", new Long( 41 ), Boolean.TRUE}, 
                {new Long( 42 ), ">=", new Long( 42 ), Boolean.TRUE}, 
                {new Long( 42 ), ">=", new Long( 100 ), Boolean.FALSE},
                {new Long( 42 ), "<", new Long( 1 ), Boolean.FALSE},
                {new Long( 42 ), "==", null, Boolean.FALSE}, 
                {new Long( 42 ), "!=", null, Boolean.TRUE}, 
                {null, "==", null, Boolean.TRUE}, 
                {null, "==", new Long( 42 ), Boolean.FALSE},
                {null, "!=", null, Boolean.FALSE}, 
                {null, "!=", new Long( 42 ), Boolean.TRUE}};

        runEvaluatorTest( data,
                          Evaluator.LONG_TYPE );
    }

    public void testCharacter() {
        final Object[][] data = {
                {new Character( 'a' ), "==", new Character( 'a' ), Boolean.TRUE}, 
                {new Character( 'a' ), "<", new Character( 'b' ), Boolean.TRUE}, 
                {new Character( 'a' ), ">=", new Character( 'a' ), Boolean.TRUE},
                {new Character( 'a' ), "!=", new Character( 'Z' ), Boolean.TRUE}, 
                {new Character( 'z' ), ">", new Character( 'a' ), Boolean.TRUE}, 
                {new Character( 'z' ), ">=", new Character( 'z' ), Boolean.TRUE},
                {new Character( 'z' ), ">=", new Character( 'a' ), Boolean.TRUE}, 
                {new Character( 'a' ), ">=", new Character( 'z' ), Boolean.FALSE}, 
                {new Character( 'z' ), "<", new Character( 'a' ), Boolean.FALSE},
                {new Character( 'z' ), "==", null, Boolean.FALSE}, 
                {new Character( 'z' ), "!=", null, Boolean.TRUE}, 
                {null, "==", null, Boolean.TRUE}, 
                {null, "==", new Character( 'z' ), Boolean.FALSE},
                {null, "!=", null, Boolean.FALSE}, 
                {null, "!=", new Character( 'z' ), Boolean.TRUE}};
        runEvaluatorTest( data,
                          Evaluator.CHAR_TYPE );
    }

    public void testDate() throws Exception {

        final SimpleDateFormat df = new SimpleDateFormat( "dd-MMM-yyyy",
                                                          Locale.ENGLISH );

        //note that strings are also allowed on the right
        final Object[][] data = {
                {df.parse( "10-Jul-1974" ), "==", df.parse( "10-Jul-1974" ), Boolean.TRUE}, 
                {df.parse( "10-Jul-1974" ), "<", df.parse( "11-Jul-1974" ), Boolean.TRUE},
                {df.parse( "10-Jul-1974" ), ">=", df.parse( "10-Jul-1974" ), Boolean.TRUE}, 
                {df.parse( "10-Jul-1974" ), "!=", df.parse( "11-Jul-1974" ), Boolean.TRUE}, 
                {df.parse( "10-Jul-2000" ), ">", df.parse( "10-Jul-1974" ), Boolean.TRUE},
                {df.parse( "10-Jul-1974" ), ">=", df.parse( "10-Jul-1974" ), Boolean.TRUE}, 
                {df.parse( "11-Jul-1974" ), ">=", df.parse( "10-Jul-1974" ), Boolean.TRUE}, 
                {df.parse( "10-Jul-1974" ), ">=", df.parse( "11-Jul-1974" ), Boolean.FALSE},
                {df.parse( "10-Jul-2000" ), "<", df.parse( "10-Jul-1974" ), Boolean.FALSE}, 
                {df.parse( "10-Jul-1974" ), "<", "11-Jul-1974", Boolean.TRUE}, 
                {df.parse( "10-Jul-1974" ), ">=", "10-Jul-1974", Boolean.TRUE},
                {df.parse( "10-Jul-1974" ), "!=", "11-Jul-1974", Boolean.TRUE}, 
                {df.parse( "10-Jul-2000" ), ">", "10-Jul-1974", Boolean.TRUE}, 
                {df.parse( "10-Jul-1974" ), ">=", "10-Jul-1974", Boolean.TRUE},
                {df.parse( "11-Jul-1974" ), ">=", "10-Jul-1974", Boolean.TRUE}, 
                {df.parse( "10-Jul-1974" ), ">=", "11-Jul-1974", Boolean.FALSE}, 
                {df.parse( "10-Jul-1974" ), "==", null, Boolean.FALSE}, 
                {df.parse( "10-Jul-1974" ), "!=", null, Boolean.TRUE}, 
                {null, "==", null, Boolean.TRUE}, 
                {null, "==", df.parse( "10-Jul-1974" ), Boolean.FALSE},
                {null, "!=", null, Boolean.FALSE}, 
                {null, "!=", df.parse( "10-Jul-1974" ), Boolean.TRUE}};
        runEvaluatorTest( data,
                          Evaluator.DATE_TYPE );
    }

    public void testByte() {
        final Object[][] data = {
                {new Byte( "1" ), "==", new Byte( "1" ), Boolean.TRUE}, 
                {new Byte( "1" ), "==", new Byte( "2" ), Boolean.FALSE}, 
                {new Byte( "1" ), "!=", new Byte( "2" ), Boolean.TRUE},
                {new Byte( "1" ), "!=", new Byte( "1" ), Boolean.FALSE}, 
                {new Byte( "1" ), "<=", new Byte( "1" ), Boolean.TRUE}, 
                {new Byte( "1" ), "==", null, Boolean.FALSE}, 
                {new Byte( "1" ), "!=", null, Boolean.TRUE}, 
                {null, "==", null, Boolean.TRUE}, 
                {null, "==", new Byte( "1" ), Boolean.FALSE},
                {null, "!=", null, Boolean.FALSE}, 
                {null, "!=", new Byte( "1" ), Boolean.TRUE}};
        runEvaluatorTest( data,
                          Evaluator.BYTE_TYPE );

    }

    /**
     * Test utility to play the data through the evaluators.
     * @param data The data to try out : Array of {arg1, operator, arg2}
     * @param evalType The Evaluator.**_TYPE to test
     */
    private void runEvaluatorTest(final Object[][] data,
                                  final int evalType) {
        for ( int i = 0; i < data.length; i++ ) {
            final Object[] row = data[i];
            final Evaluator evaluator = EvaluatorFactory.getEvaluator( evalType,
                                                                       (String) row[1] );
            final boolean result = evaluator.evaluate( row[0],
                                                       row[2] );
            final String message = "The evaluator type: [" + evalType + "] incorrectly returned " + result + " for [" + row[0] + " " + row[1] + " " + row[2] + "]. It was asserted to return " + row[3];

            if ( row[3] == Boolean.TRUE ) {
                assertTrue( message,
                            result );
            } else {
                assertFalse( message,
                             result );
            }

            assertEquals( evalType,
                          evaluator.getType() );

        }
    }

    //    public void testRegexFoo() {
    //        Pattern p = Pattern.compile( ".*foo" );
    //        boolean b;
    //        long start = System.currentTimeMillis();
    //        for (int i = 0; i < 1000000; i++) {
    //            b = ("something foo".matches( ".*foo" ));
    //        }
    //        System.out.println("time: " + (System.currentTimeMillis() - start));
    //        
    //        start = System.currentTimeMillis();
    //        for (int i = 0; i < 1000000; i++) {        
    //            Matcher m = p.matcher( "something foo" );
    //            b = m.matches();
    //        }
    //        System.out.println("time: " + (System.currentTimeMillis() - start));
    //    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -