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

📄 regression.java

📁 jena2.5.4推理机系统的一种最基本实现 HP实验室出品
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
    (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
    [See end of file]
    $Id: Regression.java,v 1.25 2007/01/02 11:49:22 andy_seaborne Exp $
 */

package com.hp.hpl.jena.regression;

import com.hp.hpl.jena.rdf.model.impl.*;
import com.hp.hpl.jena.rdf.model.*;

import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.shared.*;
import com.hp.hpl.jena.graph.*;

import java.net.*;
import java.util.*;
import java.io.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/** A common set of regression tests. [Now being factored out into the
 * NewRegression suite; kers.]
 *
 * @author  bwm
 * @version Release='$Name:  $' Revision='$Revision: 1.25 $' Date='$Date: 2007/01/02 11:49:22 $'
 */
public class Regression extends Object {

    protected boolean errors = false;

    public static void doTest(Model m1, Model m2, Model m3, Model m4) {
        (new Regression()).test(m1, m2, m3, m4);
    }

    protected static Log logger = LogFactory.getLog( Regression.class );

    /** Run the whole batch of common tests on a model implementation
     * @param m an instance of the model to be tested
     */
    public void test(Model m1, Model m2, Model m3, Model m4) {
        try {
            StmtIterator iter = m1.listStatements();
            while (iter.hasNext()) {
                iter.nextStatement();
                iter.remove();
            }

            iter = m2.listStatements();
            while (iter.hasNext()) {
                iter.nextStatement();
                iter.remove();
            }

            iter = m3.listStatements();
            while (iter.hasNext()) {
                iter.nextStatement();
                iter.remove();
            }

            iter = m4.listStatements();
            while (iter.hasNext()) {
                iter.nextStatement();
                iter.remove();
            }
        } catch (Exception e) {
            System.out.println(e);
            errors = true;
        }

        test1(m1);
        test2(m1);
        test3(m1);
        test4(m1);
        test5(m1);  // leaves m empty if successful
        test6(m1);
        test7(m1,m2);
        test8(m1);
        test9(m2);
        test10(m3);
        test11(m1,m2);
        test12(m1);
        test13(m1);
        test14(m1);
        test15(m1);
        test16(m1);
        test17(m1);
        test18(m4);
        test19(m2,m3);
//        test20(m4);  reification is not working
        test97(m4);
 //       test98(m1);
    }

    /** Test Literal creation methods
     * @param m the model implementation under test
     */
    public void test1(Model m) {
        Literal l;
        String  test = "Test1";
        int     n = 0;
//        System.out.println("Beginning " + test);
        try {
            {
                n = 100;
                n++; if (! m.createLiteral(true).getBoolean()) error(test, n);
                n++; if (  m.createLiteral(false).getBoolean()) error(test, n);
            }

            {
                n = 200;
                byte tv = 0;

                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = -1;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Byte.MIN_VALUE;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Byte.MAX_VALUE;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);
            }

            {
                n = 300;
                short tv;

                tv = 0;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = -1;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Short.MIN_VALUE;
                l = m.createLiteral(tv);
                try {
                    n++; if (l.getByte() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Short.MAX_VALUE;
                l = m.createLiteral(tv);
                try {
                    n++; if (l.getByte() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);
            }

            {
                n = 400;
                int tv;

                tv = 0;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = -1;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Integer.MIN_VALUE;
                l = m.createLiteral(tv);
                try {
                    n++; if (l.getByte() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                try {
                    n++; if (l.getShort() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Integer.MAX_VALUE;
                l = m.createLiteral(tv);
                try {
                    n++; if (l.getByte() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                try {
                    n++; if (l.getShort() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);
            }

            {
                n = 500;
                long tv;

                tv = 0;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = -1;
                l = m.createLiteral(tv);
                n++; if (l.getByte() != tv) error(test, n);
                n++; if (l.getShort() != tv) error(test, n);
                n++; if (l.getInt() != tv) error(test, n);
                n++; if (l.getLong() != tv) error(test, n);

                tv = Long.MIN_VALUE;
                l = m.createLiteral(tv);
                try {
                    n++; if (l.getByte() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                try {
                    n++; if (l.getShort() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                try {
                    n++; if (l.getInt() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                n++; if (l.getLong() != tv) error(test, n);

                tv = Long.MAX_VALUE;
                l = m.createLiteral(tv);
                try {
                    n++; if (l.getByte() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                try {
                    n++; if (l.getShort() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                try {
                    n++; if (l.getInt() != tv) error(test, n);
            } catch (NumberFormatException e) {}
                n++; if (l.getLong() != tv) error(test, n);
            }

            {
                float tv;
                float maxerror = (float) 0.00005;
                n = 600;

                tv = (float) 0.0;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror) error(test, n);

                tv = (float) -1.0;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror) error(test, n);

                tv = (float) 12345.6789;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror) error(test, n);

                tv = Float.MAX_VALUE;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror) error(test, n);

                tv = Float.MIN_VALUE;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getFloat() - tv) >= maxerror) error(test, n);
            }
            {
                double tv;
                double maxerror = (double) 0.000000005;
                n = 700;

                tv = (double) 0.0;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror) error(test, n);

                tv = (double) -1.0;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror) error(test, n);

                tv = (double) 12345.67890;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror) error(test, n);

                tv = Double.MAX_VALUE;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror) error(test, n);

                tv = Double.MIN_VALUE;
                l = m.createLiteral(tv);
                n++; if (java.lang.Math.abs(l.getDouble() - tv) >= maxerror) error(test, n);
            }

            {
                char tv;
                n = 800;

                tv = 'A';
                n++; if (m.createLiteral(tv).getChar() != tv) error(test, n);

                tv = 'a';
                n++; if (m.createLiteral(tv).getChar() != tv) error(test, n);

                tv = '#';
                n++; if (m.createLiteral(tv).getChar() != tv) error(test, n);

                tv = '@';
                n++; if (m.createLiteral(tv).getChar() != tv) error(test, n);
            }

            {
                String language = "en";
                String tv;
                n = 900;

                tv = "";
                n++; if (! m.createLiteral(tv).getString()
                                                .equals(tv)) error(test, n);

                tv = "A test string";
                n++; if (! m.createLiteral(tv).getString()
                                                  .equals(tv)) error(test, n);

                tv = "Another test string";
                n++; l = m.createLiteral(tv);
                n++; if (! l.getString().equals(tv)) error(test, n);
                n++; if (! (l.getLanguage().equals(""))) error(test,n);
                n++; l = m.createLiteral(tv, language);

⌨️ 快捷键说明

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