-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f815f49
commit 595e0a8
Showing
44 changed files
with
814 additions
and
400 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
.../src/test/java/org/enso/interpreter/node/expression/builtin/number/decimal/FloatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package org.enso.interpreter.node.expression.builtin.number.decimal; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import java.math.BigInteger; | ||
import org.enso.interpreter.runtime.data.EnsoMultiValue; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.interpreter.runtime.error.PanicException; | ||
import org.enso.interpreter.runtime.number.EnsoBigInteger; | ||
import org.enso.interpreter.test.WrappedPrimitive; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.enso.test.utils.TestRootNode; | ||
import org.graalvm.polyglot.Context; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** Tests Truffle nodes for integer operations. */ | ||
public class FloatTest { | ||
|
||
private static AbsNode absNode; | ||
private static AddNode addNode; | ||
private static TestRootNode root; | ||
private static Context ctx; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
ctx = ContextUtils.createDefaultContext(); | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
absNode = AbsNode.build(); | ||
addNode = AddNode.build(); | ||
|
||
root = new TestRootNode(); | ||
root.insertChildren(absNode, addNode); | ||
return null; | ||
}); | ||
} | ||
|
||
@AfterClass | ||
public static void teardown() { | ||
ctx.close(); | ||
ctx = null; | ||
} | ||
|
||
private static final EnsoBigInteger bigInt = | ||
new EnsoBigInteger(new BigInteger("1000000000000000000000000000000000000")); | ||
private static final EnsoBigInteger bigIntNegative = | ||
new EnsoBigInteger(new BigInteger("-1000000000000000000000000000000000000")); | ||
|
||
@Test | ||
public void testAbs23() { | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
assertEquals(23.1, absNode.execute(23.1), 0.01); | ||
assertEquals(23.1, absNode.execute(-23.1), 0.01); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void testAdd21And1Point0() { | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
assertEquals(23.1, addNode.execute(22.0, 1.1), 0.01); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void testAdd21And1() { | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
assertEquals(23.1, addNode.execute(22.1, 1L), 0.01); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void testAddMulti21And1() { | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
var nn = EnsoMultiValue.NewNode.getUncached(); | ||
var leak = ContextUtils.leakContext(ctx); | ||
var floatType = leak.getBuiltins().number().getFloat(); | ||
var textType = leak.getBuiltins().text(); | ||
var both = new Type[] {floatType, textType}; | ||
var twentyTwoHello = nn.newValue(both, 2, 0, new Object[] {22.1, "Hello"}); | ||
assertEquals(23.2, addNode.execute(1.1, twentyTwoHello), 0.01); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void testAddInterop21And1() { | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
var twentyOne = new WrappedPrimitive(21.1); | ||
assertEquals(23.1, addNode.execute(2.0, twentyOne), 0.01); | ||
return null; | ||
}); | ||
} | ||
|
||
@Test | ||
public void testAddDoubleAndText() { | ||
ContextUtils.executeInContext( | ||
ctx, | ||
() -> { | ||
assertThrows(PanicException.class, () -> addNode.execute(23.1, "Hello")); | ||
return null; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/CaseOfTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.enso.interpreter.test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.data.EnsoMultiValue; | ||
import org.enso.interpreter.runtime.data.Type; | ||
import org.enso.test.utils.ContextUtils; | ||
import org.graalvm.polyglot.Context; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class CaseOfTest { | ||
private static Context ctx; | ||
private static EnsoContext leak; | ||
|
||
@BeforeClass | ||
public static void initCtx() throws Exception { | ||
ctx = ContextUtils.createDefaultContext(); | ||
leak = ContextUtils.leakContext(ctx); | ||
} | ||
|
||
@AfterClass | ||
public static void closeCtx() { | ||
ctx.close(); | ||
ctx = null; | ||
leak = null; | ||
} | ||
|
||
@Test | ||
public void caseOfBoolean() { | ||
doCaseOfBoolean(true, false); | ||
} | ||
|
||
@Test | ||
public void caseOfInteropBoolean() { | ||
var t = new WrappedPrimitive(true); | ||
var f = new WrappedPrimitive(false); | ||
doCaseOfBoolean(t, f); | ||
} | ||
|
||
@Test | ||
public void caseOfMultiValueBoolean() { | ||
var n = EnsoMultiValue.NewNode.getUncached(); | ||
|
||
var bAndT = | ||
new Type[] {leak.getBuiltins().bool().getType(), leak.getBuiltins().number().getInteger()}; | ||
var t = n.newValue(bAndT, 2, 0, new Object[] {true, 300}); | ||
var f = n.newValue(bAndT, 2, 0, new Object[] {false, 200}); | ||
doCaseOfBoolean(t, f); | ||
} | ||
|
||
private void doCaseOfBoolean(Object t, Object f) { | ||
var code = | ||
""" | ||
from Standard.Base import True, False | ||
choose v = case v of | ||
True -> 1 | ||
False -> 2 | ||
_ -> 3 | ||
"""; | ||
|
||
var choose = ContextUtils.evalModule(ctx, code, "choose.enso", "choose"); | ||
|
||
var one = choose.execute(t); | ||
assertEquals("With " + t + " we should get 1", 1, one.asInt()); | ||
var two = choose.execute(f); | ||
assertEquals("With " + f + " we should get 2", 2, two.asInt()); | ||
} | ||
} |
Oops, something went wrong.