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");
}
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();
}
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");
}
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();
}
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();
}
Aggregations