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

📄 icltermtest.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
package com.sri.oaa2.test.icl;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Writer;

import com.sri.oaa2.icl.IclDataQ;
import com.sri.oaa2.icl.IclTerm;
import junit.framework.Assert;
import junit.framework.TestCase;

/**
 * Author: Chris Brigham (cbrigham)
 * (some code borrowed from Balen Gore's original tests)
 * Date: Jun 29, 2004
 * Time: 1:45:21 PM
 * Description: TestCase for IclTerm class that tests parsing icl terms
 * to strings and back again.
 */
public class IclTermTest extends TestCase {
    private static final String[] strings = new String[]{
        "a",
        "1",
        "1.0",
        "V",
        "goal(_x,_y,_z)",
        "_",
        "hello(there)",
        "{hello}",
        "[hello]",
        "'spaces spaces'",
        "a + b",
        "a :- b",
        ":-(a,b)",
        "{hello,there}",
        "[hello, there]",
        "{g1, 5, _9}",
        "'blah''blah'",
        "hello([there,blah, blah],'blah''blah',{1.5, another(struct,[nested])})",
        "icldataq(\"blah blah\")",
        "<(_6025,43)",
        "卢(卢卢)",
        "卢",
        "锣",
        "卢(锣)",
        ":*",
        "\\=*",
        "=*++=",
        "<+",
        ">+",
        "=.?",
        ">=(a,b)",
        "\\=(a,b)",
        //"a \\= b",
        "\\==(a,b)",
        "\\***",
        "[a|V]",
        "+(a,b)",
        "++(a,b)",
        //"a is b",
        ">=\\",
        "++(++,b)",
    };

    public IclTermTest(String arg) {
        super(arg);
    }

    private PrintWriter output;
    
    protected void setUp() throws Exception
    {
      super.setUp();
      try {
        this.output = new PrintWriter(new FileWriter(File.createTempFile("testoutput", null, new File(".")), true));
      }
      catch(Exception e) {
        throw new RuntimeException(e);
      }
    }

    protected void tearDown() throws Exception
    {
      super.tearDown();
      this.output.close();
    }

    /**
     * Test the FromString() method by creating a number of IclTerm objects from the strings[] array,
     * reparsing their toString() equivalents into another IclTerm object, and comparing the two.
     * IclDataQ objects output a different toString, so they must be identified and tested using
     * getQuotedData() instead of toString().
     */
    public void testFromString() {

        for (int i = 0; i < strings.length; ++i) {
          IclTerm t = null;
            try {
                t = IclTerm.fromString(strings[i]);
                Assert.assertTrue(t != null);
                this.output.println("test string #" + i + ": " + t.toString());

                /* toString() for IclDataQ objects is treated differently, so test must be different */
                if (t instanceof IclDataQ) {
                    //System.out.println("reparse: " + ((IclDataQ) t).getQuotedData());
                    Assert.assertTrue("parsed term does not reparse to equal input",
                            t.equals(IclTerm.fromString(((IclDataQ) t).getQuotedData())));
                } else {
                    Assert.assertTrue("parsed term does not reparse to equal input: " + t.toString() + ", " + strings[i],
                            t.equals(IclTerm.fromString(t.toString())));
                }
            } catch (Exception e) {
                this.output.println("Bad String " + strings[i] + " " + t + " " + e.toString());
                e.printStackTrace();
                TestCase.assertTrue(false);
            }
        }

        IclTerm t = IclTerm.fromString(true, "");
        TestCase.assertTrue(t == null);

    }

    public void testEquals() {
        IclTerm t1, t2;
        IclTerm badcomp = IclTerm.fromString(true, "goal(23,_,next([1.0,icldataq(\"12345\"),X]),'str ing')");

        //t1 = IclTerm.fromString(true,"a(_1,_1)");
        //t2 =IclTerm.fromString(true,"a(b,c)");
        //System.out.println(Unifier.getInstance().unify(t1,t2));
        //System.out.println(t1.equals(t2));

        for (int i = 0; i < strings.length; i++) {
            t1 = IclTerm.fromString(true, strings[i]);
            t2 = IclTerm.fromString(true, strings[i]);

            //System.out.println((i+1)+":t1: "+t1);
            //System.out.println((i+1)+":t2: "+t2);
            //System.out.println(Unifier.getInstance().unify(t1,t2));

            Assert.assertTrue((i + 1) + ".1", !t1.equals(null));
            Assert.assertTrue((i + 1) + ".2", !t1.equals(badcomp));
            Assert.assertTrue((i + 1) + ".3", t1.equals(t1));
            Assert.assertEquals((i + 1) + ".4", t1.equals(t2), t2.equals(t1));
        }
    }

}

⌨️ 快捷键说明

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