Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-08 04:20:06 +01:00
Extract common simple test case method
(cherry picked from commit 910c89be65501e8f6bcb823e819a0a16073db60a)
Dieser Commit ist enthalten in:
Ursprung
5b4b5de761
Commit
8c385b0593
@ -25,6 +25,7 @@ import com.sk89q.worldedit.extension.platform.Platform;
|
|||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ -50,6 +51,19 @@ class BaseExpressionTest {
|
|||||||
WorldEdit.getInstance().getConfiguration().calculationTimeout = 1_000;
|
WorldEdit.getInstance().getConfiguration().calculationTimeout = 1_000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
WorldEdit.getInstance().getPlatformManager().unregister(mockPlat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkTestCase(String expression, double result) {
|
||||||
|
checkTestCase(ExpressionTestCase.testCase(expression, result));
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkTestCase(ExpressionTestCase testCase) {
|
||||||
|
assertEquals(testCase.getResult(), simpleEval(testCase.getExpression()), 0);
|
||||||
|
}
|
||||||
|
|
||||||
double simpleEval(String expressionString) throws ExpressionException {
|
double simpleEval(String expressionString) throws ExpressionException {
|
||||||
final Expression expression = compile(expressionString);
|
final Expression expression = compile(expressionString);
|
||||||
|
|
||||||
@ -88,11 +102,6 @@ class BaseExpressionTest {
|
|||||||
return expression.evaluate();
|
return expression.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void tearDown() {
|
|
||||||
WorldEdit.getInstance().getPlatformManager().unregister(mockPlat);
|
|
||||||
}
|
|
||||||
|
|
||||||
Expression compile(String expressionString, String... variableNames) throws ExpressionException {
|
Expression compile(String expressionString, String... variableNames) throws ExpressionException {
|
||||||
final Expression expression = Expression.compile(expressionString, variableNames);
|
final Expression expression = Expression.compile(expressionString, variableNames);
|
||||||
expression.optimize();
|
expression.optimize();
|
||||||
|
@ -70,7 +70,7 @@ class ExpressionTest extends BaseExpressionTest {
|
|||||||
return testCases.stream()
|
return testCases.stream()
|
||||||
.map(testCase -> DynamicTest.dynamicTest(
|
.map(testCase -> DynamicTest.dynamicTest(
|
||||||
testCase.getExpression(),
|
testCase.getExpression(),
|
||||||
() -> assertEquals(testCase.getResult(), simpleEval(testCase.getExpression()), 0)
|
() -> checkTestCase(testCase)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class ExpressionTest extends BaseExpressionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTightTokenization() {
|
void testTightTokenization() {
|
||||||
assertEquals(4, simpleEval("3+1"), 0);
|
checkTestCase("3+1", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -137,8 +137,8 @@ class ExpressionTest extends BaseExpressionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIf() throws ExpressionException {
|
public void testIf() throws ExpressionException {
|
||||||
assertEquals(40, simpleEval("y=0; if (1) x=4; else y=5; x*10+y;"), 0);
|
checkTestCase("y=0; if (1) x=4; else y=5; x*10+y;", 40);
|
||||||
assertEquals(5, simpleEval("x=0; if (0) x=4; else y=5; x*10+y;"), 0);
|
checkTestCase("x=0; if (0) x=4; else y=5; x*10+y;", 5);
|
||||||
|
|
||||||
// test 'dangling else'
|
// test 'dangling else'
|
||||||
final Expression expression1 = compile("if (1) if (0) x=4; else y=5;", "x", "y");
|
final Expression expression1 = compile("if (1) if (0) x=4; else y=5;", "x", "y");
|
||||||
@ -154,36 +154,36 @@ class ExpressionTest extends BaseExpressionTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhile() throws ExpressionException {
|
public void testWhile() throws ExpressionException {
|
||||||
assertEquals(5, simpleEval("c=5; a=0; while (c > 0) { ++a; --c; } a"), 0);
|
checkTestCase("c=5; a=0; while (c > 0) { ++a; --c; } a", 5);
|
||||||
assertEquals(5, simpleEval("c=5; a=0; do { ++a; --c; } while (c > 0); a"), 0);
|
checkTestCase("c=5; a=0; do { ++a; --c; } while (c > 0); a", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFor() throws ExpressionException {
|
public void testFor() throws ExpressionException {
|
||||||
assertEquals(5, simpleEval("a=0; for (i=0; i<5; ++i) { ++a; } a"), 0);
|
checkTestCase("a=0; for (i=0; i<5; ++i) { ++a; } a", 5);
|
||||||
assertEquals(12345, simpleEval("y=0; for (i=1,5) { y *= 10; y += i; } y"), 0);
|
checkTestCase("y=0; for (i=1,5) { y *= 10; y += i; } y", 12345);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSwitch() throws ExpressionException {
|
public void testSwitch() throws ExpressionException {
|
||||||
assertEquals(523, simpleEval("x=1;y=2;z=3;switch (1) { case 1: x=5; break; case 2: y=6; break; default: z=7 } x*100+y*10+z"), 0);
|
checkTestCase("x=1;y=2;z=3;switch (1) { case 1: x=5; break; case 2: y=6; break; default: z=7 } x*100+y*10+z", 523);
|
||||||
assertEquals(163, simpleEval("x=1;y=2;z=3;switch (2) { case 1: x=5; break; case 2: y=6; break; default: z=7 } x*100+y*10+z"), 0);
|
checkTestCase("x=1;y=2;z=3;switch (2) { case 1: x=5; break; case 2: y=6; break; default: z=7 } x*100+y*10+z", 163);
|
||||||
assertEquals(127, simpleEval("x=1;y=2;z=3;switch (3) { case 1: x=5; break; case 2: y=6; break; default: z=7 } x*100+y*10+z"), 0);
|
checkTestCase("x=1;y=2;z=3;switch (3) { case 1: x=5; break; case 2: y=6; break; default: z=7 } x*100+y*10+z", 127);
|
||||||
|
|
||||||
assertEquals(567, simpleEval("x=1;y=2;z=3;switch (1) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z"), 0);
|
checkTestCase("x=1;y=2;z=3;switch (1) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z", 567);
|
||||||
assertEquals(167, simpleEval("x=1;y=2;z=3;switch (2) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z"), 0);
|
checkTestCase("x=1;y=2;z=3;switch (2) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z", 167);
|
||||||
assertEquals(127, simpleEval("x=1;y=2;z=3;switch (3) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z"), 0);
|
checkTestCase("x=1;y=2;z=3;switch (3) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z", 127);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQuery() throws Exception {
|
public void testQuery() throws Exception {
|
||||||
assertEquals(1, simpleEval("a=1;b=2;query(3,4,5,a,b); a==3 && b==4"), 0);
|
checkTestCase("a=1;b=2;query(3,4,5,a,b); a==3 && b==4", 1);
|
||||||
assertEquals(1, simpleEval("a=1;b=2;queryAbs(3,4,5,a*1,b*1); a==1 && b==2"), 0);
|
checkTestCase("a=1;b=2;queryAbs(3,4,5,a*1,b*1); a==1 && b==2", 1);
|
||||||
assertEquals(1, simpleEval("a=1;b=2;queryRel(3,4,5,(a),(b)); a==300 && b==400"), 0);
|
checkTestCase("a=1;b=2;queryRel(3,4,5,(a),(b)); a==300 && b==400", 1);
|
||||||
assertEquals(1, simpleEval("query(3,4,5,3,4)"), 0);
|
checkTestCase("query(3,4,5,3,4)", 1);
|
||||||
assertEquals(1, simpleEval("!query(3,4,5,3,2)"), 0);
|
checkTestCase("!query(3,4,5,3,2)", 1);
|
||||||
assertEquals(1, simpleEval("!queryAbs(3,4,5,10,40)"), 0);
|
checkTestCase("!queryAbs(3,4,5,10,40)", 1);
|
||||||
assertEquals(1, simpleEval("!queryRel(3,4,5,100,200)"), 0);
|
checkTestCase("!queryRel(3,4,5,100,200)", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren