示例#1
0
  @Test
  public void testReadmesExample() throws Exception {
    // extract the example script
    final File readme = new File("README.md");
    final String contents = new String(FileUtils.readFile(readme), "UTF-8");
    final String telltale = String.format("```python%n");
    final int begin = contents.indexOf(telltale) + telltale.length();
    assertTrue(begin > telltale.length());
    assertTrue(contents.indexOf(telltale, begin) < 0);
    final int end = contents.indexOf(String.format("```%n"), begin);
    assertTrue(end > 0);
    final String snippet = contents.substring(begin, end);
    assertTrue(snippet.startsWith("# @ImageJ ij"));

    final Context context = new Context();
    final ScriptService script = context.getService(ScriptService.class);

    // create mock ImageJ gateway
    script.addAlias("ImageJ", Mock.class);
    final ScriptModule module = script.run("op-example.py", snippet, true).get();
    assertNotNull(module);
    module.run();

    final Mock ij = context.getService(Mock.class);
    assertEquals(3, ij.images.size());
    assertEquals(11.906, ij.getPixel("sinusoid", 50, 50), 1e-3);
    assertEquals(100, ij.getPixel("gradient", 50, 50), 1e-3);
    assertEquals(111.906, ij.getPixel("composite", 50, 50), 1e-3);
  }
 @Test
 public void testRot13() throws Exception {
   final Context context = new Context(ScriptService.class);
   final ScriptService scriptService = context.getService(ScriptService.class);
   final ScriptLanguage hello = scriptService.getLanguageByName("Hello");
   assertNotNull(hello);
   final ScriptLanguage rot13 = scriptService.getLanguageByName("Rot13");
   assertEquals(hello, rot13);
   assertEquals("Svool", rot13.getScriptEngine().eval("Hello"));
 }
 @Test
 public void testScriptModuleValue() throws Exception {
   final Context context = new Context(ScriptService.class);
   final ScriptService scriptService = context.getService(ScriptService.class);
   final ScriptModule module =
       scriptService
           .run("test.rot13", ScriptModule.class.getName(), false, (Map<String, Object>) null)
           .get();
   final ScriptModule scriptModule = Rot13Engine.latestModule;
   assertEquals(module, scriptModule);
   assertNotNull(scriptModule);
   final ScriptInfo info = scriptModule.getInfo();
   assertEquals(context, info.context());
 }
示例#4
0
文件: Helper.java 项目: smorsi/imagej
 public static Dataset makeDataset(final Context context, final byte[][] data, final String name) {
   final int w = data.length;
   final int h = data[0].length;
   final ArrayImg<ByteType, ByteArray> img =
       new ArrayImgFactory<ByteType>().createByteInstance(new long[] {w, h}, 1);
   final ByteType t = new ByteType(img);
   img.setLinkedType(t);
   final RandomAccess<ByteType> ra = img.randomAccess();
   for (int i = 0; i < w; i++) {
     ra.setPosition(i, 0);
     for (int j = 0; j < h; j++) {
       ra.setPosition(j, 1);
       ra.get().set(data[i][j]);
     }
   }
   final DatasetService datasetService = context.getService(DatasetService.class);
   return datasetService.create(new ImgPlus<ByteType>(img, name, new AxisType[] {Axes.X, Axes.Y}));
 }