Package test.list.types

Examples of test.list.types.Module


  public void run() {
    String[] strs = new String[8];
    Modules[] mods = new Modules[8];
    Module[] mod = new Module[8];
    Module m = factory.makeModule_Default("amodule");
    ModuleList l;
    boolean exceptionThrown = false;

    try {
      mods[0] = factory.ModulesFromTerm(factory.getPureFactory().parse("meuk([\"m1\",\"m2\",\"m3\",\"m4\"])"));
    }
    catch (RuntimeException e) {
      exceptionThrown = true;
    }

    testAssert(exceptionThrown, "negative fromTermTest");
    exceptionThrown = false;

    mods[0] = factory.ModulesFromTerm(factory.getPureFactory().parse("[\"m1\",\"m2\",\"m3\",\"m4\"]"));

    mod[0] = mods[0].getHead();
    testAssert("\"m1\"".equals(mod[0].toString()), "getFirstTest");

    testAssert(mods[0].hasTail(), "hasTail test");

    mods[4] = mods[0].getTail();
    testAssert("[\"m2\",\"m3\",\"m4\"]".equals(mods[4].toString()), "getNextTest");

    mods[1] = factory.makeModules(m, factory.makeModules());
    strs[1] = mods[1].toString();
    testAssert("[\"amodule\"]".equals(strs[1]), "toStringTest1");

    mods[2] = factory.makeModules(m, mods[1]);
    strs[2] = mods[2].toString();
    testAssert("[\"amodule\",\"amodule\"]".equals(strs[2]), "toStringTest2");

    mods[3] = factory.makeModules(m, mods[2]);
    strs[3] = mods[3].toString();
    testAssert("[\"amodule\",\"amodule\",\"amodule\"]".equals(strs[3]), "toStringTest3");

    l = factory.makeModuleList_Modules(mods[3]);
    strs[4] = l.toString();

    testAssert("list([\"amodule\",\"amodule\",\"amodule\"])".equals(strs[4]), "toStringTest4");

    /*
     * If the hash code generator does not generate different hash codes
     * for these two constructors (they have the same pattern, same
     * alternative name, but a different type) then a ClassCastException
     * will occurr:
     */
    l = factory.makeModuleList_Modules(mods[3]);
    testAssert(l.isSortModuleList() == true, "is<type> test");
    testAssert(l.isModules() == true, "is<cons> test");

    String example = "[]";
    ATerm termExample;

    try {
      termExample = factory.getPureFactory().parse(example);
      testAssert(termExample != null, "need reference to prevent gc");
      mods[4] = factory.makeModules();
    }
    catch (ClassCastException ex) {
      testAssert(false, "ClassCastException occurred due to wrong equivalence implementation");
    }

    example = "\"amodule\"";
    termExample = factory.getPureFactory().parse(example);
    Module amodule = factory.makeModule_Default(example);
    testAssert(amodule != null, "test cast");

    ATerm pattern =
      factory.getPureFactory().parse(
        "[\"m1\",l(\"l1\"),\"sep\",l(\"l2\"),\"m2\",l(\"l3\"),\"sep\",l(\"l4\"),\"m3\",l(\"l5\"),\"sep\",l(\"l6\"),\"m4\"]");

    Separated sep = factory.SeparatedFromTerm(pattern);
    testAssert(sep.toTerm().isEqual(pattern), " fromTerm == toTerm separated lists");

    ATerm patternReversed =
      factory.getPureFactory().parse(
        "[\"m4\",l(\"l5\"),\"sep\",l(\"l6\"),\"m3\",l(\"l3\"),\"sep\",l(\"l4\"),\"m2\",l(\"l1\"),\"sep\",l(\"l2\"),\"m1\"]");
    Separated sepReversed = factory.SeparatedFromTerm(patternReversed);
    testAssert(sep.reverse().isEqual(sepReversed), " separated reverse test");
    testAssert(sep.reverseSeparated().toTerm().isEqual(patternReversed), "separated reverse toTerm test");

    Module head = sep.getHead();

    testAssert(head.isEqual(factory.makeModule_Default("m1")), "separator from term test, head");
    Layout l1 = sep.getWsl();
    testAssert(l1.isEqual(factory.makeLayout_Default("l1")), "getSeparator test l1");
    Layout l2 = sep.getWsr();
    testAssert(l2.isEqual(factory.makeLayout_Default("l2")), "getSeparator test l2");
    Module second = sep.getTail().getHead();
    testAssert(second.isEqual(factory.makeModule_Default("m2")), "separator from term test, second element");
    Layout l3 = sep.getTail().getWsl();

    testAssert(l3.isEqual(factory.makeLayout_Default("l3")), "getSeparator test l3");
    Layout l4 = sep.getTail().getWsr();
    testAssert(l4.isEqual(factory.makeLayout_Default("l4")), "getSeparator test l4");

    testAssert(sep.getLength() == 4, "separated list length test");

    sep = factory.makeSeparated();
    testAssert(sep.toTerm().isEqual(factory.getPureFactory().makeList()), "empty separated list");

    m = factory.makeModule_Default("m");
    sep = factory.makeSeparated(m);

    testAssert(sep.toTerm().isEqual(factory.getPureFactory().makeList(m.toTerm())), "singleton separated list");

    Module m2 = factory.makeModule_Default("m2");
    l1 = factory.makeLayout_Default("l1");
    l2 = factory.makeLayout_Default("l2");
    sep = factory.makeSeparated(m, l1, l2, factory.makeSeparated(m2));

    ATerm p = factory.getPureFactory().parse("[\"m\",l(\"l1\"),\"sep\",l(\"l2\"),\"m2\"]");
View Full Code Here


    for (int i = 0; i < 10; i++) {
      list = list.insert(factory.makeModule_Default("m" + i));
    }

    for (int i = 0; i < list.getLength(); i++) {
      Module m = factory.makeModule_Default("m" + (list.getLength() - i - 1));
      testAssert(list.elementAt(i).equals(m), "list element at " + i);
      testAssert(list.getModuleAt(i).equals(m), "typed list element at " + i);
    }
  }
View Full Code Here

      testAssert(list.getModuleAt(i).equals(m), "typed list element at " + i);
    }
  }

  private void testAppend() {
    Module m = factory.makeModule_Default("m");
    Modules list = factory.makeModules();

    list = list.append(m);
    testAssert(list.equals(factory.makeModules(m)), "append to empty list");

    Module q = factory.makeModule_Default("q");
    list = list.append(q);
    testAssert(list.equals(factory.makeModules(m, q)), "append to singleton list");
  }
View Full Code Here

    list = list.append(q);
    testAssert(list.equals(factory.makeModules(m, q)), "append to singleton list");
  }

  private void testConcat() {
    Module m[] = new Module[3];
    for (int i = 0; i < m.length; i++) {
      m[i] = factory.makeModule_Default("m" + i);
    }

    Modules list = factory.makeModules(m[0], m[1], m[2]);
View Full Code Here

    testAssert(concatenated.getLength() == 2 * list.getLength(), "length concatenated lists");
    testAssert(concatenated.equals(factory.makeModules(m[0], m[1], m[2], m[0], m[1], m[2])), "concatenated lists");
  }

  private void testReverse() {
    Module m[] = new Module[3];
    for (int i = 0; i < m.length; i++) {
      m[i] = factory.makeModule_Default("m" + i);
    }

    Modules forward = factory.makeModules(m[0], m[1], m[2]);
View Full Code Here

    Modules ml = reverse.reverseModules();
    testAssert(forward.equals(ml), "typed reverse list");
  }

  private void testMakeLists() {
    Module m[] = new Module[6];

    for (int i = 0; i < m.length; i++) {
      m[i] = factory.makeModule_Default("m" + i);
    }
View Full Code Here

    testAssert(list[0] == list[0].setAnnotations(list[0].getAnnotations()),"empty-1");

  }

  private void testMakeSeparatedLists() {
    Module m[] = new Module[6];

    for (int i = 0; i < 6; i++) {
      m[i] = factory.makeModule_Default("m" + i);
    }
    Layout l = factory.makeLayout_Default("l");
View Full Code Here

  private void testSeparatedElementAt() {
    Separated triple =
      factory.SeparatedFromString("[\"m0\",l(\" \"),\"sep\",l(\" \"),\"m1\",l(\" \"),\"sep\",l(\" \"),\"m2\"]");

    for (int i = 0; i < 3; i++) {
      Module m = (Module) triple.elementAt(i);
      Module ref = factory.makeModule_Default("m" + i);
      testAssert(m.isEqual(ref), "elementAt " + i);

      m = triple.getModuleAt(i);
      testAssert(m.isEqual(ref), "getModuleAt " + i);
    }
View Full Code Here

    }
  }

  private void testSeparatedAppend() {
    Separated empty = factory.makeSeparated();
    Module m = factory.makeModule_Default("m");
    Layout l = factory.makeLayout_Default(" ");
    Separated single = empty.append(l, l, m);

    testAssert(single.isEqual(factory.SeparatedFromString("[\"m\"]")), "test append on empty list");
View Full Code Here

      twin.isEqual(factory.SeparatedFromString("[\"m\",l(\" \"),\"sep\",l(\" \"),\"m\"]")),
      "append on singleton");
  }

  private void testNineSeps() {
    Module m = factory.makeModule_Default("m");
    Module m2 = factory.makeModule_Default("m2");
    NineSeps ns = factory.makeNineSeps(m, factory.makeNineSeps(m2));

    testAssert(
      ns.toTerm().isEqual(factory.getPureFactory().parse("[\"m\",1,2,3,4,5,6,7,8,9,\"m2\"]")),
      "many separated toTerm");
View Full Code Here

TOP

Related Classes of test.list.types.Module

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.