Search in sources :

Example 41 with SimpleEvaluationObject

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

the class KotlinEvaluatorTest method returnFromFunction.

@Test
public void returnFromFunction() throws Exception {
    // given
    String code = "" + "val a = 2.2\n" + "val b = 14\n" + "\n" + "val f = {x: Double -> a*x + b}\n" + "\n" + "println(f(2.0))\n" + "f(2.0)";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = evaluator.evaluate(seo, code);
    // then
    assertThat((Double) evaluate.result()).isEqualTo(18.4);
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 42 with SimpleEvaluationObject

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

the class KotlinEvaluatorTest method javaImports_shouldBeAdjustedForKotlin.

@Test
public void javaImports_shouldBeAdjustedForKotlin() throws Exception {
    // given
    Map<String, Object> paramMap = new HashMap<>();
    // This import tests both "static" removal and "object" escaping.
    List<String> imports = asList("import static com.twosigma.beakerx.kotlin.evaluator.object.ImportTestHelper.staticMethod");
    paramMap.put(IMPORTS, imports);
    EvaluatorParameters kernelParameters = new EvaluatorParameters(paramMap);
    // when
    evaluator.setShellOptions(kernelParameters);
    String code = "val x = staticMethod()";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    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)

Example 43 with SimpleEvaluationObject

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

the class SQLEvaluatorTest method evaluateSql.

@Test
public void evaluateSql() throws Exception {
    // given
    SimpleEvaluationObject seo = new SimpleEvaluationObject(SQLForColorTable.CREATE_AND_SELECT_ALL);
    // when
    TryResult evaluate = sqlEvaluator.evaluate(seo, seo.getExpression());
    // then
    verifyResult(evaluate);
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 44 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method onlyPackage.

@Test
public void onlyPackage() throws Exception {
    // given
    String code = "package beaker.test;";
    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 45 with SimpleEvaluationObject

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

the class JavaEvaluatorTest method noCode.

@Test
public void noCode() throws Exception {
    // given
    String code = "";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate).isNotNull();
}
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