Best junit code snippet using junit.framework.Assert.assertTrue
Source:TestOdbcTypes.java  
...41import org.junit.Ignore;42import org.junit.Test;43import static junit.framework.Assert.assertEquals;44import static junit.framework.Assert.assertFalse;45import static junit.framework.Assert.assertTrue;46/**47 * See TestOdbcBase for more general ODBC test information.48 *49 * This class has been converted to JUnit 4.10.50 * Test runs are faster than the JUnit 3.x original with one-time-per-class51 * setUp and tearDown (fredt@users).52 * <p>53 *54 * @author Blaine Simpson (blaine dot simpson at admc dot com)55 * @since 1.9.056 * @see TestOdbcBase57 */58public class TestOdbcTypes extends TestOdbcBase {59    /* HyperSQL types to be tested:60     *61     * Exact Numeric62     *     TINYINT63     *     SMALLINT64     *     INTEGER65     *     BIGINT66     *     NUMERIC(p?,s?) = DECIMAL()   (default for decimal literals)67     * Approximate Numeric68     *     FLOAT(p?)69     *     DOUBLE = REAL (default for literals with exponent)70     * BOOLEAN71     * Character Strings72     *     CHARACTER(1l)* = CHAR()73     *     CHARACTER VARYING(1l) = VARCHAR() = LONGVARCHAR()74     *     CLOB(1l) = CHARACTER LARGE OBJECT(1)75     * Binary Strings76     *     BINARY(1l)*77     *     BINARY VARYING(1l) = VARBINARY()78     *     BLOB(1l) = BINARY LARGE OBJECT()79     * Bits80     *     BIT(1l)81     *     BIT VARYING(1l)82     * OTHER  (for holding serialized Java objects)83     * Date/Times84     *     DATE85     *     TIME(p?,p?)86     *     TIMESTAMP(p?,p?)87     *     INTERVAL...(p2,p0)88     */89    public TestOdbcTypes() {}90    @BeforeClass91    public static void setUpForTests() {92        setUpServer();93    }94    @AfterClass95    public static void tearDownClass() throws SQLException {96        tearDownServer();97    }98    @Before99    public void setUp() throws Exception {100        super.setUp();101    }102    protected void populate(Statement st) throws SQLException {103        st.executeUpdate("DROP TABLE alltypes IF EXISTS");104        st.executeUpdate("CREATE TABLE alltypes (\n" + "    id INTEGER,\n"105                         + "    ti TINYINT,\n" + "    si SMALLINT,\n"106                         + "    i INTEGER,\n" + "    bi BIGINT,\n"107                         + "    n NUMERIC(5,2),\n" + "    f FLOAT(5),\n"108                         + "    r DOUBLE,\n" + "    b BOOLEAN,\n"109                         + "    c CHARACTER(3),\n"110                         + "    cv CHARACTER VARYING(3),\n"111                         + "    bt BIT(9),\n" + "    btv BIT VARYING(3),\n"112                         + "    d DATE,\n" + "    t TIME(2),\n"113                         + "    tw TIME(2) WITH TIME ZONE,\n"114                         + "    ts TIMESTAMP(2),\n"115                         + "    tsw TIMESTAMP(2) WITH TIME ZONE,\n"116                         + "    bin BINARY(4),\n" + "    vb VARBINARY(4),\n"117                         + "    dsival INTERVAL DAY(5) TO SECOND(6),\n"118                         + "    sival INTERVAL SECOND(6,4)\n" + ')');119        // Would be more elegant and efficient to use a prepared statement120        // here, but our we want this setup to be as simple as possible, and121        // leave feature testing for the actual unit tests.122        st.executeUpdate(123            "INSERT INTO alltypes VALUES (\n"124            + "    1, 3, 4, 5, 6, 7.8, 8.9, 9.7, true, 'ab', 'cd',\n"125            + "    b'10', b'10', current_date, '13:14:00',\n"126            + "    '15:16:00', '2009-02-09 16:17:18', '2009-02-09 17:18:19',\n"127            + "    x'A103', x'A103', "128            + "INTERVAL '145 23:12:19.345' DAY TO SECOND,\n"129            + "    INTERVAL '1000.345' SECOND\n" + ')');130        st.executeUpdate(131            "INSERT INTO alltypes VALUES (\n"132            + "    2, 3, 4, 5, 6, 7.8, 8.9, 9.7, true, 'ab', 'cd',\n"133            + "    b'10', b'10', current_date, '13:14:00',\n"134            + "    '15:16:00', '2009-02-09 16:17:18', '2009-02-09 17:18:19',\n"135            + "    x'A103', x'A103', "136            + "    INTERVAL '145 23:12:19.345' DAY TO SECOND,\n"137            + "    INTERVAL '1000.345' SECOND\n" + ')');138    }139    @Test140    public void testIntegerSimpleRead() {141        ResultSet rs = null;142        Statement st = null;143        try {144            st = netConn.createStatement();145            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");146            assertTrue("Got no rows with id in (1, 2)", rs.next());147            assertEquals(Integer.class, rs.getObject("i").getClass());148            assertTrue("Got only one row with id in (1, 2)", rs.next());149            assertEquals(5, rs.getInt("i"));150            assertFalse("Got too many rows with id in (1, 2)", rs.next());151        } catch (SQLException se) {152            junit.framework.AssertionFailedError ase =153                new junit.framework.AssertionFailedError(se.getMessage());154            ase.initCause(se);155            throw ase;156        } finally {157            try {158                if (rs != null) {159                    rs.close();160                }161                if (st != null) {162                    st.close();163                }164            } catch (Exception ignored) {}165        }166    }167    @Test168    public void testTinyIntSimpleRead() {169        ResultSet rs = null;170        Statement st = null;171        try {172            st = netConn.createStatement();173            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");174            assertTrue("Got no rows with id in (1, 2)", rs.next());175            Object o = rs.getObject("ti"); // todo - returns string176            // assertEquals(Integer.class, rs.getObject("ti").getClass());177            // Nb. HyperSQL purposefully returns an Integer for this type178            assertTrue("Got only one row with id in (1, 2)", rs.next());179            assertEquals((byte) 3, rs.getByte("ti"));180            assertFalse("Got too many rows with id in (1, 2)", rs.next());181        } catch (SQLException se) {182            junit.framework.AssertionFailedError ase =183                new junit.framework.AssertionFailedError(se.getMessage());184            ase.initCause(se);185            throw ase;186        } finally {187            try {188                if (rs != null) {189                    rs.close();190                }191                if (st != null) {192                    st.close();193                }194            } catch (Exception ignored) {}195        }196    }197    @Test198    public void testSmallIntSimpleRead() {199        ResultSet rs = null;200        Statement st = null;201        try {202            st = netConn.createStatement();203            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");204            assertTrue("Got no rows with id in (1, 2)", rs.next());205            assertEquals(Integer.class, rs.getObject("si").getClass());206            // Nb. HyperSQL purposefully returns an Integer for this type207            assertTrue("Got only one row with id in (1, 2)", rs.next());208            assertEquals((short) 4, rs.getShort("si"));209            assertFalse("Got too many rows with id in (1, 2)", rs.next());210        } catch (SQLException se) {211            junit.framework.AssertionFailedError ase =212                new junit.framework.AssertionFailedError(se.getMessage());213            ase.initCause(se);214            throw ase;215        } finally {216            try {217                if (rs != null) {218                    rs.close();219                }220                if (st != null) {221                    st.close();222                }223            } catch (Exception ignored) {}224        }225    }226    @Test227    public void testBigIntSimpleRead() {228        ResultSet rs = null;229        Statement st = null;230        try {231            st = netConn.createStatement();232            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");233            assertTrue("Got no rows with id in (1, 2)", rs.next());234            assertEquals(Long.class, rs.getObject("bi").getClass());235            assertTrue("Got only one row with id in (1, 2)", rs.next());236            assertEquals(6, rs.getLong("bi"));237            assertFalse("Got too many rows with id in (1, 2)", rs.next());238        } catch (SQLException se) {239            junit.framework.AssertionFailedError ase =240                new junit.framework.AssertionFailedError(se.getMessage());241            ase.initCause(se);242            throw ase;243        } finally {244            try {245                if (rs != null) {246                    rs.close();247                }248                if (st != null) {249                    st.close();250                }251            } catch (Exception ignored) {}252        }253    }254    @Test255    public void testNumericSimpleRead() {256        // This is failing.257        // Looks like we inherited a real bug with numerics from psqlodbc,258        // because the problem exists with Postresql-supplied psqlodbc259        // connecting to a Postgresql server.260        ResultSet rs = null;261        Statement st = null;262        try {263            st = netConn.createStatement();264            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");265            assertTrue("Got no rows with id in (1, 2)", rs.next());266            Object o = rs.getObject("n");267            assertEquals(BigDecimal.class, o.getClass());268            assertTrue("Got only one row with id in (1, 2)", rs.next());269            o = rs.getBigDecimal("n"); // todo - wrong result270            BigDecimal expected = new BigDecimal("7.80");271            assertEquals(expected, o);272            assertFalse("Got too many rows with id in (1, 2)", rs.next());273        } catch (SQLException se) {274            junit.framework.AssertionFailedError ase275                = new junit.framework.AssertionFailedError(se.getMessage());276            ase.initCause(se);277            throw ase;278        } finally {279            try {280                if (rs != null) {281                    rs.close();282                }283                if (st != null) {284                    st.close();285                }286            } catch(Exception ignored) {287            }288        }289    }290    @Test291    public void testFloatSimpleRead() {292        ResultSet rs = null;293        Statement st = null;294        try {295            st = netConn.createStatement();296            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");297            assertTrue("Got no rows with id in (1, 2)", rs.next());298            assertEquals(Double.class, rs.getObject("f").getClass());299            assertTrue("Got only one row with id in (1, 2)", rs.next());300            assertEquals(8.9D, rs.getDouble("f"), 0D);301            assertFalse("Got too many rows with id in (1, 2)", rs.next());302        } catch (SQLException se) {303            junit.framework.AssertionFailedError ase =304                new junit.framework.AssertionFailedError(se.getMessage());305            ase.initCause(se);306            throw ase;307        } finally {308            try {309                if (rs != null) {310                    rs.close();311                }312                if (st != null) {313                    st.close();314                }315            } catch (Exception ignored) {}316        }317    }318    @Test319    public void testDoubleSimpleRead() {320        ResultSet rs = null;321        Statement st = null;322        try {323            st = netConn.createStatement();324            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");325            assertTrue("Got no rows with id in (1, 2)", rs.next());326            assertEquals(Double.class, rs.getObject("r").getClass());327            assertTrue("Got only one row with id in (1, 2)", rs.next());328            assertEquals(9.7D, rs.getDouble("r"), 0D);329            assertFalse("Got too many rows with id in (1, 2)", rs.next());330        } catch (SQLException se) {331            junit.framework.AssertionFailedError ase =332                new junit.framework.AssertionFailedError(se.getMessage());333            ase.initCause(se);334            throw ase;335        } finally {336            try {337                if (rs != null) {338                    rs.close();339                }340                if (st != null) {341                    st.close();342                }343            } catch (Exception ignored) {}344        }345    }346    // todo347    @Test348    public void testBooleanSimpleRead() {349        ResultSet rs = null;350        Statement st = null;351        try {352            st = netConn.createStatement();353            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");354            assertTrue("Got no rows with id in (1, 2)", rs.next());355            Object o = rs.getObject("b"); // todo - returns string356            // assertEquals(Boolean.class, o.getClass());357            assertTrue("Got only one row with id in (1, 2)", rs.next());358            assertTrue(rs.getBoolean("b"));359            assertFalse("Got too many rows with id in (1, 2)", rs.next());360        } catch (SQLException se) {361            junit.framework.AssertionFailedError ase =362                new junit.framework.AssertionFailedError(se.getMessage());363            ase.initCause(se);364            throw ase;365        } finally {366            try {367                if (rs != null) {368                    rs.close();369                }370                if (st != null) {371                    st.close();372                }373            } catch (Exception ignored) {}374        }375    }376    @Test377    public void testCharSimpleRead() {378        ResultSet rs = null;379        Statement st = null;380        try {381            st = netConn.createStatement();382            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");383            assertTrue("Got no rows with id in (1, 2)", rs.next());384            assertEquals(String.class, rs.getObject("c").getClass());385            assertTrue("Got only one row with id in (1, 2)", rs.next());386            assertEquals("ab ", rs.getString("c"));387            assertFalse("Got too many rows with id in (1, 2)", rs.next());388        } catch (SQLException se) {389            junit.framework.AssertionFailedError ase =390                new junit.framework.AssertionFailedError(se.getMessage());391            ase.initCause(se);392            throw ase;393        } finally {394            try {395                if (rs != null) {396                    rs.close();397                }398                if (st != null) {399                    st.close();400                }401            } catch (Exception ignored) {}402        }403    }404    @Test405    public void testVarCharSimpleRead() {406        ResultSet rs = null;407        Statement st = null;408        try {409            st = netConn.createStatement();410            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");411            assertTrue("Got no rows with id in (1, 2)", rs.next());412            assertEquals(String.class, rs.getObject("cv").getClass());413            assertTrue("Got only one row with id in (1, 2)", rs.next());414            assertEquals("cd", rs.getString("cv"));415            assertFalse("Got too many rows with id in (1, 2)", rs.next());416        } catch (SQLException se) {417            junit.framework.AssertionFailedError ase =418                new junit.framework.AssertionFailedError(se.getMessage());419            ase.initCause(se);420            throw ase;421        } finally {422            try {423                if (rs != null) {424                    rs.close();425                }426                if (st != null) {427                    st.close();428                }429            } catch (Exception ignored) {}430        }431    }432    @Test433    public void testFixedStringSimpleRead() {434        ResultSet rs = null;435        Statement st = null;436        try {437            st = netConn.createStatement();438            rs = st.executeQuery("SELECT i, 'fixed str' fs, cv\n"439                                 + "FROM alltypes WHERE id in (1, 2)");440            assertTrue("Got no rows with id in (1, 2)", rs.next());441            assertEquals(String.class, rs.getObject("fs").getClass());442            assertTrue("Got only one row with id in (1, 2)", rs.next());443            assertEquals("fixed str", rs.getString("fs"));444            assertFalse("Got too many rows with id in (1, 2)", rs.next());445        } catch (SQLException se) {446            junit.framework.AssertionFailedError ase =447                new junit.framework.AssertionFailedError(se.getMessage());448            ase.initCause(se);449            throw ase;450        } finally {451            try {452                if (rs != null) {453                    rs.close();454                }455                if (st != null) {456                    st.close();457                }458            } catch (Exception ignored) {}459        }460    }461    @Test462    public void testDerivedStringSimpleRead() {463        ResultSet rs = null;464        Statement st = null;465        try {466            st = netConn.createStatement();467            rs = st.executeQuery("SELECT i, cv || 'appendage' app, 4\n"468                                 + "FROM alltypes WHERE id in (1, 2)");469            assertTrue("Got no rows with id in (1, 2)", rs.next());470            assertEquals(String.class, rs.getObject("app").getClass());471            assertTrue("Got only one row with id in (1, 2)", rs.next());472            assertEquals("cdappendage", rs.getString("app"));473            assertFalse("Got too many rows with id in (1, 2)", rs.next());474        } catch (SQLException se) {475            junit.framework.AssertionFailedError ase =476                new junit.framework.AssertionFailedError(se.getMessage());477            ase.initCause(se);478            throw ase;479        } finally {480            try {481                if (rs != null) {482                    rs.close();483                }484                if (st != null) {485                    st.close();486                }487            } catch (Exception ignored) {}488        }489    }490    @Test491    public void testDateSimpleRead() {492        ResultSet rs = null;493        Statement st = null;494        try {495            st = netConn.createStatement();496            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");497            assertTrue("Got no rows with id in (1, 2)", rs.next());498            assertEquals(java.sql.Date.class, rs.getObject("d").getClass());499            assertTrue("Got only one row with id in (1, 2)", rs.next());500            assertEquals(501                new java.sql.Date(new java.util.Date().getTime()).toString(),502                rs.getDate("d").toString());503            assertFalse("Got too many rows with id in (1, 2)", rs.next());504        } catch (SQLException se) {505            junit.framework.AssertionFailedError ase =506                new junit.framework.AssertionFailedError(se.getMessage());507            ase.initCause(se);508            throw ase;509        } finally {510            try {511                if (rs != null) {512                    rs.close();513                }514                if (st != null) {515                    st.close();516                }517            } catch (Exception ignored) {}518        }519    }520    @Test521    public void testTimeSimpleRead() {522        ResultSet rs = null;523        Statement st = null;524        try {525            st = netConn.createStatement();526            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");527            assertTrue("Got no rows with id in (1, 2)", rs.next());528            assertEquals(java.sql.Time.class, rs.getObject("t").getClass());529            assertTrue("Got only one row with id in (1, 2)", rs.next());530            assertEquals(Time.valueOf("13:14:00"), rs.getTime("t"));531            assertFalse("Got too many rows with id in (1, 2)", rs.next());532        } catch (SQLException se) {533            junit.framework.AssertionFailedError ase =534                new junit.framework.AssertionFailedError(se.getMessage());535            ase.initCause(se);536            throw ase;537        } finally {538            try {539                if (rs != null) {540                    rs.close();541                }542                if (st != null) {543                    st.close();544                }545            } catch (Exception ignored) {}546        }547    }548    @Test549    public void testTimeWSimpleRead() {550        // This test is failing because the JDBC Driver is returning a551        // String instead of a Time oject for rs.getTime().552        ResultSet rs = null;553        Statement st = null;554        try {555            st = netConn.createStatement();556            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");557            assertTrue("Got no rows with id in (1, 2)", rs.next());558            Object o = rs.getObject("tw"); // todo - returns string 15:16:00.00+1:00559            // assertEquals(java.sql.Time.class, o.getClass());560            assertTrue("Got only one row with id in (1, 2)", rs.next());561            o = rs.getTime("tw"); // todo - wrong result - returns 1 hour562            // assertEquals(Time.valueOf("15:16:00"), o);563            assertFalse("Got too many rows with id in (1, 2)", rs.next());564        } catch (SQLException se) {565            junit.framework.AssertionFailedError ase566                = new junit.framework.AssertionFailedError(se.getMessage());567            ase.initCause(se);568            throw ase;569        } finally {570            try {571                if (rs != null) {572                    rs.close();573                }574                if (st != null) {575                    st.close();576                }577            } catch(Exception ignored) {578            }579        }580    }581    @Test582    public void testTimestampSimpleRead() {583        ResultSet rs = null;584        Statement st = null;585        try {586            st = netConn.createStatement();587            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");588            assertTrue("Got no rows with id in (1, 2)", rs.next());589            assertEquals(Timestamp.class, rs.getObject("ts").getClass());590            assertTrue("Got only one row with id in (1, 2)", rs.next());591            assertEquals(Timestamp.valueOf("2009-02-09 16:17:18"),592                         rs.getTimestamp("ts"));593            assertFalse("Got too many rows with id in (1, 2)", rs.next());594        } catch (SQLException se) {595            junit.framework.AssertionFailedError ase =596                new junit.framework.AssertionFailedError(se.getMessage());597            ase.initCause(se);598            throw ase;599        } finally {600            try {601                if (rs != null) {602                    rs.close();603                }604                if (st != null) {605                    st.close();606                }607            } catch (Exception ignored) {}608        }609    }610    @Test611    public void testTimestampWSimpleRead() {612        ResultSet rs = null;613        Statement st = null;614        try {615            st = netConn.createStatement();616            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");617            assertTrue("Got no rows with id in (1, 2)", rs.next());618            assertEquals(Timestamp.class, rs.getObject("tsw").getClass());619            assertTrue("Got only one row with id in (1, 2)", rs.next());620            assertEquals(Timestamp.valueOf("2009-02-09 17:18:19"),621                         rs.getTimestamp("tsw"));622            assertFalse("Got too many rows with id in (1, 2)", rs.next());623        } catch (SQLException se) {624            junit.framework.AssertionFailedError ase =625                new junit.framework.AssertionFailedError(se.getMessage());626            ase.initCause(se);627            throw ase;628        } finally {629            try {630                if (rs != null) {631                    rs.close();632                }633                if (st != null) {634                    st.close();635                }636            } catch (Exception ignored) {}637        }638    }639    @Test640    public void testBitSimpleRead() {641        // This test is failing because of a BIT padding bug in the engine.642        ResultSet rs = null;643        Statement st = null;644        try {645            st = netConn.createStatement();646            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");647            assertTrue("Got no rows with id in (1, 2)", rs.next());648            assertTrue("Got only one row with id in (1, 2)", rs.next());649            assertEquals("100000000", rs.getString("bt"));650            assertFalse("Got too many rows with id in (1, 2)", rs.next());651        } catch (SQLException se) {652            junit.framework.AssertionFailedError ase =653                new junit.framework.AssertionFailedError(se.getMessage());654            ase.initCause(se);655            throw ase;656        } finally {657            try {658                if (rs != null) {659                    rs.close();660                }661                if (st != null) {662                    st.close();663                }664            } catch (Exception ignored) {}665        }666    }667    @Test668    public void testBitVaryingSimpleRead() {669        ResultSet rs = null;670        Statement st = null;671        try {672            st = netConn.createStatement();673            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");674            assertTrue("Got no rows with id in (1, 2)", rs.next());675            assertTrue("Got only one row with id in (1, 2)", rs.next());676            assertEquals("10", rs.getString("btv"));677            assertFalse("Got too many rows with id in (1, 2)", rs.next());678        } catch (SQLException se) {679            junit.framework.AssertionFailedError ase =680                new junit.framework.AssertionFailedError(se.getMessage());681            ase.initCause(se);682            throw ase;683        } finally {684            try {685                if (rs != null) {686                    rs.close();687                }688                if (st != null) {689                    st.close();690                }691            } catch (Exception ignored) {}692        }693    }694    @Test695    public void testBinarySimpleRead() {696        ResultSet rs            = null;697        Statement st            = null;698        byte[]    expectedBytes = new byte[] {699            (byte) 0xa1, (byte) 0x03, (byte) 0, (byte) 0700        };701        byte[]    ba;702        try {703            st = netConn.createStatement();704            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");705            assertTrue("Got no rows with id in (1, 2)", rs.next());706            assertEquals("A1030000", rs.getString("bin"));707            assertTrue("Got only one row with id in (1, 2)", rs.next());708            ba = rs.getBytes("bin");709            assertFalse("Got too many rows with id in (1, 2)", rs.next());710        } catch (SQLException se) {711            junit.framework.AssertionFailedError ase =712                new junit.framework.AssertionFailedError(se.getMessage());713            ase.initCause(se);714            throw ase;715        } finally {716            try {717                if (rs != null) {718                    rs.close();719                }720                if (st != null) {721                    st.close();722                }723            } catch (Exception ignored) {}724        }725        assertEquals("Retrieved bye array length wrong", expectedBytes.length,726                     ba.length);727        for (int i = 0; i < ba.length; i++) {728            assertEquals("Byte " + i + " wrong", expectedBytes[i], ba[i]);729        }730    }731    @Test732    public void testVarBinarySimpleRead() {733        ResultSet rs            = null;734        Statement st            = null;735        byte[]    expectedBytes = new byte[] {736            (byte) 0xa1, (byte) 0x03737        };738        byte[]    ba;739        try {740            st = netConn.createStatement();741            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");742            assertTrue("Got no rows with id in (1, 2)", rs.next());743            assertEquals("A103", rs.getString("vb"));744            assertTrue("Got only one row with id in (1, 2)", rs.next());745            ba = rs.getBytes("vb");746            assertFalse("Got too many rows with id in (1, 2)", rs.next());747        } catch (SQLException se) {748            junit.framework.AssertionFailedError ase =749                new junit.framework.AssertionFailedError(se.getMessage());750            ase.initCause(se);751            throw ase;752        } finally {753            try {754                if (rs != null) {755                    rs.close();756                }757                if (st != null) {758                    st.close();759                }760            } catch (Exception ignored) {}761        }762        assertEquals("Retrieved bye array length wrong", expectedBytes.length,763                     ba.length);764        for (int i = 0; i < ba.length; i++) {765            assertEquals("Byte " + i + " wrong", expectedBytes[i], ba[i]);766        }767    }768    @Test769    public void testDaySecIntervalSimpleRead() {770        /* Since our client does not support the INTERVAL precision771         * constraints, the returned value will always be toString()'d to772         * precision of microseconds. */773        ResultSet rs = null;774        Statement st = null;775        try {776            st = netConn.createStatement();777            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");778            assertTrue("Got no rows with id in (1, 2)", rs.next());779            assertEquals("145 23:12:19.345000", rs.getString("dsival"));780            assertTrue("Got only one row with id in (1, 2)", rs.next());781            // Can't test the class, because jdbc:odbc or the driver returns782            // a String for getObject() for interval values.783            assertFalse("Got too many rows with id in (1, 2)", rs.next());784        } catch (SQLException se) {785            junit.framework.AssertionFailedError ase =786                new junit.framework.AssertionFailedError(se.getMessage());787            ase.initCause(se);788            throw ase;789        } finally {790            try {791                if (rs != null) {792                    rs.close();793                }794                if (st != null) {795                    st.close();796                }797            } catch (Exception ignored) {}798        }799    }800    @Test801    public void testSecIntervalSimpleRead() {802        /* Since our client does not support the INTERVAL precision803         * constraints, the returned value will always be toString()'d to804         * precision of microseconds. */805        ResultSet rs = null;806        Statement st = null;807        try {808            st = netConn.createStatement();809            rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");810            assertTrue("Got no rows with id in (1, 2)", rs.next());811            assertEquals("1000.345000", rs.getString("sival"));812            assertTrue("Got only one row with id in (1, 2)", rs.next());813            // Can't test the class, because jdbc:odbc or the driver returns814            // a String for getObject() for interval values.815            assertFalse("Got too many rows with id in (1, 2)", rs.next());816        } catch (SQLException se) {817            junit.framework.AssertionFailedError ase =818                new junit.framework.AssertionFailedError(se.getMessage());819            ase.initCause(se);820            throw ase;821        } finally {822            try {823                if (rs != null) {824                    rs.close();825                }826                if (st != null) {827                    st.close();828                }829            } catch (Exception ignored) {}830        }831    }832    @Test833    public void testIntegerComplex() {834        PreparedStatement ps = null;835        ResultSet         rs = null;836        try {837            ps = netConn.prepareStatement(838                "INSERT INTO alltypes(id, i) VALUES(?, ?)");839            ps.setInt(1, 3);840            ps.setInt(2, 495);841            assertEquals(1, ps.executeUpdate());842            ps.setInt(1, 4);843            assertEquals(1, ps.executeUpdate());844            ps.close();845            netConn.commit();846            ps = netConn.prepareStatement(847                "SELECT * FROM alltypes WHERE i = ?");848            ps.setInt(1, 495);849            rs = ps.executeQuery();850            assertTrue("Got no rows with i = 495", rs.next());851            assertEquals(Integer.class, rs.getObject("i").getClass());852            assertTrue("Got only one row with i = 495", rs.next());853            assertEquals(495, rs.getInt("i"));854            assertFalse("Got too many rows with i = 495", rs.next());855        } catch (SQLException se) {856            junit.framework.AssertionFailedError ase =857                new junit.framework.AssertionFailedError(se.getMessage());858            ase.initCause(se);859            throw ase;860        } finally {861            try {862                if (rs != null) {863                    rs.close();864                }865                if (ps != null) {866                    ps.close();867                }868            } catch (Exception ignored) {}869        }870    }871    @Test872    public void testTinyIntComplex() {873        PreparedStatement ps = null;874        ResultSet         rs = null;875        try {876            ps = netConn.prepareStatement(877                "INSERT INTO alltypes(id, ti) VALUES(?, ?)");878            ps.setInt(1, 3);879            ps.setByte(2, (byte) 200);880            assertEquals(1, ps.executeUpdate());881            ps.setInt(1, 4);882            assertEquals(1, ps.executeUpdate());883            ps.close();884            netConn.commit();885            ps = netConn.prepareStatement(886                "SELECT * FROM alltypes WHERE ti = ?");887            ps.setByte(1, (byte) 200);888            rs = ps.executeQuery();889            assertTrue("Got no rows with ti = 200", rs.next());890            Object o = rs.getObject("ti"); // todo - returns string891            // assertEquals(Integer.class, o.getClass());892            assertTrue("Got only one row with ti = 200", rs.next());893            assertEquals((byte) 200, rs.getByte("ti"));894            assertFalse("Got too many rows with ti = 200", rs.next());895            assertFalse(false);896        } catch (SQLException se) {897            junit.framework.AssertionFailedError ase =898                new junit.framework.AssertionFailedError(se.getMessage());899            ase.initCause(se);900            throw ase;901        } finally {902            try {903                if (rs != null) {904                    rs.close();905                }906                if (ps != null) {907                    ps.close();908                }909            } catch (Exception ignored) {}910        }911    }912    @Test913    public void testSmallIntComplex() {914        PreparedStatement ps = null;915        ResultSet         rs = null;916        try {917            ps = netConn.prepareStatement(918                "INSERT INTO alltypes(id, si) VALUES(?, ?)");919            ps.setInt(1, 3);920            ps.setShort(2, (short) 395);921            assertEquals(1, ps.executeUpdate());922            ps.setInt(1, 4);923            assertEquals(1, ps.executeUpdate());924            ps.close();925            netConn.commit();926            ps = netConn.prepareStatement(927                "SELECT * FROM alltypes WHERE si = ?");928            ps.setShort(1, (short) 395);929            rs = ps.executeQuery();930            assertTrue("Got no rows with si = 395", rs.next());931            assertEquals(Integer.class, rs.getObject("si").getClass());932            // Nb. HyperSQL purposefully returns an Integer for this type933            assertTrue("Got only one row with si = 395", rs.next());934            assertEquals((short) 395, rs.getShort("si"));935            assertFalse("Got too many rows with si = 395", rs.next());936        } catch (SQLException se) {937            junit.framework.AssertionFailedError ase =938                new junit.framework.AssertionFailedError(se.getMessage());939            ase.initCause(se);940            throw ase;941        } finally {942            try {943                if (rs != null) {944                    rs.close();945                }946                if (ps != null) {947                    ps.close();948                }949            } catch (Exception ignored) {}950        }951    }952    @Test953    public void testBigIntComplex() {954        PreparedStatement ps = null;955        ResultSet         rs = null;956        try {957            ps = netConn.prepareStatement(958                "INSERT INTO alltypes(id, bi) VALUES(?, ?)");959            ps.setInt(1, 3);960            ps.setLong(2, 295L);961            assertEquals(1, ps.executeUpdate());962            ps.setInt(1, 4);963            assertEquals(1, ps.executeUpdate());964            ps.close();965            netConn.commit();966            ps = netConn.prepareStatement(967                "SELECT * FROM alltypes WHERE bi = ?");968            ps.setLong(1, 295L);969            rs = ps.executeQuery();970            assertTrue("Got no rows with bi = 295L", rs.next());971            assertEquals(Long.class, rs.getObject("bi").getClass());972            assertTrue("Got only one row with bi = 295L", rs.next());973            assertEquals(295L, rs.getLong("bi"));974            assertFalse("Got too many rows with bi = 295L", rs.next());975        } catch (SQLException se) {976            junit.framework.AssertionFailedError ase =977                new junit.framework.AssertionFailedError(se.getMessage());978            ase.initCause(se);979            throw ase;980        } finally {981            try {982                if (rs != null) {983                    rs.close();984                }985                if (ps != null) {986                    ps.close();987                }988            } catch (Exception ignored) {}989        }990    }991    /* TODO:  Implement this test after get testNumericSimpleRead() working.992     *        See that method above.993    public void testNumericComplex() {994    */995   @Test996    public void testFloatComplex() {997        PreparedStatement ps = null;998        ResultSet         rs = null;999        try {1000            ps = netConn.prepareStatement(1001                "INSERT INTO alltypes(id, f) VALUES(?, ?)");1002            ps.setInt(1, 3);1003            ps.setFloat(2, 98.765F);1004            assertEquals(1, ps.executeUpdate());1005            ps.setInt(1, 4);1006            assertEquals(1, ps.executeUpdate());1007            ps.close();1008            netConn.commit();1009            ps = netConn.prepareStatement(1010                "SELECT * FROM alltypes WHERE f = ?");1011            ps.setFloat(1, 98.765F);1012            rs = ps.executeQuery();1013            assertTrue("Got no rows with f = 98.765F", rs.next());1014            assertEquals(Double.class, rs.getObject("f").getClass());1015            assertTrue("Got only one row with f = 98.765F", rs.next());1016            assertEquals(98.765D, rs.getDouble("f"), .01D);1017            assertFalse("Got too many rows with f = 98.765F", rs.next());1018        } catch (SQLException se) {1019            junit.framework.AssertionFailedError ase =1020                new junit.framework.AssertionFailedError(se.getMessage());1021            ase.initCause(se);1022            throw ase;1023        } finally {1024            try {1025                if (rs != null) {1026                    rs.close();1027                }1028                if (ps != null) {1029                    ps.close();1030                }1031            } catch (Exception ignored) {}1032        }1033    }1034    @Test1035    public void testDoubleComplex() {1036        PreparedStatement ps = null;1037        ResultSet         rs = null;1038        try {1039            ps = netConn.prepareStatement(1040                "INSERT INTO alltypes(id, r) VALUES(?, ?)");1041            ps.setInt(1, 3);1042            ps.setDouble(2, 876.54D);1043            assertEquals(1, ps.executeUpdate());1044            ps.setInt(1, 4);1045            assertEquals(1, ps.executeUpdate());1046            ps.close();1047            netConn.commit();1048            ps = netConn.prepareStatement(1049                "SELECT * FROM alltypes WHERE r = ?");1050            ps.setDouble(1, 876.54D);1051            rs = ps.executeQuery();1052            assertTrue("Got no rows with r = 876.54D", rs.next());1053            assertEquals(Double.class, rs.getObject("r").getClass());1054            assertTrue("Got only one row with r = 876.54D", rs.next());1055            assertEquals(876.54D, rs.getDouble("r"), 0D);1056            assertFalse("Got too many rows with r = 876.54D", rs.next());1057        } catch (SQLException se) {1058            junit.framework.AssertionFailedError ase =1059                new junit.framework.AssertionFailedError(se.getMessage());1060            ase.initCause(se);1061            throw ase;1062        } finally {1063            try {1064                if (rs != null) {1065                    rs.close();1066                }1067                if (ps != null) {1068                    ps.close();1069                }1070            } catch (Exception ignored) {}1071        }1072    }1073    @Test1074    public void testBooleanComplex() {1075        PreparedStatement ps = null;1076        ResultSet         rs = null;1077        try {1078            ps = netConn.prepareStatement(1079                "INSERT INTO alltypes(id, b) VALUES(?, ?)");1080            ps.setInt(1, 3);1081            ps.setBoolean(2, false);1082            assertEquals(1, ps.executeUpdate());1083            ps.setInt(1, 4);1084            assertEquals(1, ps.executeUpdate());1085            ps.close();1086            netConn.commit();1087            ps = netConn.prepareStatement(1088                "SELECT * FROM alltypes WHERE b = ?");1089            ps.setBoolean(1, false);1090            rs = ps.executeQuery();1091            assertTrue("Got no rows with b = false", rs.next());1092            Object o = rs.getObject("b"); // todo - returns string1093            // assertEquals(Boolean.class, rs.getObject("b").getClass());1094            assertTrue("Got only one row with b = false", rs.next());1095            assertEquals(false, rs.getBoolean("b"));1096            assertFalse("Got too many rows with b = false", rs.next());1097        } catch (SQLException se) {1098            junit.framework.AssertionFailedError ase =1099                new junit.framework.AssertionFailedError(se.getMessage());1100            ase.initCause(se);1101            throw ase;1102        } finally {1103            try {1104                if (rs != null) {1105                    rs.close();1106                }1107                if (ps != null) {1108                    ps.close();1109                }1110            } catch (Exception ignored) {}1111        }1112    }1113    @Test1114    public void testCharComplex() {1115        PreparedStatement ps = null;1116        ResultSet         rs = null;1117        try {1118            ps = netConn.prepareStatement(1119                "INSERT INTO alltypes(id, c) VALUES(?, ?)");1120            ps.setInt(1, 3);1121            ps.setString(2, "xy");1122            assertEquals(1, ps.executeUpdate());1123            ps.setInt(1, 4);1124            assertEquals(1, ps.executeUpdate());1125            ps.close();1126            netConn.commit();1127            ps = netConn.prepareStatement(1128                "SELECT * FROM alltypes WHERE c = ?");1129            ps.setString(1, "xy ");1130            rs = ps.executeQuery();1131            assertTrue("Got no rows with c = 'xy '", rs.next());1132            assertEquals(String.class, rs.getObject("c").getClass());1133            assertTrue("Got only one row with c = 'xy '", rs.next());1134            assertEquals("xy ", rs.getString("c"));1135            assertFalse("Got too many rows with c = 'xy '", rs.next());1136        } catch (SQLException se) {1137            junit.framework.AssertionFailedError ase =1138                new junit.framework.AssertionFailedError(se.getMessage());1139            ase.initCause(se);1140            throw ase;1141        } finally {1142            try {1143                if (rs != null) {1144                    rs.close();1145                }1146                if (ps != null) {1147                    ps.close();1148                }1149            } catch (Exception ignored) {}1150        }1151    }1152    @Test1153    public void testVarCharComplex() {1154        PreparedStatement ps = null;1155        ResultSet         rs = null;1156        try {1157            ps = netConn.prepareStatement(1158                "INSERT INTO alltypes(id, cv) VALUES(?, ?)");1159            ps.setInt(1, 3);1160            ps.setString(2, "xy");1161            assertEquals(1, ps.executeUpdate());1162            ps.setInt(1, 4);1163            assertEquals(1, ps.executeUpdate());1164            ps.close();1165            netConn.commit();1166            ps = netConn.prepareStatement(1167                "SELECT * FROM alltypes WHERE cv = ?");1168            ps.setString(1, "xy");1169            rs = ps.executeQuery();1170            assertTrue("Got no rows with cv = 'xy'", rs.next());1171            assertEquals(String.class, rs.getObject("cv").getClass());1172            assertTrue("Got only one row with cv = 'xy'", rs.next());1173            assertEquals("xy", rs.getString("cv"));1174            assertFalse("Got too many rows with cv = 'xy'", rs.next());1175        } catch (SQLException se) {1176            junit.framework.AssertionFailedError ase =1177                new junit.framework.AssertionFailedError(se.getMessage());1178            ase.initCause(se);1179            throw ase;1180        } finally {1181            try {1182                if (rs != null) {1183                    rs.close();1184                }1185                if (ps != null) {1186                    ps.close();1187                }1188            } catch (Exception ignored) {}1189        }1190    }1191    /**1192     * TODO:  Find out if there is a way to select based on an expression1193     * using a named derived pseudo-column.1194     */1195    @Test1196    public void testDerivedComplex() {1197        PreparedStatement ps = null;1198        ResultSet rs = null;1199        try {1200            ps = netConn.prepareStatement(1201                "SELECT id, cv || 'app' appendage FROM alltypes\n"1202                + "WHERE (cv || 'app') = ?");1203            ps.setString(1, "cvapp");1204            rs = ps.executeQuery();1205            assertTrue("Got no rows appendage = 'cvapp'", rs.next());1206            assertEquals(String.class, rs.getObject("r").getClass());1207            assertTrue("Got only one row with appendage = 'cvapp'", rs.next());1208            assertEquals("cvapp", rs.getString("r"));1209            assertFalse("Got too many rows with appendage = 'cvapp'", rs.next());1210        } catch (SQLException se) {1211            junit.framework.AssertionFailedError ase1212                = new junit.framework.AssertionFailedError(se.getMessage());1213            ase.initCause(se);1214            throw ase;1215        } finally {1216            try {1217                if (rs != null) {1218                    rs.close();1219                }1220                if (ps != null) {1221                    ps.close();1222                }1223            } catch(Exception ignored) {1224            }1225        }1226    }1227    @Test1228    public void testDateComplex() {1229        PreparedStatement ps = null;1230        ResultSet         rs = null;1231        java.sql.Date tomorrow =1232            new java.sql.Date(new java.util.Date().getTime()1233                              + 1000 * 60 * 60 * 24);1234        try {1235            ps = netConn.prepareStatement(1236                "INSERT INTO alltypes(id, d) VALUES(?, ?)");1237            ps.setInt(1, 3);1238            ps.setDate(2, tomorrow);1239            assertEquals(1, ps.executeUpdate());1240            ps.setInt(1, 4);1241            assertEquals(1, ps.executeUpdate());1242            ps.close();1243            netConn.commit();1244            ps = netConn.prepareStatement(1245                "SELECT * FROM alltypes WHERE d = ?");1246            ps.setDate(1, tomorrow);1247            rs = ps.executeQuery();1248            assertTrue("Got no rows with d = tomorrow", rs.next());1249            assertEquals(java.sql.Date.class, rs.getObject("d").getClass());1250            assertTrue("Got only one row with d = tomorrow", rs.next());1251            assertEquals(tomorrow.toString(), rs.getDate("d").toString());1252            // Compare the Strings since "tomorrow" has resolution to1253            // millisecond, but getDate() is probably to the day.1254            assertFalse("Got too many rows with d = tomorrow", rs.next());1255        } catch (SQLException se) {1256            junit.framework.AssertionFailedError ase =1257                new junit.framework.AssertionFailedError(se.getMessage());1258            ase.initCause(se);1259            throw ase;1260        } finally {1261            try {1262                if (rs != null) {1263                    rs.close();1264                }1265                if (ps != null) {1266                    ps.close();1267                }1268            } catch (Exception ignored) {}1269        }1270    }1271    @Test1272    public void testTimeComplex() {1273        PreparedStatement ps    = null;1274        ResultSet         rs    = null;1275        Time              aTime = Time.valueOf("21:19:27");1276        try {1277            ps = netConn.prepareStatement(1278                "INSERT INTO alltypes(id, t) VALUES(?, ?)");1279            ps.setInt(1, 3);1280            ps.setTime(2, aTime);1281            assertEquals(1, ps.executeUpdate());1282            ps.setInt(1, 4);1283            assertEquals(1, ps.executeUpdate());1284            ps.close();1285            netConn.commit();1286            ps = netConn.prepareStatement(1287                "SELECT * FROM alltypes WHERE t = ?");1288            ps.setTime(1, aTime);1289            rs = ps.executeQuery();1290            assertTrue("Got no rows with t = aTime", rs.next());1291            assertEquals(Time.class, rs.getObject("t").getClass());1292            assertTrue("Got only one row with t = aTime", rs.next());1293            assertEquals(aTime, rs.getTime("t"));1294            assertFalse("Got too many rows with t = aTime", rs.next());1295        } catch (SQLException se) {1296            junit.framework.AssertionFailedError ase =1297                new junit.framework.AssertionFailedError(se.getMessage());1298            ase.initCause(se);1299            throw ase;1300        } finally {1301            try {1302                if (rs != null) {1303                    rs.close();1304                }1305                if (ps != null) {1306                    ps.close();1307                }1308            } catch (Exception ignored) {}1309        }1310    }1311    /* TODO:  Implement this test after get testTimeWSimpleRead() working.1312     *        See that method above.1313    public void testTimeWComplex() {1314    */1315   @Test1316    public void testTimestampComplex() {1317        PreparedStatement ps = null;1318        ResultSet         rs = null;1319        Timestamp aTimestamp = Timestamp.valueOf("2009-03-27 17:18:19");1320        try {1321            ps = netConn.prepareStatement(1322                "INSERT INTO alltypes(id, ts) VALUES(?, ?)");1323            ps.setInt(1, 3);1324            ps.setTimestamp(2, aTimestamp);1325            assertEquals(1, ps.executeUpdate());1326            ps.setInt(1, 4);1327            assertEquals(1, ps.executeUpdate());1328            ps.close();1329            netConn.commit();1330            ps = netConn.prepareStatement(1331                "SELECT * FROM alltypes WHERE ts = ?");1332            ps.setTimestamp(1, aTimestamp);1333            rs = ps.executeQuery();1334            assertTrue("Got no rows with ts = aTimestamp", rs.next());1335            assertEquals(Timestamp.class, rs.getObject("ts").getClass());1336            assertTrue("Got only one row with ts = aTimestamp", rs.next());1337            assertEquals(aTimestamp, rs.getTimestamp("ts"));1338            assertFalse("Got too many rows with ts = aTimestamp", rs.next());1339        } catch (SQLException se) {1340            junit.framework.AssertionFailedError ase =1341                new junit.framework.AssertionFailedError(se.getMessage());1342            ase.initCause(se);1343            throw ase;1344        } finally {1345            try {1346                if (rs != null) {1347                    rs.close();1348                }1349                if (ps != null) {1350                    ps.close();1351                }1352            } catch (Exception ignored) {}1353        }1354    }1355    @Test1356    public void testTimestampWComplex() {1357        PreparedStatement ps = null;1358        ResultSet         rs = null;1359        Timestamp aTimestamp = Timestamp.valueOf("2009-03-27 17:18:19");1360        try {1361            ps = netConn.prepareStatement(1362                "INSERT INTO alltypes(id, tsw) VALUES(?, ?)");1363            ps.setInt(1, 3);1364            ps.setTimestamp(2, aTimestamp);1365            assertEquals(1, ps.executeUpdate());1366            ps.setInt(1, 4);1367            assertEquals(1, ps.executeUpdate());1368            ps.close();1369            netConn.commit();1370            ps = netConn.prepareStatement(1371                "SELECT * FROM alltypes WHERE tsw = ?");1372            ps.setTimestamp(1, aTimestamp);1373            rs = ps.executeQuery();1374            assertTrue("Got no rows with tsw = aTimestamp", rs.next());1375            assertEquals(Timestamp.class, rs.getObject("tsw").getClass());1376            assertTrue("Got only one row with tsw = aTimestamp", rs.next());1377            assertEquals(aTimestamp, rs.getTimestamp("tsw"));1378            assertFalse("Got too many rows with tsw = aTimestamp", rs.next());1379        } catch (SQLException se) {1380            junit.framework.AssertionFailedError ase =1381                new junit.framework.AssertionFailedError(se.getMessage());1382            ase.initCause(se);1383            throw ase;1384        } finally {1385            try {1386                if (rs != null) {1387                    rs.close();1388                }1389                if (ps != null) {1390                    ps.close();1391                }1392            } catch (Exception ignored) {}1393        }1394    }1395    /*1396     * Driver needs to be modified to transfer bits in byte (binary) fashion,1397     * the same as is done for VARBINARY/bytea type.1398     */1399    @Ignore1400    public void testBitComplex() {1401        PreparedStatement ps = null;1402        ResultSet rs = null;1403        try {1404            ps = netConn.prepareStatement(1405                "INSERT INTO alltypes(id, bt) VALUES(?, ?)");1406            ps.setInt(1, 3);1407            ps.setString(2, "101");1408            assertEquals(1, ps.executeUpdate());1409            ps.setInt(1, 4);1410            assertEquals(1, ps.executeUpdate());1411            ps.close();1412            netConn.commit();1413            ps = netConn.prepareStatement(1414                "SELECT * FROM alltypes WHERE bt = ?");1415            ps.setString(1, "101");1416            rs = ps.executeQuery();1417            assertTrue("Got no rows with bt = 101", rs.next());1418            assertEquals(String.class, rs.getObject("bt").getClass());1419            assertTrue("Got only one row with bt = 101", rs.next());1420            assertEquals("101000000", rs.getString("bt"));1421            assertFalse("Got too many rows with bt = 101", rs.next());1422        } catch (SQLException se) {1423            junit.framework.AssertionFailedError ase1424                = new junit.framework.AssertionFailedError(se.getMessage());1425            ase.initCause(se);1426            throw ase;1427        } finally {1428            try {1429                if (rs != null) {1430                    rs.close();1431                }1432                if (ps != null) {1433                    ps.close();1434                }1435            } catch(Exception ignored) {1436            } }1437    }1438    @Ignore1439    public void testBitVaryingComplex() {1440        PreparedStatement ps = null;1441        ResultSet rs = null;1442        try {1443            ps = netConn.prepareStatement(1444                "INSERT INTO alltypes(id, btv) VALUES(?, ?)");1445            ps.setInt(1, 3);1446            ps.setString(2, "10101"); // toto - throws right truncation1447            assertEquals(1, ps.executeUpdate());1448            ps.setInt(1, 4);1449            assertEquals(1, ps.executeUpdate());1450            ps.close();1451            netConn.commit();1452            ps = netConn.prepareStatement(1453                "SELECT * FROM alltypes WHERE btv = ?");1454            ps.setString(1, "10101");1455            rs = ps.executeQuery();1456            assertTrue("Got no rows with btv = 10101", rs.next());1457            Object o = rs.getObject("btv");1458            assertEquals(String.class, rs.getObject("btv").getClass());1459            assertTrue("Got only one row with btv = 10101", rs.next());1460            assertEquals("10101", rs.getString("btv"));1461            assertFalse("Got too many rows with btv = 10101", rs.next());1462        } catch (SQLException se) {1463            junit.framework.AssertionFailedError ase1464                = new junit.framework.AssertionFailedError(se.getMessage());1465            ase.initCause(se);1466            throw ase;1467        } finally {1468            try {1469                if (rs != null) {1470                    rs.close();1471                }1472                if (ps != null) {1473                    ps.close();1474                }1475            } catch(Exception ignored) {1476            }1477        }1478    }1479    @Test1480    public void testBinaryComplex() {1481        PreparedStatement ps            = null;1482        ResultSet         rs            = null;1483        byte[]            expectedBytes = new byte[] {1484            (byte) 0xaa, (byte) 0x99, (byte) 0, (byte) 01485        };1486        byte[]            ba1, ba2;1487        try {1488            ps = netConn.prepareStatement(1489                "INSERT INTO alltypes(id, bin) VALUES(?, ?)");1490            ps.setInt(1, 3);1491            ps.setBytes(2, expectedBytes);1492            assertEquals(1, ps.executeUpdate());1493            ps.setInt(1, 4);1494            assertEquals(1, ps.executeUpdate());1495            ps.close();1496            netConn.commit();1497            ps = netConn.prepareStatement(1498                "SELECT * FROM alltypes WHERE bin = ?");1499            ps.setBytes(1, expectedBytes);1500            rs = ps.executeQuery();1501            assertTrue("Got no rows with bin = b'AA99'", rs.next());1502            ba1 = rs.getBytes("bin");1503            assertTrue("Got only one row with bin = b'AA99'", rs.next());1504            ba2 = rs.getBytes("bin");1505            assertFalse("Got too many rows with bin = b'AA99'", rs.next());1506        } catch (SQLException se) {1507            junit.framework.AssertionFailedError ase =1508                new junit.framework.AssertionFailedError(se.getMessage());1509            ase.initCause(se);1510            throw ase;1511        } finally {1512            try {1513                if (rs != null) {1514                    rs.close();1515                }1516                if (ps != null) {1517                    ps.close();1518                }1519            } catch (Exception ignored) {}1520        }1521        assertEquals("Retrieved bye array length wrong (1)",1522                     expectedBytes.length, ba1.length);1523        for (int i = 0; i < ba1.length; i++) {1524            assertEquals("Byte " + i + " wrong (1)", expectedBytes[i], ba1[i]);1525        }1526        assertEquals("Retrieved bye array length wrong (2)",1527                     expectedBytes.length, ba2.length);1528        for (int i = 0; i < ba2.length; i++) {1529            assertEquals("Byte " + i + " wrong (2)", expectedBytes[i], ba2[i]);1530        }1531    }1532    @Test1533    public void testVarBinaryComplex() {1534        PreparedStatement ps            = null;1535        ResultSet         rs            = null;1536        byte[]            expectedBytes = new byte[] {1537            (byte) 0xaa, (byte) 0x991538        };1539        byte[]            ba1, ba2;1540        try {1541            ps = netConn.prepareStatement(1542                "INSERT INTO alltypes(id, vb) VALUES(?, ?)");1543            ps.setInt(1, 3);1544            ps.setBytes(2, expectedBytes);1545            assertEquals(1, ps.executeUpdate());1546            ps.setInt(1, 4);1547            assertEquals(1, ps.executeUpdate());1548            ps.close();1549            netConn.commit();1550            ps = netConn.prepareStatement(1551                "SELECT * FROM alltypes WHERE vb = ?");1552            ps.setBytes(1, expectedBytes);1553            rs = ps.executeQuery();1554            assertTrue("Got no rows with vb = b'AA99'", rs.next());1555            ba1 = rs.getBytes("vb");1556            assertTrue("Got only one row with vb = b'AA99'", rs.next());1557            ba2 = rs.getBytes("vb");1558            assertFalse("Got too many rows with vb = b'AA99'", rs.next());1559        } catch (SQLException se) {1560            junit.framework.AssertionFailedError ase =1561                new junit.framework.AssertionFailedError(se.getMessage());1562            ase.initCause(se);1563            throw ase;1564        } finally {1565            try {1566                if (rs != null) {1567                    rs.close();1568                }1569                if (ps != null) {1570                    ps.close();1571                }1572            } catch (Exception ignored) {}1573        }1574        assertEquals("Retrieved bye array length wrong (1)",1575                     expectedBytes.length, ba1.length);1576        for (int i = 0; i < ba1.length; i++) {1577            assertEquals("Byte " + i + " wrong (1)", expectedBytes[i], ba1[i]);1578        }1579        assertEquals("Retrieved bye array length wrong (2)",1580                     expectedBytes.length, ba2.length);1581        for (int i = 0; i < ba2.length; i++) {1582            assertEquals("Byte " + i + " wrong (2)", expectedBytes[i], ba2[i]);1583        }1584    }1585    /*1586     * TODO:  Learn how to set input params for INTERVAL types.1587     *        I don't see how I could set the variant1588     *        (HOUR, ...TO SECOND, etc.) with setString() or anything else.1589     */1590    @Test1591    public void testDaySecIntervalComplex() {1592        PreparedStatement ps = null;1593        ResultSet rs = null;1594        try {1595            ps = netConn.prepareStatement(1596                "INSERT INTO alltypes(id, dsival) VALUES(?, ?)");1597            ps.setInt(1, 3);1598            ps.setString(2, "45 23:12:19.345000");1599            assertEquals(1, ps.executeUpdate());1600            ps.setInt(1, 4);1601            assertEquals(1, ps.executeUpdate());1602            ps.close();1603            netConn.commit();1604            ps = netConn.prepareStatement(1605                "SELECT * FROM alltypes WHERE dsival = ?");1606            ps.setString(1, "45 23:12:19.345000");1607            rs = ps.executeQuery();1608            assertTrue("Got no rows with dsival = 45 23:12:19.345000", rs.next());1609            assertEquals(String.class, rs.getObject("dsival").getClass());1610            assertTrue("Got only one row with dsival = 45 23:12:19.345000", rs.next());1611            assertEquals("45 23:12:19.345000", rs.getString("dsival"));1612            assertFalse("Got too many rows with dsival = 45 23:12:19.345000", rs.next());1613        } catch (SQLException se) {1614            junit.framework.AssertionFailedError ase1615                = new junit.framework.AssertionFailedError(se.getMessage());1616            ase.initCause(se);1617            throw ase;1618        } finally {1619            try {1620                if (rs != null) {1621                    rs.close();1622                }1623                if (ps != null) {1624                    ps.close();1625                }1626            } catch(Exception e) {1627            }1628        }1629    }1630    @Test1631    public void testSecIntervalComplex() {1632        PreparedStatement ps = null;1633        ResultSet rs = null;1634        try {1635            ps = netConn.prepareStatement(1636                "INSERT INTO alltypes(id, sival) VALUES(?, ?)");1637            ps.setInt(1, 3);1638            ps.setString(2, "876.54");1639            assertEquals(1, ps.executeUpdate());1640            ps.setInt(1, 4);1641            assertEquals(1, ps.executeUpdate());1642            ps.close();1643            netConn.commit();1644            ps = netConn.prepareStatement(1645                "SELECT * FROM alltypes WHERE sival = ?");1646            ps.setString(1, "876.54");1647            rs = ps.executeQuery();1648            assertTrue("Got no rows with sival = 876.54D", rs.next());1649            assertEquals(String.class, rs.getObject("sival").getClass());1650            assertTrue("Got only one row with sival = 876.54D", rs.next());1651            assertTrue(rs.getString("sival").startsWith("876.54"));1652            assertFalse("Got too many rows with sival = 876.54D", rs.next());1653        } catch (SQLException se) {1654            junit.framework.AssertionFailedError ase1655                = new junit.framework.AssertionFailedError(se.getMessage());1656            ase.initCause(se);1657            throw ase;1658        } finally {1659            try {1660                if (rs != null) {1661                    rs.close();1662                }1663                if (ps != null) {1664                    ps.close();1665                }...Source:SimpleRegressionTest.java  
...36		junit.framework.Assert.assertEquals("r", -0.94663767742, regression.getR(), 1.0E-10);37	}38	public void testNaNs() {39		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();40		junit.framework.Assert.assertTrue("intercept not NaN", java.lang.Double.isNaN(regression.getIntercept()));41		junit.framework.Assert.assertTrue("slope not NaN", java.lang.Double.isNaN(regression.getSlope()));42		junit.framework.Assert.assertTrue("slope std err not NaN", java.lang.Double.isNaN(regression.getSlopeStdErr()));43		junit.framework.Assert.assertTrue("intercept std err not NaN", java.lang.Double.isNaN(regression.getInterceptStdErr()));44		junit.framework.Assert.assertTrue("MSE not NaN", java.lang.Double.isNaN(regression.getMeanSquareError()));45		junit.framework.Assert.assertTrue("e not NaN", java.lang.Double.isNaN(regression.getR()));46		junit.framework.Assert.assertTrue("r-square not NaN", java.lang.Double.isNaN(regression.getRSquare()));47		junit.framework.Assert.assertTrue("RSS not NaN", java.lang.Double.isNaN(regression.getRegressionSumSquares()));48		junit.framework.Assert.assertTrue("SSE not NaN", java.lang.Double.isNaN(regression.getSumSquaredErrors()));49		junit.framework.Assert.assertTrue("SSTO not NaN", java.lang.Double.isNaN(regression.getTotalSumSquares()));50		junit.framework.Assert.assertTrue("predict not NaN", java.lang.Double.isNaN(regression.predict(0)));51		regression.addData(1, 2);52		regression.addData(1, 3);53		junit.framework.Assert.assertTrue("intercept not NaN", java.lang.Double.isNaN(regression.getIntercept()));54		junit.framework.Assert.assertTrue("slope not NaN", java.lang.Double.isNaN(regression.getSlope()));55		junit.framework.Assert.assertTrue("slope std err not NaN", java.lang.Double.isNaN(regression.getSlopeStdErr()));56		junit.framework.Assert.assertTrue("intercept std err not NaN", java.lang.Double.isNaN(regression.getInterceptStdErr()));57		junit.framework.Assert.assertTrue("MSE not NaN", java.lang.Double.isNaN(regression.getMeanSquareError()));58		junit.framework.Assert.assertTrue("e not NaN", java.lang.Double.isNaN(regression.getR()));59		junit.framework.Assert.assertTrue("r-square not NaN", java.lang.Double.isNaN(regression.getRSquare()));60		junit.framework.Assert.assertTrue("RSS not NaN", java.lang.Double.isNaN(regression.getRegressionSumSquares()));61		junit.framework.Assert.assertTrue("SSE not NaN", java.lang.Double.isNaN(regression.getSumSquaredErrors()));62		junit.framework.Assert.assertTrue("predict not NaN", java.lang.Double.isNaN(regression.predict(0)));63		junit.framework.Assert.assertTrue("SSTO NaN", !(java.lang.Double.isNaN(regression.getTotalSumSquares())));64		regression = new org.apache.commons.math.stat.regression.SimpleRegression();65		regression.addData(1, 2);66		regression.addData(3, 3);67		junit.framework.Assert.assertTrue("interceptNaN", !(java.lang.Double.isNaN(regression.getIntercept())));68		junit.framework.Assert.assertTrue("slope NaN", !(java.lang.Double.isNaN(regression.getSlope())));69		junit.framework.Assert.assertTrue("slope std err not NaN", java.lang.Double.isNaN(regression.getSlopeStdErr()));70		junit.framework.Assert.assertTrue("intercept std err not NaN", java.lang.Double.isNaN(regression.getInterceptStdErr()));71		junit.framework.Assert.assertTrue("MSE not NaN", java.lang.Double.isNaN(regression.getMeanSquareError()));72		junit.framework.Assert.assertTrue("r NaN", !(java.lang.Double.isNaN(regression.getR())));73		junit.framework.Assert.assertTrue("r-square NaN", !(java.lang.Double.isNaN(regression.getRSquare())));74		junit.framework.Assert.assertTrue("RSS NaN", !(java.lang.Double.isNaN(regression.getRegressionSumSquares())));75		junit.framework.Assert.assertTrue("SSE NaN", !(java.lang.Double.isNaN(regression.getSumSquaredErrors())));76		junit.framework.Assert.assertTrue("SSTO NaN", !(java.lang.Double.isNaN(regression.getTotalSumSquares())));77		junit.framework.Assert.assertTrue("predict NaN", !(java.lang.Double.isNaN(regression.predict(0))));78		regression.addData(1, 4);79		junit.framework.Assert.assertTrue("MSE NaN", !(java.lang.Double.isNaN(regression.getMeanSquareError())));80		junit.framework.Assert.assertTrue("slope std err NaN", !(java.lang.Double.isNaN(regression.getSlopeStdErr())));81		junit.framework.Assert.assertTrue("intercept std err NaN", !(java.lang.Double.isNaN(regression.getInterceptStdErr())));82	}83	public void testClear() {84		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();85		regression.addData(corrData);86		junit.framework.Assert.assertEquals("number of observations", 17, regression.getN());87		regression.clear();88		junit.framework.Assert.assertEquals("number of observations", 0, regression.getN());89		regression.addData(corrData);90		junit.framework.Assert.assertEquals("r-square", 0.896123, regression.getRSquare(), 1.0E-5);91		regression.addData(data);92		junit.framework.Assert.assertEquals("number of observations", 53, regression.getN());93	}94	public void testInference() throws java.lang.Exception {95		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();96		regression.addData(infData);97		junit.framework.Assert.assertEquals("slope std err", 0.011448491, regression.getSlopeStdErr(), 1.0E-10);98		junit.framework.Assert.assertEquals("std err intercept", 0.286036932, regression.getInterceptStdErr(), 1.0E-8);99		junit.framework.Assert.assertEquals("significance", 4.596E-7, regression.getSignificance(), 1.0E-8);100		junit.framework.Assert.assertEquals("slope conf interval half-width", 0.0270713794287, regression.getSlopeConfidenceInterval(), 1.0E-8);101		regression = new org.apache.commons.math.stat.regression.SimpleRegression();102		regression.addData(infData2);103		junit.framework.Assert.assertEquals("slope std err", 1.07260253, regression.getSlopeStdErr(), 1.0E-8);104		junit.framework.Assert.assertEquals("std err intercept", 4.17718672, regression.getInterceptStdErr(), 1.0E-8);105		junit.framework.Assert.assertEquals("significance", 0.261829133982, regression.getSignificance(), 1.0E-11);106		junit.framework.Assert.assertEquals("slope conf interval half-width", 2.97802204827, regression.getSlopeConfidenceInterval(), 1.0E-8);107		junit.framework.Assert.assertTrue("tighter means wider", ((regression.getSlopeConfidenceInterval()) < (regression.getSlopeConfidenceInterval(0.01))));108		try {109			regression.getSlopeConfidenceInterval(1);110			junit.framework.Assert.fail("expecting IllegalArgumentException for alpha = 1");111		} catch (java.lang.IllegalArgumentException ex) {112		}113	}114	public void testPerfect() throws java.lang.Exception {115		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();116		int n = 100;117		for (int i = 0 ; i < n ; i++) {118			regression.addData((((double)(i)) / (n - 1)), i);119		}120		junit.framework.Assert.assertEquals(0.0, regression.getSignificance(), 1.0E-5);121		junit.framework.Assert.assertTrue(((regression.getSlope()) > 0.0));122		junit.framework.Assert.assertTrue(((regression.getSumSquaredErrors()) >= 0.0));123	}124	public void testPerfectNegative() throws java.lang.Exception {125		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();126		int n = 100;127		for (int i = 0 ; i < n ; i++) {128			regression.addData(((-((double)(i))) / (n - 1)), i);129		}130		junit.framework.Assert.assertEquals(0.0, regression.getSignificance(), 1.0E-5);131		junit.framework.Assert.assertTrue(((regression.getSlope()) < 0.0));132	}133	public void testRandom() throws java.lang.Exception {134		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();135		java.util.Random random = new java.util.Random(1);136		int n = 100;137		for (int i = 0 ; i < n ; i++) {138			regression.addData((((double)(i)) / (n - 1)), random.nextDouble());139		}140		junit.framework.Assert.assertTrue(((0.0 < (regression.getSignificance())) && ((regression.getSignificance()) < 1.0)));141	}142	public void testSSENonNegative() {143		double[] y = new double[]{ 8915.102 , 8919.302 , 8923.502 };144		double[] x = new double[]{ 110.7178495 , 110.7264895 , 110.7351295 };145		org.apache.commons.math.stat.regression.SimpleRegression reg = new org.apache.commons.math.stat.regression.SimpleRegression();146		for (int i = 0 ; i < (x.length) ; i++) {147			reg.addData(x[i], y[i]);148		}149		junit.framework.Assert.assertTrue(((reg.getSumSquaredErrors()) >= 0.0));150	}151	public void testRemoveXY() throws java.lang.Exception {152		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();153		regression.addData(infData);154		regression.removeData(removeX, removeY);155		regression.addData(removeX, removeY);156		junit.framework.Assert.assertEquals("slope std err", 0.011448491, regression.getSlopeStdErr(), 1.0E-10);157		junit.framework.Assert.assertEquals("std err intercept", 0.286036932, regression.getInterceptStdErr(), 1.0E-8);158		junit.framework.Assert.assertEquals("significance", 4.596E-7, regression.getSignificance(), 1.0E-8);159		junit.framework.Assert.assertEquals("slope conf interval half-width", 0.0270713794287, regression.getSlopeConfidenceInterval(), 1.0E-8);160	}161	public void testRemoveSingle() throws java.lang.Exception {162		org.apache.commons.math.stat.regression.SimpleRegression regression = new org.apache.commons.math.stat.regression.SimpleRegression();163		regression.addData(infData);...Source:ConvertFunctionTestCase.java  
...54            public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {55                EventPrinter.print(timeStamp, inEvents, removeEvents);56                for (Event inEvent : inEvents) {57                    count++;58                    junit.framework.Assert.assertTrue(inEvent.getData(0) instanceof String);59                    junit.framework.Assert.assertTrue(inEvent.getData(1) instanceof Float);60                    junit.framework.Assert.assertTrue(inEvent.getData(2) instanceof Double);61                    junit.framework.Assert.assertTrue(inEvent.getData(3) instanceof Integer);62                    junit.framework.Assert.assertTrue(inEvent.getData(4) instanceof Long);63                    junit.framework.Assert.assertTrue(inEvent.getData(5) instanceof Boolean);64                }65            }66        });67        InputHandler inputHandler = executionPlanRuntime.getInputHandler("typeStream");68        executionPlanRuntime.start();69        inputHandler.send(new Object[]{"WSO2", 2f, 3d, 4, 5l, true});70        Thread.sleep(100);71        Assert.assertEquals(1, count);72        executionPlanRuntime.shutdown();73    }74    @Test75    public void convertFunctionTest2() throws InterruptedException {76        log.info("convert function test 2");77        SiddhiManager siddhiManager = new SiddhiManager();78        String cseEventStream = "" +79                "@config(async = 'true') " +80                "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB bool) ;";81        String query = "" +82                "@info(name = 'query1') " +83                "from typeStream " +84                "select convert(typeS,'string') as valueS1, convert(typeS,'float') as valueF1, convert(typeS,'double') as valueD1, convert(typeS,'int') as valueI1 , convert(typeS,'long') as valueL1 , convert(typeS,'bool') as valueB1, " +85                "        convert(typeF,'string') as valueS2, convert(typeF,'float') as valueF2, convert(typeF,'double') as valueD2, convert(typeF,'int') as valueI2 , convert(typeF,'long') as valueL2 , convert(typeF,'bool') as valueB2, " +86                "        convert(typeD,'string') as valueS3, convert(typeD,'float') as valueF3, convert(typeD,'double') as valueD3, convert(typeD,'int') as valueI3 , convert(typeD,'long') as valueL3 , convert(typeD,'bool') as valueB3, " +87                "        convert(typeI,'string') as valueS4, convert(typeI,'float') as valueF4, convert(typeI,'double') as valueD4, convert(typeI,'int') as valueI4 , convert(typeI,'long') as valueL4 , convert(typeI,'bool') as valueB4, " +88                "        convert(typeL,'string') as valueS5, convert(typeL,'float') as valueF5, convert(typeL,'double') as valueD5, convert(typeL,'int') as valueI5 , convert(typeL,'long') as valueL5 , convert(typeL,'bool') as valueB5, " +89                "        convert(typeB,'string') as valueS6, convert(typeB,'float') as valueF6, convert(typeB,'double') as valueD6, convert(typeB,'int') as valueI6 , convert(typeB,'long') as valueL6 , convert(typeB,'bool') as valueB6  " +90                "insert into outputStream ;";91        ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(cseEventStream + query);92        executionPlanRuntime.addCallback("query1", new QueryCallback() {93            @Override94            public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {95                EventPrinter.print(timeStamp, inEvents, removeEvents);96                count++;97                junit.framework.Assert.assertTrue(inEvents[0].getData(0) instanceof String);98                junit.framework.Assert.assertTrue(inEvents[0].getData(1) == null);99                junit.framework.Assert.assertTrue(inEvents[0].getData(2) == null);100                junit.framework.Assert.assertTrue(inEvents[0].getData(3) == null);101                junit.framework.Assert.assertTrue(inEvents[0].getData(4) == null);102                junit.framework.Assert.assertTrue(inEvents[0].getData(5) instanceof Boolean && !((Boolean) inEvents[0].getData(5)));103                junit.framework.Assert.assertTrue(inEvents[0].getData(6) instanceof String);104                junit.framework.Assert.assertTrue(inEvents[0].getData(7) instanceof Float);105                junit.framework.Assert.assertTrue(inEvents[0].getData(8) instanceof Double);106                junit.framework.Assert.assertTrue(inEvents[0].getData(9) instanceof Integer);107                junit.framework.Assert.assertTrue(inEvents[0].getData(10) instanceof Long);108                junit.framework.Assert.assertTrue(inEvents[0].getData(11) instanceof Boolean && !((Boolean) inEvents[0].getData(11)));109                junit.framework.Assert.assertTrue(inEvents[0].getData(12) instanceof String);110                junit.framework.Assert.assertTrue(inEvents[0].getData(13) instanceof Float);111                junit.framework.Assert.assertTrue(inEvents[0].getData(14) instanceof Double);112                junit.framework.Assert.assertTrue(inEvents[0].getData(15) instanceof Integer);113                junit.framework.Assert.assertTrue(inEvents[0].getData(16) instanceof Long);114                junit.framework.Assert.assertTrue(inEvents[0].getData(17) instanceof Boolean && !((Boolean) inEvents[0].getData(17)));115                junit.framework.Assert.assertTrue(inEvents[0].getData(18) instanceof String);116                junit.framework.Assert.assertTrue(inEvents[0].getData(19) instanceof Float);117                junit.framework.Assert.assertTrue(inEvents[0].getData(20) instanceof Double);118                junit.framework.Assert.assertTrue(inEvents[0].getData(21) instanceof Integer);119                junit.framework.Assert.assertTrue(inEvents[0].getData(22) instanceof Long);120                junit.framework.Assert.assertTrue(inEvents[0].getData(23) instanceof Boolean && !((Boolean) inEvents[0].getData(23)));121                junit.framework.Assert.assertTrue(inEvents[0].getData(24) instanceof String);122                junit.framework.Assert.assertTrue(inEvents[0].getData(25) instanceof Float);123                junit.framework.Assert.assertTrue(inEvents[0].getData(26) instanceof Double);124                junit.framework.Assert.assertTrue(inEvents[0].getData(27) instanceof Integer);125                junit.framework.Assert.assertTrue(inEvents[0].getData(28) instanceof Long);126                junit.framework.Assert.assertTrue(inEvents[0].getData(29) instanceof Boolean && !((Boolean) inEvents[0].getData(29)));127                junit.framework.Assert.assertTrue(inEvents[0].getData(30) instanceof String);128                junit.framework.Assert.assertTrue(inEvents[0].getData(31) instanceof Float);129                junit.framework.Assert.assertTrue(inEvents[0].getData(32) instanceof Double);130                junit.framework.Assert.assertTrue(inEvents[0].getData(33) instanceof Integer);131                junit.framework.Assert.assertTrue(inEvents[0].getData(34) instanceof Long);132                junit.framework.Assert.assertTrue(inEvents[0].getData(35) instanceof Boolean && ((Boolean) inEvents[0].getData(35)));133            }134        });135        InputHandler inputHandler = executionPlanRuntime.getInputHandler("typeStream");136        executionPlanRuntime.start();137        inputHandler.send(new Object[]{"WSO2", 2f, 3d, 4, 5l, true});138        Thread.sleep(100);139        Assert.assertEquals(1, count);140        executionPlanRuntime.shutdown();141    }142    @Test143    public void convertFunctionTest3() throws InterruptedException {144        log.info("convert function test 3");145        SiddhiManager siddhiManager = new SiddhiManager();146        String cseEventStream = "" +147                "@config(async = 'true') " +148                "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB bool) ;";149        String query = "" +150                "@info(name = 'query1') " +151                "from typeStream " +152                "select convert(typeS,'bool') as valueB1, convert(typeF,'bool') as valueB2, convert(typeD,'bool') as valueB3 , convert(typeI,'bool') as valueB4 , convert(typeL,'bool') as valueB5 , convert(typeB,'bool') as valueB6 " +153                "insert into outputStream ;";154        ExecutionPlanRuntime executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(cseEventStream + query);155        executionPlanRuntime.addCallback("query1", new QueryCallback() {156            @Override157            public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {158                EventPrinter.print(timeStamp, inEvents, removeEvents);159                count++;160                junit.framework.Assert.assertTrue(inEvents[0].getData(0) instanceof Boolean && (Boolean) inEvents[0].getData(0));161                junit.framework.Assert.assertTrue(inEvents[0].getData(1) instanceof Boolean && (Boolean) inEvents[0].getData(1));162                junit.framework.Assert.assertTrue(inEvents[0].getData(2) instanceof Boolean && (Boolean) inEvents[0].getData(2));163                junit.framework.Assert.assertTrue(inEvents[0].getData(3) instanceof Boolean && (Boolean) inEvents[0].getData(3));164                junit.framework.Assert.assertTrue(inEvents[0].getData(4) instanceof Boolean && (Boolean) inEvents[0].getData(4));165                junit.framework.Assert.assertTrue(inEvents[0].getData(5) instanceof Boolean && (Boolean) inEvents[0].getData(5));166            }167        });168        InputHandler inputHandler = executionPlanRuntime.getInputHandler("typeStream");169        executionPlanRuntime.start();170        inputHandler.send(new Object[]{"true", 1f, 1d, 1, 1l, true});171        Thread.sleep(100);172        Assert.assertEquals(1, count);173        executionPlanRuntime.shutdown();174    }175    @Test(expected = ExecutionPlanValidationException.class)176    public void convertFunctionTest4() throws InterruptedException {177        log.info("convert function test 4");178        SiddhiManager siddhiManager = new SiddhiManager();179        String cseEventStream = "" +...Source:MultivariateSummaryStatisticsTest.java  
...140		junit.framework.Assert.assertEquals(0, u.getN());141	}142	public void testN0andN1Conditions() throws java.lang.Exception {143		org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(1, true);144		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getMean()[0]));145		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getStandardDeviation()[0]));146		u.addValue(new double[]{ 1 });147		junit.framework.Assert.assertEquals(1.0, u.getMean()[0], 1.0E-10);148		junit.framework.Assert.assertEquals(1.0, u.getGeometricMean()[0], 1.0E-10);149		junit.framework.Assert.assertEquals(0.0, u.getStandardDeviation()[0], 1.0E-10);150		u.addValue(new double[]{ 2 });151		junit.framework.Assert.assertTrue(((u.getStandardDeviation()[0]) > 0));152	}153	public void testNaNContracts() throws org.apache.commons.math.DimensionMismatchException {154		org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(1, true);155		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getMean()[0]));156		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getMin()[0]));157		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getStandardDeviation()[0]));158		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(u.getGeometricMean()[0]));159		u.addValue(new double[]{ 1.0 });160		junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getMean()[0]));161		junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getMin()[0]));162		junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getStandardDeviation()[0]));163		junit.framework.Assert.assertFalse(java.lang.Double.isNaN(u.getGeometricMean()[0]));164	}165	public void testSerialization() throws org.apache.commons.math.DimensionMismatchException {166		org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);167		org.apache.commons.math.TestUtils.checkSerializedEquality(u);168		org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics s = ((org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics)(org.apache.commons.math.TestUtils.serializeAndRecover(u)));169		junit.framework.Assert.assertEquals(u, s);170		u.addValue(new double[]{ 2.0 , 1.0 });171		u.addValue(new double[]{ 1.0 , 1.0 });172		u.addValue(new double[]{ 3.0 , 1.0 });173		u.addValue(new double[]{ 4.0 , 1.0 });174		u.addValue(new double[]{ 5.0 , 1.0 });175		org.apache.commons.math.TestUtils.checkSerializedEquality(u);176		s = ((org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics)(org.apache.commons.math.TestUtils.serializeAndRecover(u)));177		junit.framework.Assert.assertEquals(u, s);178	}179	public void testEqualsAndHashCode() throws org.apache.commons.math.DimensionMismatchException {180		org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics u = createMultivariateSummaryStatistics(2, true);181		org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics t = null;182		int emptyHash = u.hashCode();183		junit.framework.Assert.assertTrue(u.equals(u));184		junit.framework.Assert.assertFalse(u.equals(t));185		junit.framework.Assert.assertFalse(u.equals(java.lang.Double.valueOf(0)));186		t = createMultivariateSummaryStatistics(2, true);187		junit.framework.Assert.assertTrue(t.equals(u));188		junit.framework.Assert.assertTrue(u.equals(t));189		junit.framework.Assert.assertEquals(emptyHash, t.hashCode());190		u.addValue(new double[]{ 2.0 , 1.0 });191		u.addValue(new double[]{ 1.0 , 1.0 });192		u.addValue(new double[]{ 3.0 , 1.0 });193		u.addValue(new double[]{ 4.0 , 1.0 });194		u.addValue(new double[]{ 5.0 , 1.0 });195		junit.framework.Assert.assertFalse(t.equals(u));196		junit.framework.Assert.assertFalse(u.equals(t));197		junit.framework.Assert.assertTrue(((u.hashCode()) != (t.hashCode())));198		t.addValue(new double[]{ 2.0 , 1.0 });199		t.addValue(new double[]{ 1.0 , 1.0 });200		t.addValue(new double[]{ 3.0 , 1.0 });201		t.addValue(new double[]{ 4.0 , 1.0 });202		t.addValue(new double[]{ 5.0 , 1.0 });203		junit.framework.Assert.assertTrue(t.equals(u));204		junit.framework.Assert.assertTrue(u.equals(t));205		junit.framework.Assert.assertEquals(u.hashCode(), t.hashCode());206		u.clear();207		t.clear();208		junit.framework.Assert.assertTrue(t.equals(u));209		junit.framework.Assert.assertTrue(u.equals(t));210		junit.framework.Assert.assertEquals(emptyHash, t.hashCode());211		junit.framework.Assert.assertEquals(emptyHash, u.hashCode());212	}213}...Source:BrentSolverTest.java  
...9		double result;10		org.apache.commons.math.analysis.solvers.UnivariateRealSolver solver = new org.apache.commons.math.analysis.solvers.BrentSolver(f);11		result = solver.solve(3, 4);12		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());13		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 5));14		result = solver.solve(1, 4);15		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());16		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 6));17		solver = new org.apache.commons.math.analysis.solvers.SecantSolver(f);18		result = solver.solve(3, 4);19		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());20		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 5));21		result = solver.solve(1, 4);22		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());23		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 6));24		junit.framework.Assert.assertEquals(result, solver.getResult(), 0);25	}26	public void testSinZero() throws org.apache.commons.math.MathException {27		org.apache.commons.math.analysis.UnivariateRealFunction f = new org.apache.commons.math.analysis.SinFunction();28		double result;29		org.apache.commons.math.analysis.solvers.UnivariateRealSolver solver = new org.apache.commons.math.analysis.solvers.BrentSolver();30		result = solver.solve(f, 3, 4);31		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());32		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 5));33		result = solver.solve(f, 1, 4);34		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());35		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 6));36		solver = new org.apache.commons.math.analysis.solvers.SecantSolver();37		result = solver.solve(f, 3, 4);38		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());39		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 5));40		result = solver.solve(f, 1, 4);41		junit.framework.Assert.assertEquals(result, java.lang.Math.PI, solver.getAbsoluteAccuracy());42		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 6));43		junit.framework.Assert.assertEquals(result, solver.getResult(), 0);44	}45	public void testQuinticZero() throws org.apache.commons.math.MathException {46		org.apache.commons.math.analysis.UnivariateRealFunction f = new org.apache.commons.math.analysis.QuinticFunction();47		double result;48		org.apache.commons.math.analysis.solvers.UnivariateRealSolver solver = new org.apache.commons.math.analysis.solvers.BrentSolver();49		result = solver.solve(f, -0.2, 0.2);50		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());51		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 2));52		result = solver.solve(f, -0.1, 0.3);53		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());54		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 6));55		result = solver.solve(f, -0.3, 0.45);56		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());57		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 7));58		result = solver.solve(f, 0.3, 0.7);59		junit.framework.Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());60		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 7));61		result = solver.solve(f, 0.2, 0.6);62		junit.framework.Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());63		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 7));64		result = solver.solve(f, 0.05, 0.95);65		junit.framework.Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());66		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 9));67		result = solver.solve(f, 0.85, 1.25);68		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());69		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 9));70		result = solver.solve(f, 0.8, 1.2);71		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());72		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 9));73		result = solver.solve(f, 0.85, 1.75);74		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());75		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 11));76		result = solver.solve(f, 0.55, 1.45);77		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());78		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 8));79		result = solver.solve(f, 0.85, 5);80		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());81		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 13));82		solver = new org.apache.commons.math.analysis.solvers.SecantSolver();83		result = solver.solve(f, -0.2, 0.2);84		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());85		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 2));86		result = solver.solve(f, -0.1, 0.3);87		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());88		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 6));89		result = solver.solve(f, -0.3, 0.45);90		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());91		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 7));92		result = solver.solve(f, 0.3, 0.7);93		junit.framework.Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());94		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 8));95		result = solver.solve(f, 0.2, 0.6);96		junit.framework.Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());97		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 7));98		result = solver.solve(f, 0.05, 0.95);99		junit.framework.Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy());100		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 9));101		result = solver.solve(f, 0.85, 1.25);102		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());103		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 11));104		result = solver.solve(f, 0.8, 1.2);105		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());106		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 9));107		result = solver.solve(f, 0.85, 1.75);108		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());109		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 15));110		result = solver.solve(f, 0.55, 1.45);111		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());112		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 8));113		result = solver.solve(f, 0.85, 5);114		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());115		junit.framework.Assert.assertTrue(((solver.getIterationCount()) <= 15));116		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, -0.2, 0.2);117		junit.framework.Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy());118		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, -0.1, 0.3);119		junit.framework.Assert.assertEquals(result, 0, 1.0E-8);120		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, -0.3, 0.45);121		junit.framework.Assert.assertEquals(result, 0, 1.0E-6);122		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.3, 0.7);123		junit.framework.Assert.assertEquals(result, 0.5, 1.0E-6);124		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.2, 0.6);125		junit.framework.Assert.assertEquals(result, 0.5, 1.0E-6);126		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.05, 0.95);127		junit.framework.Assert.assertEquals(result, 0.5, 1.0E-6);128		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.85, 1.25);129		junit.framework.Assert.assertEquals(result, 1.0, 1.0E-6);130		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.8, 1.2);131		junit.framework.Assert.assertEquals(result, 1.0, 1.0E-6);132		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.85, 1.75);133		junit.framework.Assert.assertEquals(result, 1.0, 1.0E-6);134		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.55, 1.45);135		junit.framework.Assert.assertEquals(result, 1.0, 1.0E-6);136		result = org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils.solve(f, 0.85, 5);137		junit.framework.Assert.assertEquals(result, 1.0, 1.0E-6);138	}139	public void testRootEndpoints() throws java.lang.Exception {140		org.apache.commons.math.analysis.UnivariateRealFunction f = new org.apache.commons.math.analysis.SinFunction();141		org.apache.commons.math.analysis.solvers.UnivariateRealSolver solver = new org.apache.commons.math.analysis.solvers.BrentSolver();142		double result = solver.solve(f, java.lang.Math.PI, 4);143		junit.framework.Assert.assertEquals(java.lang.Math.PI, result, solver.getAbsoluteAccuracy());144		result = solver.solve(f, 3, java.lang.Math.PI);145		junit.framework.Assert.assertEquals(java.lang.Math.PI, result, solver.getAbsoluteAccuracy());146		result = solver.solve(f, java.lang.Math.PI, 4, 3.5);147		junit.framework.Assert.assertEquals(java.lang.Math.PI, result, solver.getAbsoluteAccuracy());148		result = solver.solve(f, 3, java.lang.Math.PI, 3.07);149		junit.framework.Assert.assertEquals(java.lang.Math.PI, result, solver.getAbsoluteAccuracy());150	}151	public void testBadEndpoints() throws java.lang.Exception {152		org.apache.commons.math.analysis.UnivariateRealFunction f = new org.apache.commons.math.analysis.SinFunction();153		org.apache.commons.math.analysis.solvers.UnivariateRealSolver solver = new org.apache.commons.math.analysis.solvers.BrentSolver();154		try {155			solver.solve(f, 1, -1);156			junit.framework.Assert.fail("Expecting IllegalArgumentException - bad interval");157		} catch (java.lang.IllegalArgumentException ex) {158		}159		try {160			solver.solve(f, 1, 1.5);161			junit.framework.Assert.fail("Expecting IllegalArgumentException - non-bracketing");162		} catch (java.lang.IllegalArgumentException ex) {163		}164		try {165			solver.solve(f, 1, 1.5, 1.2);166			junit.framework.Assert.fail("Expecting IllegalArgumentException - non-bracketing");167		} catch (java.lang.IllegalArgumentException ex) {168		}169	}170	public void testInitialGuess() throws org.apache.commons.math.MathException {171		org.apache.commons.math.analysis.MonitoredFunction f = new org.apache.commons.math.analysis.MonitoredFunction(new org.apache.commons.math.analysis.QuinticFunction());172		org.apache.commons.math.analysis.solvers.UnivariateRealSolver solver = new org.apache.commons.math.analysis.solvers.BrentSolver();173		double result;174		result = solver.solve(f, 0.6, 7.0);175		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());176		int referenceCallsCount = f.getCallsCount();177		junit.framework.Assert.assertTrue((referenceCallsCount >= 13));178		try {179			result = solver.solve(f, 0.6, 7.0, 0.0);180			junit.framework.Assert.fail("an IllegalArgumentException was expected");181		} catch (java.lang.IllegalArgumentException iae) {182		} catch (java.lang.Exception e) {183			junit.framework.Assert.fail(("wrong exception caught: " + (e.getMessage())));184		}185		f.setCallsCount(0);186		result = solver.solve(f, 0.6, 7.0, 0.61);187		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());188		junit.framework.Assert.assertTrue(((f.getCallsCount()) > referenceCallsCount));189		f.setCallsCount(0);190		result = solver.solve(f, 0.6, 7.0, 0.999999);191		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());192		junit.framework.Assert.assertTrue(((f.getCallsCount()) < referenceCallsCount));193		f.setCallsCount(0);194		result = solver.solve(f, 0.6, 7.0, 1.0);195		junit.framework.Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy());196		junit.framework.Assert.assertEquals(0, solver.getIterationCount());197		junit.framework.Assert.assertEquals(1, f.getCallsCount());198	}199}...Source:SummaryStatisticsTest.java  
...38		junit.framework.Assert.assertEquals("total count", 0, u.getN(), tolerance);39	}40	public void testN0andN1Conditions() throws java.lang.Exception {41		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();42		junit.framework.Assert.assertTrue("Mean of n = 0 set should be NaN", java.lang.Double.isNaN(u.getMean()));43		junit.framework.Assert.assertTrue("Standard Deviation of n = 0 set should be NaN", java.lang.Double.isNaN(u.getStandardDeviation()));44		junit.framework.Assert.assertTrue("Variance of n = 0 set should be NaN", java.lang.Double.isNaN(u.getVariance()));45		u.addValue(one);46		junit.framework.Assert.assertTrue("mean should be one (n = 1)", ((u.getMean()) == (one)));47		junit.framework.Assert.assertTrue(("geometric should be one (n = 1) instead it is " + (u.getGeometricMean())), ((u.getGeometricMean()) == (one)));48		junit.framework.Assert.assertTrue("Std should be zero (n = 1)", ((u.getStandardDeviation()) == 0.0));49		junit.framework.Assert.assertTrue("variance should be zero (n = 1)", ((u.getVariance()) == 0.0));50		u.addValue(twoF);51		junit.framework.Assert.assertTrue("Std should not be zero (n = 2)", ((u.getStandardDeviation()) != 0.0));52		junit.framework.Assert.assertTrue("variance should not be zero (n = 2)", ((u.getVariance()) != 0.0));53	}54	public void testProductAndGeometricMean() throws java.lang.Exception {55		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();56		u.addValue(1.0);57		u.addValue(2.0);58		u.addValue(3.0);59		u.addValue(4.0);60		junit.framework.Assert.assertEquals("Geometric mean not expected", 2.213364, u.getGeometricMean(), 1.0E-5);61	}62	public void testNaNContracts() {63		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();64		junit.framework.Assert.assertTrue("mean not NaN", java.lang.Double.isNaN(u.getMean()));65		junit.framework.Assert.assertTrue("min not NaN", java.lang.Double.isNaN(u.getMin()));66		junit.framework.Assert.assertTrue("std dev not NaN", java.lang.Double.isNaN(u.getStandardDeviation()));67		junit.framework.Assert.assertTrue("var not NaN", java.lang.Double.isNaN(u.getVariance()));68		junit.framework.Assert.assertTrue("geom mean not NaN", java.lang.Double.isNaN(u.getGeometricMean()));69		u.addValue(1.0);70		junit.framework.Assert.assertEquals("mean not expected", 1.0, u.getMean(), java.lang.Double.MIN_VALUE);71		junit.framework.Assert.assertEquals("variance not expected", 0.0, u.getVariance(), java.lang.Double.MIN_VALUE);72		junit.framework.Assert.assertEquals("geometric mean not expected", 1.0, u.getGeometricMean(), java.lang.Double.MIN_VALUE);73		u.addValue(-1.0);74		junit.framework.Assert.assertTrue("geom mean not NaN", java.lang.Double.isNaN(u.getGeometricMean()));75		u.addValue(0.0);76		junit.framework.Assert.assertTrue("geom mean not NaN", java.lang.Double.isNaN(u.getGeometricMean()));77	}78	public void testGetSummary() {79		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();80		org.apache.commons.math.stat.descriptive.StatisticalSummary summary = u.getSummary();81		verifySummary(u, summary);82		u.addValue(1.0);83		summary = u.getSummary();84		verifySummary(u, summary);85		u.addValue(2.0);86		summary = u.getSummary();87		verifySummary(u, summary);88		u.addValue(2.0);89		summary = u.getSummary();90		verifySummary(u, summary);91	}92	public void testSerialization() {93		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();94		org.apache.commons.math.TestUtils.checkSerializedEquality(u);95		org.apache.commons.math.stat.descriptive.SummaryStatistics s = ((org.apache.commons.math.stat.descriptive.SummaryStatistics)(org.apache.commons.math.TestUtils.serializeAndRecover(u)));96		org.apache.commons.math.stat.descriptive.StatisticalSummary summary = s.getSummary();97		verifySummary(u, summary);98		u.addValue(2.0);99		u.addValue(1.0);100		u.addValue(3.0);101		u.addValue(4.0);102		u.addValue(5.0);103		org.apache.commons.math.TestUtils.checkSerializedEquality(u);104		s = ((org.apache.commons.math.stat.descriptive.SummaryStatistics)(org.apache.commons.math.TestUtils.serializeAndRecover(u)));105		summary = s.getSummary();106		verifySummary(u, summary);107	}108	public void testEqualsAndHashCode() {109		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();110		org.apache.commons.math.stat.descriptive.SummaryStatistics t = null;111		int emptyHash = u.hashCode();112		junit.framework.Assert.assertTrue("reflexive", u.equals(u));113		junit.framework.Assert.assertFalse("non-null compared to null", u.equals(t));114		junit.framework.Assert.assertFalse("wrong type", u.equals(java.lang.Double.valueOf(0)));115		t = createSummaryStatistics();116		junit.framework.Assert.assertTrue("empty instances should be equal", t.equals(u));117		junit.framework.Assert.assertTrue("empty instances should be equal", u.equals(t));118		junit.framework.Assert.assertEquals("empty hash code", emptyHash, t.hashCode());119		u.addValue(2.0);120		u.addValue(1.0);121		u.addValue(3.0);122		u.addValue(4.0);123		junit.framework.Assert.assertFalse("different n's should make instances not equal", t.equals(u));124		junit.framework.Assert.assertFalse("different n's should make instances not equal", u.equals(t));125		junit.framework.Assert.assertTrue("different n's should make hashcodes different", ((u.hashCode()) != (t.hashCode())));126		t.addValue(2.0);127		t.addValue(1.0);128		t.addValue(3.0);129		t.addValue(4.0);130		junit.framework.Assert.assertTrue("summaries based on same data should be equal", t.equals(u));131		junit.framework.Assert.assertTrue("summaries based on same data should be equal", u.equals(t));132		junit.framework.Assert.assertEquals("summaries based on same data should have same hashcodes", u.hashCode(), t.hashCode());133		u.clear();134		t.clear();135		junit.framework.Assert.assertTrue("empty instances should be equal", t.equals(u));136		junit.framework.Assert.assertTrue("empty instances should be equal", u.equals(t));137		junit.framework.Assert.assertEquals("empty hash code", emptyHash, t.hashCode());138		junit.framework.Assert.assertEquals("empty hash code", emptyHash, u.hashCode());139	}140	public void testCopy() throws java.lang.Exception {141		org.apache.commons.math.stat.descriptive.SummaryStatistics u = createSummaryStatistics();142		u.addValue(2.0);143		u.addValue(1.0);144		u.addValue(3.0);145		u.addValue(4.0);146		org.apache.commons.math.stat.descriptive.SummaryStatistics v = new org.apache.commons.math.stat.descriptive.SummaryStatistics(u);147		junit.framework.Assert.assertEquals(u, v);148		junit.framework.Assert.assertEquals(v, u);149		junit.framework.Assert.assertTrue(((v.geoMean) == (v.getGeoMeanImpl())));150		junit.framework.Assert.assertTrue(((v.mean) == (v.getMeanImpl())));151		junit.framework.Assert.assertTrue(((v.min) == (v.getMinImpl())));152		junit.framework.Assert.assertTrue(((v.max) == (v.getMaxImpl())));153		junit.framework.Assert.assertTrue(((v.sum) == (v.getSumImpl())));154		junit.framework.Assert.assertTrue(((v.sumsq) == (v.getSumsqImpl())));155		junit.framework.Assert.assertTrue(((v.sumLog) == (v.getSumLogImpl())));156		junit.framework.Assert.assertTrue(((v.variance) == (v.getVarianceImpl())));157		u.addValue(7.0);158		u.addValue(9.0);159		u.addValue(11.0);160		u.addValue(23.0);161		v.addValue(7.0);162		v.addValue(9.0);163		v.addValue(11.0);164		v.addValue(23.0);165		junit.framework.Assert.assertEquals(u, v);166		junit.framework.Assert.assertEquals(v, u);167		u.clear();168		u.setSumImpl(new org.apache.commons.math.stat.descriptive.summary.Sum());169		org.apache.commons.math.stat.descriptive.SummaryStatistics.copy(u, v);170		junit.framework.Assert.assertEquals(u.sum, v.sum);...Source:StorelessUnivariateStatisticAbstractTest.java  
...19		statistic.incrementAll(testArray);20		junit.framework.Assert.assertEquals(expectedValue(), statistic.getResult(), getTolerance());21		junit.framework.Assert.assertEquals(testArray.length, statistic.getN());22		statistic.clear();23		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(statistic.getResult()));24		junit.framework.Assert.assertEquals(0, statistic.getN());25	}26	public void testSerialization() throws java.lang.Exception {27		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic statistic = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(getUnivariateStatistic()));28		org.apache.commons.math.TestUtils.checkSerializedEquality(statistic);29		statistic.clear();30		for (int i = 0 ; i < (testArray.length) ; i++) {31			statistic.increment(testArray[i]);32			if ((i % 5) == 0)33				statistic = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(org.apache.commons.math.TestUtils.serializeAndRecover(statistic)));34			35		}36		org.apache.commons.math.TestUtils.checkSerializedEquality(statistic);37		junit.framework.Assert.assertEquals(expectedValue(), statistic.getResult(), getTolerance());38		statistic.clear();39		junit.framework.Assert.assertTrue(java.lang.Double.isNaN(statistic.getResult()));40	}41	public void testEqualsAndHashCode() {42		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic statistic = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(getUnivariateStatistic()));43		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic statistic2 = null;44		junit.framework.Assert.assertTrue("non-null, compared to null", !(statistic.equals(statistic2)));45		junit.framework.Assert.assertTrue("reflexive, non-null", statistic.equals(statistic));46		int emptyHash = statistic.hashCode();47		statistic2 = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(getUnivariateStatistic()));48		junit.framework.Assert.assertTrue("empty stats should be equal", statistic.equals(statistic2));49		junit.framework.Assert.assertEquals("empty stats should have the same hashcode", emptyHash, statistic2.hashCode());50		statistic.increment(1.0);51		junit.framework.Assert.assertTrue("reflexive, non-empty", statistic.equals(statistic));52		junit.framework.Assert.assertTrue("non-empty, compared to empty", !(statistic.equals(statistic2)));53		junit.framework.Assert.assertTrue("non-empty, compared to empty", !(statistic2.equals(statistic)));54		junit.framework.Assert.assertTrue("non-empty stat should have different hashcode from empty stat", ((statistic.hashCode()) != emptyHash));55		statistic2.increment(1.0);56		junit.framework.Assert.assertTrue("stats with same data should be equal", statistic.equals(statistic2));57		junit.framework.Assert.assertEquals("stats with same data should have the same hashcode", statistic.hashCode(), statistic2.hashCode());58		statistic.increment(java.lang.Double.POSITIVE_INFINITY);59		junit.framework.Assert.assertTrue("stats with different n's should not be equal", !(statistic2.equals(statistic)));60		junit.framework.Assert.assertTrue("stats with different n's should have different hashcodes", ((statistic.hashCode()) != (statistic2.hashCode())));61		statistic2.increment(java.lang.Double.POSITIVE_INFINITY);62		junit.framework.Assert.assertTrue("stats with same data should be equal", statistic.equals(statistic2));63		junit.framework.Assert.assertEquals("stats with same data should have the same hashcode", statistic.hashCode(), statistic2.hashCode());64		statistic.clear();65		statistic2.clear();66		junit.framework.Assert.assertTrue("cleared stats should be equal", statistic.equals(statistic2));67		junit.framework.Assert.assertEquals("cleared stats should have thashcode of empty stat", emptyHash, statistic2.hashCode());68		junit.framework.Assert.assertEquals("cleared stats should have thashcode of empty stat", emptyHash, statistic.hashCode());69	}70	public void testMomentSmallSamples() {71		org.apache.commons.math.stat.descriptive.UnivariateStatistic stat = getUnivariateStatistic();72		if (stat instanceof org.apache.commons.math.stat.descriptive.moment.SecondMoment) {73			org.apache.commons.math.stat.descriptive.moment.SecondMoment moment = ((org.apache.commons.math.stat.descriptive.moment.SecondMoment)(getUnivariateStatistic()));74			junit.framework.Assert.assertTrue(java.lang.Double.isNaN(moment.getResult()));75			moment.increment(1.0);76			junit.framework.Assert.assertEquals(0.0, moment.getResult(), 0);77		} 78	}79	public void testConsistency() {80		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic stat = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(getUnivariateStatistic()));81		stat.incrementAll(testArray);82		junit.framework.Assert.assertEquals(stat.getResult(), stat.evaluate(testArray), getTolerance());83		for (int i = 0 ; i < (smallSamples.length) ; i++) {84			stat.clear();85			for (int j = 0 ; j < (smallSamples[i].length) ; j++) {86				stat.increment(smallSamples[i][j]);87			}88			org.apache.commons.math.TestUtils.assertEquals(stat.getResult(), stat.evaluate(smallSamples[i]), getTolerance());89		}90	}91	public void testCopyConsistency() {92		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic master = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(getUnivariateStatistic()));93		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic replica = null;94		long index = java.lang.Math.round(((java.lang.Math.random()) * (testArray.length)));95		master.incrementAll(testArray, 0, ((int)(index)));96		replica = master.copy();97		junit.framework.Assert.assertTrue(replica.equals(master));98		junit.framework.Assert.assertTrue(master.equals(replica));99		master.incrementAll(testArray, ((int)(index)), ((int)((testArray.length) - index)));100		replica.incrementAll(testArray, ((int)(index)), ((int)((testArray.length) - index)));101		junit.framework.Assert.assertTrue(replica.equals(master));102		junit.framework.Assert.assertTrue(master.equals(replica));103	}104	public void testSerial() {105		org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic s = ((org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic)(getUnivariateStatistic()));106		junit.framework.Assert.assertEquals(s, org.apache.commons.math.TestUtils.serializeAndRecover(s));107	}108}...Source:JsStaticEvalTest.java  
...89    }90  }91  private native void doTestAfterReturn() /*-{92    func();93    @junit.framework.Assert::assertTrue(Z)(result);94    return;95    var result;96    function func() {97      result = true;98    }99  }-*/;100  private native void doTestAfterReturnInBlock() /*-{101    func();102    @junit.framework.Assert::assertTrue(Z)(result);103    return;104    {105      var result;106      function func() {107        result = true;108      }109    }110  }-*/;111  private native void doTestConditionalFalse() /*-{112    func();113    @junit.framework.Assert::assertTrue(Z)(result);114    return;115    var result;116    var toss = false ? function func() {117      result = true;118    } : false;119  }-*/;120  private native void doTestConditionalTrue() /*-{121    func();122    @junit.framework.Assert::assertTrue(Z)(result);123    return;124    var result;125    var toss = true ? true : function func() {126      result = true;127    };128  }-*/;129  private native void doTestForFalse() /*-{130    func();131    @junit.framework.Assert::assertTrue(Z)(result);132    return;133    for (;false;) {134      var result;135      function func() {136        result = true;137      }138    }139  }-*/;140  private native void doTestIfFalse() /*-{141    func();142    @junit.framework.Assert::assertTrue(Z)(result);143    return;144    if (false) {145      var result;146      function func() {147        result = true;148      }149    }150  }-*/;151  private native void doTestOrder1() /*-{152    func();153    @junit.framework.Assert::assertTrue(Z)(result);154    return;155    var result;156    var toss = function func() {157    };158    var toss = function func() {159      result = true;160    };161  }-*/;162  private native void doTestOrder2() /*-{163    var toss = function func() {164    };165    func();166    @junit.framework.Assert::assertTrue(Z)(result);167    return;168    var result;169    var toss = function func() {170      result = true;171    };172  }-*/;173  private native void doTestShortCircuitAnd() /*-{174    func();175    @junit.framework.Assert::assertTrue(Z)(result);176    return;177    var result;178    var toss = false && function func() {179      result = true;180    };181  }-*/;182  private native void doTestShortCircuitOr() /*-{183    func();184    @junit.framework.Assert::assertTrue(Z)(result);185    return;186    var result;187    var toss = true || function func() {188      result = true;189    };190  }-*/;191  private native void doTestWhileFalse() /*-{192    func();193    @junit.framework.Assert::assertTrue(Z)(result);194    return;195    while (false) {196      var result;197      function func() {198        result = true;199      }200    }201  }-*/;202}...LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.
Here are the detailed JUnit testing chapters to help you get started:
You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.
Get 100 minutes of automation test minutes FREE!!
