Skip to content

Commit

Permalink
JUnit tests; clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Nov 24, 2024
1 parent 091cd00 commit e9b68ab
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public synchronized void check(ExprEvaluator scriptEngine, String evalString,
assertEquals(expectedResult, evaledResult);
}
} catch (SyntaxError e) {
e.printStackTrace();
System.err.println(e.getMessage());
// e.printStackTrace();
assertEquals(e.getMessage(), expectedResult);
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package org.matheclipse.core.system;

import org.junit.Before;
import org.junit.Test;
import org.matheclipse.core.basic.Config;
import org.matheclipse.core.expression.BuiltinFunctionCalls;
import org.matheclipse.core.expression.S;

public class IntegrateTest extends ExprEvaluatorTestCase {
/** The JUnit setup method */
@Override
@Before
public void setUp() {
super.setUp();
try {
S.Integrate.getEvaluator().await();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Test
public void testIntegrateDefinite() {
Expand Down Expand Up @@ -165,7 +179,8 @@ public void testIntegrateMessage() {

@Test
public void testIntegrateIncomplete() {

check("Integrate(Csch(x)/x,x)", //
"Integrate(Csch(x)/x,x)");
check("Integrate((Sinh(x)-x)/(x^2*Sinh(x)),x)", //
"-1/x-Integrate(Csch(x)/x,x)");
check("Refine(Integrate(Abs(E+Pi*x^(-8)),x), Element(x,Reals))", //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,11 @@ public void testEigensystem() {

@Test
public void testEigenvalues() {
check("mat = Array(a, {2,2}); Eigenvalues(mat.ConjugateTranspose(mat))[[1]] // FullSimplify", //
"1/2*(Abs(a(1,1))^2+Abs(a(1,2))^2+Abs(a(2,1))^2+Abs(a(2,2))^2-Sqrt((Abs(a(1,1))^2+Abs(a(\n" //
+ "1,2))^2)^2-2*(Abs(a(1,1))^2+Abs(a(1,2))^2)*(Abs(a(2,1))^2+Abs(a(2,2))^2)+(Abs(a(\n" //
+ "2,1))^2+Abs(a(2,2))^2)^2+4*(a(2,1)*Conjugate(a(1,1))+a(2,2)*Conjugate(a(1,2)))*(a(\n" //
+ "1,1)*Conjugate(a(2,1))+a(1,2)*Conjugate(a(2,2)))))");
check("Eigenvalues({{1,0,0,0,0},{3,1,0,0,0},{6,3,2,0,0},{10,6,3,2,0},{15,10,6,3,2}})", //
"{2,2,2,1,1}");
check("Eigenvalues({{1, 0, 0}, {-2, 1, 0}, {0, 1, 1}})", //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1491,10 +1491,11 @@ public void testBaseForm() {
check("BaseForm(2882400255, 16)", //
"Subscript(abcdefff,16)");
check("37^^abcdefff", //
"Syntax error in line: 1 - Base 37^^... is invalid. Only bases between 1 and 36 are allowed\n"
"Syntax error in line: 1 - Base 37^^... is invalid. Only bases between 1 and 36 are allowed\n" //
+ "37^^abcdefff\n" + " ^");
check("16^^6z12xy", //
"Syntax error in line: 1 - Number format error: 6z12xy\n" + "16^^6z12xy\n" + " ^");
"Syntax error in line: 1 - Number format error: 6z12xy\n" //
+ "16^^6z12xy\n" + " ^");
}

@Test
Expand Down Expand Up @@ -2428,6 +2429,8 @@ public void testClearAttributes() {

@Test
public void testClebschGordan() {
check("ClebschGordan({j, m}, {j1, m1}, {j2, m2})", //
"(-1)^(j-j1+m2)*Sqrt(1+2*j2)*ThreeJSymbol({j,m},{j1,m1},{j2,-m2})");
// https://en.wikipedia.org/wiki/Table_of_Clebsch%E2%80%93Gordan_coefficients
check("ClebschGordan({3/2, -3/2}, {3/2, 3/2}, {1, 0})", //
"3/2*1/Sqrt(5)");
Expand Down Expand Up @@ -4668,6 +4671,10 @@ public void testD() {

@Test
public void testDefault() {
check("Default(Times,2)", //
"1");
check("Default(Times)", //
"1");
check("Default(test) := 1", //
"1");
check("Default(test) = 1", //
Expand All @@ -4685,8 +4692,23 @@ public void testDefault() {
"Default(Power)");
check("Default(Power, 2)", //
"1");
check("Default(Times)", //
"1");
}

@Test
public void testDefaultF() {
check("Default(f)=0", //
"0");
check("f(x_., y_.) = {x, y}", //
"{x,y}");
check("f(a)", //
"{a,0}");
check("f()", //
"{0,0}");
check("Default(f, 1) = 1; Default(f, 2) = 2;", //
"");
check("Replace(f(), f(x_., y_.) :> {x, y})", //
"{1,2}");

}

@Test
Expand Down Expand Up @@ -5100,6 +5122,14 @@ public void testCapitalDifferentialD() {

@Test
public void testDerivative() {
check("Derivative(0,1,0,0)[Multinomial]", //
"(-HarmonicNumber(#2)+HarmonicNumber(#1+#2+#3+#4))*Multinomial(#1,#2,#3,#4)&");
check("Derivative(1,1,0,0)[Multinomial]", //
"Derivative(1,1,0,0)[Multinomial]");


check("Derivative(1)[I+2]", //
"0&");
check("Derivative(1)[Log10]", //
"1/(Log(10)*#1)&");
check("Derivative(1)[Log2]", //
Expand Down Expand Up @@ -5720,8 +5750,8 @@ public void testDistribute() {
// check(
// "Distribute(x^10 - 1)", //
// "-1+x^10");
check("Distribute(Factor(x^10 - 1))", //
"-1+x^10");
// check("Distribute(Factor(x^10 - 1))", //
// "-1+x^10");

check("Distribute((a + b).(x + y + z))", //
"a.x+a.y+a.z+b.x+b.y+b.z");
Expand Down Expand Up @@ -6031,12 +6061,14 @@ public void testDrop() {

@Test
public void testDSolve() {
check("DSolve(y'(t)==t+y(t), y, t)", //
"{{y->Function({t},-1-t+E^t*C(1))}}");

check("DSolve(y'(x)==2*x*y(x)^2,Null,x)", //
"DSolve(y'(x)==2*x*y(x)^2,Null,x)");
check("DSolve({},y,t)", //
"DSolve({},y,t)");
check("DSolve(y'(t)==t+y(t), y, t)", //
"{{y->Function({t},-1-t+E^t*C(1))}}");

check("DSolve(y'(t)==y(t), y, t)", //
"{{y->Function({t},E^t*C(1))}}");

Expand Down Expand Up @@ -9351,6 +9383,11 @@ public void testFullForm() {

@Test
public void testFullSimplify() {
check("FullSimplify(Mod(Mod(a, c) + Mod(b*q, c) + f(x), c))", //
"Mod(a+b*q+f(x),c)");

check("FullSimplify(a*Conjugate(a))", //
"Abs(a)^2");
check("FullSimplify( 3*E^(-x)+7*E^x )", //
"10*Cosh(x)+4*Sinh(x)");
check("Simplify( 3*E^(-x)+7*E^x )", //
Expand Down Expand Up @@ -12461,13 +12498,47 @@ public void testLengthWhile() {

@Test
public void testLerchPhi() {
check("LerchPhi(-1,1,0)", //
"-Log(2)");
check("LerchPhi(-1,2,1/2)", //
"4*Catalan");
check("LerchPhi(1,2,1)", //
"Pi^2/6");
check("LerchPhi(2,1,0)", //
"-I*Pi");
check("LerchPhi(1/2-1/2*I, 2, 1)", //
"(1+I)*PolyLog(2,1/2-I*1/2)");
check("LerchPhi(1/2-1/2*I, 2, 1) // FunctionExpand", //
"(1+I)*(-I*Catalan+Pi^2/48-(I*1/4*Pi-Log(2)/2)^2/2)");

check("LerchPhi(0,1,0)", //
"0");
check("LerchPhi(1,1,a)", //
"LerchPhi(1,1,a)");
check("LerchPhi(1,1,-42/3+7*I)", //
"Infinity");
check("LerchPhi(-1,s,1)", //
"(1-2^(1-s))*Zeta(s)");
check("LerchPhi(z,1,1)", //
"-Log(1-z)/z");
check("LerchPhi(z,s,0)", //
"PolyLog(s,z)");
check("LerchPhi(z,s,1)", //
"PolyLog(s,z)/z");
check("LerchPhi(0,1,a)", //
"1/Sqrt(a^2)");
check("LerchPhi(0,s,a)", //
"(a^2)^(-s/2)");
check("LerchPhi(-1,s,a)", //
"Zeta(s,a/2)/2^s-Zeta(s,1/2*(1+a))/2^s");
check("LerchPhi(z,0,a)", //
"1/(1-z)");
// check("LerchPhi(1,1,2)", //
// "Infinity");
check("LerchPhi(z,s,-2)", //
"z^2*(1/(2^s*z^2)+1/z+PolyLog(s,z))");
check("LerchPhi(-1,1,0)", //
"-Log(2)");

}

@Test
Expand Down Expand Up @@ -13122,12 +13193,13 @@ public void testLimitPiecewise001() {
@Test
public void testLimitIssue536() {
// avoid endless recursion:
check("Limit(Sqrt((4+x)/(4-x))-Pi/2,x->4)", //
"Indeterminate");
// TODO get -4*Pi
check(
"Limit((-4+x)*(Sqrt((4+x)/(4-x))-ArcTan(Sqrt((4+x)/(4-x)))+(-(4+x)*ArcTan(Sqrt((4+x)/(4-x))))/(4-x)), x->4)", //
"Indeterminate");
// check("Limit(Sqrt((4+x)/(4-x))-Pi/2,x->4)", //
// "Indeterminate");
// // TODO get -4*Pi
// check(
// "Limit((-4+x)*(Sqrt((4+x)/(4-x))-ArcTan(Sqrt((4+x)/(4-x)))+(-(4+x)*ArcTan(Sqrt((4+x)/(4-x))))/(4-x)),
// x->4)", //
// "Indeterminate");

// Issue 536
check("Integrate(Sqrt((4+x)/(4-x)), x) ", //
Expand Down Expand Up @@ -13674,6 +13746,10 @@ public void testMantissaExponent() {
check("MantissaExponent(3+2*I, 2)", //
"MantissaExponent(3+I*2,2)");

check("MantissaExponent(12345.6789)", //
"{0.123457,5}");
checkNumeric("MantissaExponent(12345.6789)", //
"{0.12345678900000001,5}");

check("MantissaExponent(125.24)", //
"{0.12524,3}");
Expand Down Expand Up @@ -14113,6 +14189,36 @@ public void testMatchQ() {
"True");
}

@Test
public void testMatchQRubi001() {
check("MatchQ[1 + 2*x, (a_. + b_.*x_Symbol)]", //
"True");
check("MatchQ[0 + 2*x, (a_. + b_.*x_Symbol)]", //
"True");
check("MatchQ[1 + x, (a_.+x_Symbol)]", //
"True");
}

@Test
public void testMatchQRubi002() {
check("a/.Optional(c1_?NumberQ)*a_->{{c1},{a}}", //
"{{1},{a}}");
check("Default(g)=0", //
"0");
check("g(a_., b_.):={a,b}", //
"");
check("g(x) ", //
"{x,0}");
check("f( a_. + b_. ):={a,b}", //
"");
// check("f( x ) ", //
// "{x,0}");
// check("MatchQ(2+x, ( a_. + b_. ) )", //
// "True");
// check("MatchQ(x, ( a_. + b_. ) )", //
// "True");
}

@Test
public void testMathMLForm() {
check("MathMLForm(Sqrt(3)-I)", //
Expand Down Expand Up @@ -18271,6 +18377,10 @@ public void testPossibleZeroQ() {

@Test
public void testPower() {
check("1^Infinity", //
"Indeterminate");
check("(-1)^Infinity", //
"Indeterminate");
check("Power(-Infinity, 43)", //
"-Infinity");
check("Sqrt(-Infinity)", //
Expand Down Expand Up @@ -23404,6 +23514,22 @@ public void testSwitch() {
"Switch(2,1)");
check("$f(b_) := switch(b, True, 1, False, 0, _, -1);{$f(True), $f(False), $f(x)}", //
"{1,0,-1}");

check("f::boole = \"The value `1` is not True or False.\";", //
"");
check("f(b_) := Switch(b, True, 1, False, 0, _, Message(f::boole, b); 0)", //
"");
check("{f(True), f(False), f(x)}", //
"{1,0,0}");


check("t(e_) := Switch(e, _Plus, Together, _Times, Apart, _, Identity)", //
"");
check("e = (1 + x)/(1 - x) + x/(1 + x);t(e)", //
"Together");
check("t(e)[e]", //
"(1+3*x)/((1-x)*(1+x))");

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,17 @@ public void testRootsSolve() {

}

@Test
public void testSolveConjugate() {
check("InverseFunction(Conjugate)", //
"Conjugate");
check("Solve(z^3==z,z)", //
"{{z->-1},{z->0},{z->1}}");
// TODO get {{z->-1},{z->0},{z->-I},{z->I},{z -> 1}}
check("Solve(z^3==Conjugate(z),z)", //
"Solve(z^3==Conjugate(z),z)");
}

/** The JUnit setup method */
@Override
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static void init() {
S.ListDensityPlot.setEvaluator(new org.matheclipse.image.builtin.ListDensityPlot());
// S.ListLogPlot.setEvaluator(new org.matheclipse.image.builtin.ListLogPlot());
// S.ListLogLogPlot.setEvaluator(new org.matheclipse.image.builtin.ListLogLogPlot());
// S.ListPlot.setEvaluator(new org.matheclipse.image.builtin.ListPlot());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public IExpr evaluate(final IAST ast, EvalEngine engine) {
return F.NIL;
}

public static JFreeChart listLogLogPlot(VisualSet visualSet, boolean joined) {
private static JFreeChart listLogLogPlot(VisualSet visualSet, boolean joined) {
visualSet.getAxisX().setType(Axis.Type.LOGARITHMIC);
visualSet.getAxisY().setType(Axis.Type.LOGARITHMIC);
return listPlot(visualSet, joined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,16 @@ protected static IAST createSeedList() {
F.Missing("test"), //
F.complex(-0.5, 0.5), //
F.complex(0.0, 0.5), //
F.complex(0.0, -1.0), //
F.complex(0.0, 1.0), //
F.CDI, //
F.CDNI, //
F.complex(2.0, -1.0), //
F.complex(2.0, 1.0), //
F.complex(-2.0, -2.0), //
F.complex(-2.0, 2.0), //
F.complexNum("-0.8", "1.2", 30), //
// F.complexNum(new Apfloat(Long.MIN_VALUE, 30), new Apfloat(Long.MAX_VALUE,
// 30)), //
F.CD0, //
F.num(0.5), //
F.num(-0.5), //
F.num(Math.PI * (-0.5)), //
Expand Down
Loading

0 comments on commit e9b68ab

Please sign in to comment.