コード例 #1
0
 @Test
 public void testStringArray() {
   final IREXP libraryREXP =
       PlainJavaConnectionTestSuiteContext.getInstance()
           .acquireRConnection()
           .eval(
               new StringBuffer()
                   .append("try(")
                   .append("c(\"string\",\"string2\")")
                   .append(")")
                   .toString());
   Assert.assertNotNull(libraryREXP);
   Assert.assertEquals(IREXP.XT_ARRAY_STR, libraryREXP.getType());
   final String[] sArray = libraryREXP.asStringArray();
   Assert.assertNotNull(sArray);
   Assert.assertEquals("string", sArray[0]);
   Assert.assertEquals("string2", sArray[1]);
 }
コード例 #2
0
  @Test
  public void testList() {
    final IREXP libraryREXP =
        PlainJavaConnectionTestSuiteContext.getInstance()
            .acquireRConnection()
            .eval(new StringBuffer().append("try(").append("library()").append(")").toString());

    Assert.assertEquals(IREXP.XT_MAP, libraryREXP.getType());
    final IRMap namedRList = libraryREXP.asMap();
    final String[] keys = namedRList.keys();
    Assert.assertEquals("header", keys[0]);
    Assert.assertEquals("results", keys[1]);
    Assert.assertEquals("footer", keys[2]);
    final IREXP header = namedRList.at("header");
    Assert.assertTrue(header.getType() == IREXP.XT_NULL);
    final IREXP footer = namedRList.at("footer");
    Assert.assertTrue(footer.getType() == IREXP.XT_NULL);
    final IREXP results = namedRList.at("results");
    Assert.assertNotNull(results.dim());
    Assert.assertEquals(3, results.dim()[1]);
    Assert.assertTrue(results.getType() == IREXP.XT_ARRAY_STR);
    Assert.assertTrue(results.length() > 1);
    final String[] strings = results.asStringArray();
    final int rows = results.dim()[0];
    Assert.assertEquals(rows * 3, results.length());

    final List<Library> libs = new ArrayList<Library>();
    for (int i = 0; i < rows; i++) {
      final Library lib = new Library();
      lib.name = strings[i];
      lib.active = false; // loadedLibraries.contains(lib.name);
      lib.lib = strings[i + rows];
      lib.desc = strings[i + 2 * rows];
      libs.add(lib);
    }
  }