Search in sources :

Example 36 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class EvaluatorBaseTest method shouldDivide16By2.

@Test
public void shouldDivide16By2() throws Exception {
    // given
    String code = codeForDivide16By2();
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult result = evaluator().evaluate(seo, code);
    // then
    assertThat(result.result().toString()).isEqualTo("8");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 37 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class ScalaAutocompleteTest method autocomplete_interpretedResultsVisible.

@Test
public void autocomplete_interpretedResultsVisible() {
    // This test needs a fresh ScalaEvaluator to modify without disturbing other tests
    final ScalaEvaluator localEvaluator = new ScalaEvaluator("id", "sid", null, cellExecutor(), new NoBeakerxObjectTestFactory(), getTestTempFolderFactory(), EvaluatorTest.KERNEL_PARAMETERS);
    try {
        // when
        localEvaluator.evaluate(new SimpleEvaluationObject(""), "val xyzzy = 32");
        AutocompleteResult autocomplete = localEvaluator.autocomplete("xyz", 3);
        // then
        Assertions.assertThat(autocomplete.getMatches()).isNotEmpty();
    } finally {
        localEvaluator.exit();
    }
}
Also used : SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) AutocompleteResult(com.twosigma.beakerx.autocomplete.AutocompleteResult) Test(org.junit.Test) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 38 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class ScalaEvaluatorTest method javaImports_shouldBeAdjustedForScala.

@Test
public void javaImports_shouldBeAdjustedForScala() throws Exception {
    // given
    Map<String, Object> paramMap = new HashMap<>();
    // This import tests both "static" removal and "object" escaping.
    List<String> imports = Arrays.asList("import static com.twosigma.beakerx.scala.evaluator.object.ImportTestHelper.staticMethod");
    paramMap.put(IMPORTS, imports);
    EvaluatorParameters kernelParameters = new EvaluatorParameters(paramMap);
    // when
    scalaEvaluator.setShellOptions(kernelParameters);
    String code = "val x = staticMethod()";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    TryResult evaluate = scalaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) HashMap(java.util.HashMap) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 39 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class ScalaEvaluatorTest method evaluatePlot_shouldCreatePlotObject.

@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
    // given
    String code = "import com.twosigma.beakerx.chart.xychart.Plot;\n" + "val plot = new Plot();\n" + "plot.setTitle(\"test title\");";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = scalaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result() instanceof Plot).isTrue();
    assertThat(((Plot) evaluate.result()).getTitle()).isEqualTo("test title");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) Plot(com.twosigma.beakerx.chart.xychart.Plot) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 40 with SimpleEvaluationObject

use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.

the class KotlinEvaluatorTest method evaluatePlot_shouldCreatePlotObject.

@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
    // given
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put(IMPORTS, asList("import com.twosigma.beakerx.chart.xychart.*"));
    evaluator.setShellOptions(new EvaluatorParameters(paramMap));
    String code = "val plot = Plot()\n" + "plot.setTitle(\"test title\");\n" + "plot.display();";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = evaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : EvaluatorParameters(com.twosigma.beakerx.kernel.EvaluatorParameters) HashMap(java.util.HashMap) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Aggregations

SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)57 TryResult (com.twosigma.beakerx.TryResult)37 Test (org.junit.Test)33 Message (com.twosigma.beakerx.message.Message)9 KernelTest (com.twosigma.beakerx.KernelTest)7 PlainCode.createSimpleEvaluationObject (com.twosigma.beakerx.kernel.PlainCode.createSimpleEvaluationObject)5 HashMap (java.util.HashMap)4 EvaluatorParameters (com.twosigma.beakerx.kernel.EvaluatorParameters)3 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 Plot (com.twosigma.beakerx.chart.xychart.Plot)2 MagicCommandOutcomeItem (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem)2 MessageHolder (com.twosigma.beakerx.kernel.msg.MessageHolder)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 Before (org.junit.Before)2 AutocompleteResult (com.twosigma.beakerx.autocomplete.AutocompleteResult)1 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)1 Code (com.twosigma.beakerx.kernel.Code)1 KernelFunctionality (com.twosigma.beakerx.kernel.KernelFunctionality)1