Skip to content

Commit ea90140

Browse files
committed
[io] more "fuzz" testing
1 parent b97be7a commit ea90140

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

symja_android_library/matheclipse-io/src/test/java/org/matheclipse/core/fuzz/ExprEvaluatorTests.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.matheclipse.core.expression.F;
1919
import org.matheclipse.core.expression.S;
2020
import org.matheclipse.core.expression.data.ByteArrayExpr;
21+
import org.matheclipse.core.expression.data.NumericArrayExpr;
2122
import org.matheclipse.core.expression.data.SparseArrayExpr;
2223
import org.matheclipse.core.form.output.OutputFormFactory;
2324
import org.matheclipse.core.interfaces.IAST;
@@ -105,11 +106,14 @@ public void testSmartFuzz() {
105106
ByteArrayExpr b0a = ByteArrayExpr.newInstance(b0Array);
106107
F.x.setAttributes(ISymbol.PROTECTED);
107108
F.y.setAttributes(ISymbol.PROTECTED);
108-
109+
double[] doubleArr = new double[] {1.0, -1.0, 0.0, 2.0, 100.0, 200.0};
110+
int[] dims = new int[] {2, 3};
111+
NumericArrayExpr nae = new NumericArrayExpr(doubleArr, dims, NumericArrayExpr.Real64);
109112
IAST seedList =
110113
F.List( //
111114
ba, //
112115
b0a, //
116+
nae, //
113117
// F.NIL, //
114118
F.complex(-0.5, 0.5), //
115119
F.complex(0.0, 0.5), //
@@ -993,4 +997,28 @@ private void generateASTs(
993997
}
994998
}
995999
}
1000+
1001+
public void testTogether() {
1002+
// Together(1+SparseArray(Number of elements: 0 Dimensions: {2,2} Default value: 0))
1003+
IExpr sa = SparseArrayExpr.newDenseList(F.List(F.List(F.C1, F.C0), F.List(F.C0, F.C1)), F.C0);
1004+
checkEvaluator(F.Together(F.Plus(F.C1, sa)), //
1005+
"1+SparseArray(Number of elements: 2 Dimensions: {2,2} Default value: 0)"
1006+
);
1007+
}
1008+
1009+
void checkEvaluator(IAST ast, String expected) {
1010+
EvalEngine engine = EvalEngine.get();
1011+
try {
1012+
IFunctionEvaluator evaluator =
1013+
(IFunctionEvaluator) ((IBuiltInSymbol) ast.topHead()).getEvaluator();
1014+
if (evaluator instanceof IFunctionEvaluator) {
1015+
IExpr result = evaluator.evaluate(ast, engine);
1016+
assertEquals(expected, result.toString());
1017+
return;
1018+
}
1019+
} catch (RuntimeException rex) {
1020+
rex.printStackTrace();
1021+
}
1022+
fail();
1023+
}
9961024
}

0 commit comments

Comments
 (0)