Search in sources :

Example 16 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method evaluateDivisionByZero_shouldReturnArithmeticException.

@Test
public void evaluateDivisionByZero_shouldReturnArithmeticException() throws Exception {
    // given
    String code = "return 16/0;";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.error()).contains("java.lang.ArithmeticException");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 17 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method evaluateStreamInMultipleLines.

@Test
public void evaluateStreamInMultipleLines() throws Exception {
    // given
    String code = "import java.util.stream.Stream;\n" + "return Stream.of(1, 2, 3, 4).map(i -> { \n" + "    return i * 10;\n" + "});";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNotNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 18 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method evaluatePlot_shouldCreatePlotObject.

@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
    // given
    String code = "import com.twosigma.beakerx.chart.xychart.*;\n" + "Plot plot = new Plot(); plot.setTitle(\"test title\");\n" + "return plot;";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.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 19 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method singleImport.

@Test
public void singleImport() throws Exception {
    // given
    String code = "import java.util.Date;";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 20 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method evaluateVoid.

@Test
public void evaluateVoid() throws Exception {
    // given
    String code = "System.out.println(\"Hello\");";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) 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