Search in sources :

Example 11 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldReturnCorrectResultWhenExecuteBinaryExprMult.

@Test
void shouldReturnCorrectResultWhenExecuteBinaryExprMult() {
    ArithmeticBinaryExpression abe = createBinaryExpression(MULTIPLY, 4, 2);
    assertEquals(new RedsInteger(8), abe.execute(env));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 12 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldReturnCorrectResultWhenExecuteBinaryPlus.

@Test
void shouldReturnCorrectResultWhenExecuteBinaryPlus() {
    ArithmeticBinaryExpression abe = createBinaryExpression(ADD, 4, 3);
    assertEquals(new RedsInteger(7), abe.execute(env));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 13 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class ArithmeticBinaryExpressionTest method shouldPrioritizeUnaryMinusOverMultiplyDivideAndModulo.

@Test
void shouldPrioritizeUnaryMinusOverMultiplyDivideAndModulo() {
    Statement stmt = parseStatement("2*-1/-1*(1%-(-2))");
    assertEquals(new RedsInteger(2), stmt.execute(env));
}
Also used : TestUtils.parseStatement(net.taken.redsnake.tree.TestUtils.parseStatement) Statement(net.taken.redsnake.tree.statements.Statement) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 14 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class IfTest method shouldExecuteThenBlockWhenExecutingIfWithParenthesisAndCurlyBracketsAndNotInline.

@Test
void shouldExecuteThenBlockWhenExecutingIfWithParenthesisAndCurlyBracketsAndNotInline() {
    Program program = parseProgram("a = 0\n" + "if(true) {\n" + "    a = 1\n" + "} else {\n" + "    a = 2\n" + "}");
    program.execute(env);
    assertEquals(new RedsInteger(1), env.getVariable("a"));
}
Also used : Program(net.taken.redsnake.tree.Program) RedsInteger(net.taken.redsnake.lang.RedsInteger) Test(org.junit.jupiter.api.Test)

Example 15 with RedsInteger

use of net.taken.redsnake.lang.RedsInteger in project redsnake by Taken0711.

the class IfTest method shouldNotExecuteElseBlockWhenExecutingIfWithFalseAndElseClause.

@Test
void shouldNotExecuteElseBlockWhenExecutingIfWithFalseAndElseClause() {
    If anIf = createIfWithAssignments("a", false, 1, 2);
    env.putVariable("a", new RedsInteger(0));
    anIf.execute(env);
    assertEquals(new RedsInteger(2), env.getVariable("a"));
}
Also used : RedsInteger(net.taken.redsnake.lang.RedsInteger) If(net.taken.redsnake.tree.statements.If) Test(org.junit.jupiter.api.Test)

Aggregations

RedsInteger (net.taken.redsnake.lang.RedsInteger)28 Test (org.junit.jupiter.api.Test)28 Statement (net.taken.redsnake.tree.statements.Statement)7 TestUtils.parseStatement (net.taken.redsnake.tree.TestUtils.parseStatement)5 If (net.taken.redsnake.tree.statements.If)3 Program (net.taken.redsnake.tree.Program)2