Skip to content

Commit

Permalink
JUnit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Oct 20, 2024
1 parent 5ba2e79 commit 7e705e6
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ public void testTransliterate() {
+ " \"error\" : \"false\",\n" //
+ " \"numsubpods\" : 1,\n" //
+ " \"subpods\" : [ {\n" //
+ " \"markdown\" : \"## Chop\\n\\n```\\nChop(numerical-expr)\\n```\\n\\n> replaces numerical values in the `numerical-expr` which are close to zero with symbolic value `0`. \\n\\n```\\nChop(numerical-expr, delta)\\n```\\n\\n> uses a tolerance of `delta`. The default tolerance is `10^-10`.\\n \\n### Examples\\n\\n```\\n>> Chop(0.00000000001)\\n0\\n```\\n\\n\\n### Implementation status\\n\\n* ✅ - full supported\\n\\n### Github\\n\\n* [Implementation of Chop](https://github.com/axkr/symja_android_library/blob/master/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java#L706) \\n[Github master](https://github.com/axkr/symja_android_library/blob/master/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java#L706)\\n\\n\"\n" //
+ " \"markdown\" : \"## Chop\\n\\n```\\nChop(numerical-expr)\\n```\\n\\n> replaces numerical values in the `numerical-expr` which are close to zero with symbolic value `0`. \\n\\n```\\nChop(numerical-expr, delta)\\n```\\n\\n> uses a tolerance of `delta`. The default tolerance is `10^-10`.\\n \\n### Examples\\n\\n```\\n>> Chop(0.00000000001)\\n0\\n```\\n\\n\\n### Implementation status\\n\\n* ✅ - full supported\\n\\n### Github\\n\\n* [Implementation of Chop](https://github.com/axkr/symja_android_library/blob/master/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java#L706) \\n[Github master](https://github.com/axkr/symja_android_library/blob/master/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/Arithmetic.java#L705)\\n\\n\"\n" //
+ " } ]\n" //
+ " } ]\n" //
+ " }\n" //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ public void testEqual() {
// "0.1111111111111111 == 0.1111111111111126", //
// "True");

// mathics expects result: 2. + 3.14159 I == 2 + 3 a
check("2.+ I*Pi == 2 + 3*a", //
"a==I*1.0472");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public void testCompilePrint002() {
+ " double xd = engine.evalDouble(x);\n" //
+ " stack.set(top++, F.num(xd));\n" //
+ " \n" //
+ " return F.num((20.085536923187668)-Math.cos((9.869604401089358)/evalDouble(stack.get(1))));\n" //
+ " return F.num(20.085536923187668-Math.cos(9.869604401089358/evalDouble(stack.get(1))));\n" //
+ " \n" //
+ " }\n" //
+ " public double evalDouble(IExpr expr) {\n" //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ public void testAdjugate() {
+ " {-4.0,5.0}}");
}

@Test
public void testAnglePath() {
// avoid index out of bounds exception
check("AnglePath(RandomReal({-1, 1}, {100}));", //
"");
check("AnglePath({90*Degree, 90*Degree, 90*Degree})", //
"{{0,0},{0,1},{-1,1},{-1,0}}");
check("AnglePath({90*Degree, Pi/3, -Pi/4})", //
"{{0,0},{0,1},{-Sqrt(3)/2,3/2},{(1-Sqrt(3))/(2*Sqrt(2))-Sqrt(3)/2,3/2+(1+Sqrt(3))/(\n"
+ "2*Sqrt(2))}}");
check("AnglePath({{0.7, 90*Degree}, {2.3, Pi/3}, {3.5, -Pi/4}})", //
"{{0,0},{0.0,0.7},{-1.99186,1.85},{-2.89773,5.23074}}");

check("AnglePath({t1,t2,t3})", //
"{{0,0},{Cos(t1),Sin(t1)},{Cos(t1)+Cos(t1+t2),Sin(t1)+Sin(t1+t2)},{Cos(t1)+Cos(t1+t2)+Cos(t1+t2+t3),Sin(t1)+Sin(t1+t2)+Sin(t1+t2+t3)}}");

check("AnglePath({{r1,t1},{r2,t2},{r3,t3}})", //
"{{0,0},{r1*Cos(t1),r1*Sin(t1)},{r1*Cos(t1)+r2*Cos(t1+t2),r1*Sin(t1)+r2*Sin(t1+t2)},{r1*Cos(t1)+r2*Cos(t1+t2)+r3*Cos(t1+t2+t3),r1*Sin(t1)+r2*Sin(t1+t2)+r3*Sin(t1+t2+t3)}}");

check("AnglePath({{x, y},t0}, {{r1,t1},{r2,t2},{r3,t3}})", //
"{{x,y},{x+r1*Cos(t0+t1),y+r1*Sin(t0+t1)},{x+r1*Cos(t0+t1)+r2*Cos(t0+t1+t2),y+r1*Sin(t0+t1)+r2*Sin(t0+t1+t2)},{x+r1*Cos(t0+t1)+r2*Cos(t0+t1+t2)+r3*Cos(t0+t1+t2+t3),y+r1*Sin(t0+t1)+r2*Sin(t0+t1+t2)+r3*Sin(t0+t1+t2+t3)}}");
check("AnglePath({{x, y},t0}, { })", //
"{{x,y}}");

}

@Test
public void testAngleVector() {
check("AngleVector(x)", //
Expand All @@ -51,6 +77,8 @@ public void testAngleVector() {
"{0,1}");
check("AngleVector({1, 10}, a)", //
"{1+Cos(a),10+Sin(a)}");
check("AngleVector({x,y}, {r,t})", //
"{x+r*Cos(t),y+r*Sin(t)}");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4303,6 +4303,20 @@ public void testCyclotomic() {

@Test
public void testD() {
// check("D(a*3^x,{x,n})", //
// "a*E^x");
// TODO
check("D(a*Exp(x),{x,n})", //
"a*E^x");
check("D(a*f(x),{x,10})", //
"a*Derivative(10)[f][x]");
check("D(a*Exp(x),{x,3})", //
"a*E^x");
check("D(Tan(x),{x,3})", //
"2*Sec(x)^4+4*Sec(x)^2*Tan(x)^2");
check("D(Cot(x),{x,5})", //
"-16*Cot(x)^4*Csc(x)^2-88*Cot(x)^2*Csc(x)^4-16*Csc(x)^6");

check("D((2*Sqrt(2)*(x^3))/(x^4),x)", //
"(-2*Sqrt(2))/x^2");
check("D(z^n*E^(z),{z,n})", //
Expand Down Expand Up @@ -4753,10 +4767,14 @@ public void testDelete() {
"Identity(a,b,c)");
check("Delete({ }, 0)", //
"Identity()");
// print Cannot delete position 5 in {a,b,c,d}
check("Delete({1, 2}, 0)", //
"Identity(1,2)");
// Delete: Part {5} of {a,b,c,d} does not exist.
check("Delete({a, b, c, d}, 5)", //
"Delete({a,b,c,d},5)");

// List: List of Java int numbers expected in {1,n}.
check("Delete({a, b, c, d}, {1, n})", //
"Delete({a,b,c,d},{1,n})");
check("Delete({a, b, c, d}, 3)", //
"{a,b,d}");
check("Delete({a, b, c, d}, -2)", //
Expand All @@ -4778,6 +4796,9 @@ public void testDelete() {
"Delete(pos)[x]");
check("Delete(2)[{1,2,3,4}]", //
"{1,3,4}");

check("Delete(f[a, b, u + v, c], {3, 0})", //
"f(a,b,u,v,c)");
}

@Test
Expand Down Expand Up @@ -5055,6 +5076,18 @@ public void testCapitalDifferentialD() {

@Test
public void testDerivative() {
check("Derivative(1)[Log10]", //
"1/(Log(10)*#1)&");
check("Derivative(1)[Log2]", //
"1/(Log(2)*#1)&");
check("Derivative(1)[Exp]", //
"E^#1&");
check("Derivative(1)[Abs]", //
"Derivative(1)[Abs]");
check("Derivative(1)[RealAbs]", //
"#1/RealAbs(#1)&");
check("Derivative(3)[ArcCos]", //
"-(1+2*#1^2)/(1-#1^2)^(5/2)&");
check("Derivative(0,0,0,n)[Hypergeometric2F1Regularized]", //
"Hypergeometric2F1Regularized(n+#1,n+#2,n+#3,#4)*Pochhammer(#1,n)*Pochhammer(#2,n)&");
check("Derivative(0,0,0,Sin(7))[Hypergeometric2F1Regularized]", //
Expand All @@ -5063,8 +5096,6 @@ public void testDerivative() {
"Hypergeometric2F1Regularized(3+#1,3+#2,3+#3,#4)*Pochhammer(#1,3)*Pochhammer(#2,3)&");
check("Derivative(0,0,0)[Sequence()]", //
"Derivative(0,0,0)[]");
check("Derivative(1)[Abs]", //
"Derivative(1)[Abs]");

check("Derivative(1,0)[StruveH][#1,#2]", //
"Derivative(1,0)[StruveH][#1,#2]");
Expand Down Expand Up @@ -8682,6 +8713,7 @@ public void testFlatOrderlessOneIdentity() {

@Test
public void testFlatten() {

// message Flatten: Level specification value greater equal 0 expected instead of -Infinity.
check("Flatten(f(g(u, v), f(x, y)), -Infinity, f)", //
"Flatten(f(g(u,v),f(x,y)),-Infinity,f)");
Expand Down Expand Up @@ -11425,6 +11457,13 @@ public void testInverseCDF() {

@Test
public void testInverseFunction() {
check("InverseFunction(Log2)", //
"2^#1&");
check("InverseFunction(Log10)", //
"10^#1&");
check("InverseFunction(Erfi)", //
"-I*InverseErf(I*#1)&");

check("InverseFunction(Power,1,2)", //
"#1^(1/#2)&");
check("InverseFunction(Power,2,2)", //
Expand Down Expand Up @@ -11593,7 +11632,7 @@ public void testJacobiSymbol() {
"1");
// check("JacobiSymbol(n, 1)", "n");
check("JacobiSymbol(-3, {1, 3, 5, 7})", //
"{JacobiSymbol(-3,1),JacobiSymbol(-3,3),JacobiSymbol(-3,5),JacobiSymbol(-3,7)}");
"{1,0,-1,1}");
}

@Test
Expand Down Expand Up @@ -11624,9 +11663,9 @@ public void testJavaForm() {
check("JavaForm(E^3-Cos(Pi^2/x), Prefix->True)", //
"F.Subtract(F.Exp(F.C3),F.Cos(F.Times(F.Sqr(F.Pi),F.Power(F.x,F.CN1))))");
check("JavaForm(E^3-Cos(Pi^2/x), Float->True)", //
"(20.085536923187668)-Math.cos((9.869604401089358)/x)");
"20.085536923187668-Math.cos(9.869604401089358/x)");
check("JavaForm(E^3-Cos(Pi^2/x), Float)", //
"(20.085536923187668)-Math.cos((9.869604401089358)/x)");
"20.085536923187668-Math.cos(9.869604401089358/x)");

check("JavaForm(Hold(D(sin(x)*cos(x),x)), prefix->True)", //
"F.D(F.Times(F.Sin(F.x),F.Cos(F.x)),F.x)");
Expand Down Expand Up @@ -11673,7 +11712,7 @@ public void testJSForm() {
+ " return x;})()\n" + "");

check("JSForm(E^3-Cos(Pi^2/x))", //
"(20.085536923187668)-Math.cos((9.869604401089358)/x)");
"20.085536923187668-Math.cos(9.869604401089358/x)");

check("Piecewise({{x, 0 < x < 1}, {x^3, 1 < x < 2}}) // JSForm", //
"\n" //
Expand Down Expand Up @@ -11701,7 +11740,7 @@ public void testJSForm() {
check("JSForm(a+b)", //
"a+b");
check("JSForm(E^3-Cos(Pi^2/x) )", //
"(20.085536923187668)-Math.cos((9.869604401089358)/x)");
"20.085536923187668-Math.cos(9.869604401089358/x)");
// JSXGraph.org syntax
EvalEngine.resetModuleCounter4JUnit();
// check(
Expand Down Expand Up @@ -11905,6 +11944,25 @@ public void testKleinInvariantJ() {
+ "0.387321+I*(-0.100372),-0.051849,0.387321+I*0.100372,1.0}");
}

@Test
public void testKronekerSymbol() {

check("KroneckerSymbol(2,3)", //
"-1");
check("Table(KroneckerSymbol(n, m), {n, 0, 5}, {m, 0, 5})", //
"{{0,1,0,0,0,0},{1,1,1,1,1,1},{0,1,0,-1,0,-1},{0,1,-1,0,1,-1},{0,1,0,1,0,1},{0,1,-\n" //
+ "1,-1,1,0}}");
check("Table(KroneckerSymbol(n, m), {n, -5, -1}, {m, -5, -1})", //
"{{0,-1,-1,1,-1},{-1,0,1,0,-1},{1,-1,0,1,-1},{1,0,-1,0,-1},{-1,-1,1,-1,-1}}");
check("KroneckerSymbol(10,13)", //
"1");
check("KroneckerSymbol(10^11 + 1, Prime(2000))", //
"-1");
check("KroneckerSymbol({2, 3, 5, 7, 11}, 6)", //
"{0,0,1,1,1}");

}

@Test
public void testValues() {
check("Values(<|a :> 1 + 1, b -> Nothing|>, Hold)", //
Expand Down Expand Up @@ -13063,6 +13121,8 @@ public void testLinearModelFit() {

@Test
public void testLinearRecurrence() {
check("LinearRecurrence({1, 1}, {1, 1}, {5, 5})", //
"{5}");
check("LinearRecurrence({0, 1, 1}, {1, 1, 1}, 0)", //
"LinearRecurrence({0,1,1},{1,1,1},0)");
check("LinearRecurrence({0, 1, 1}, {1, 1, 1}, 1)", //
Expand Down Expand Up @@ -13381,6 +13441,8 @@ public void testLog() {

@Test
public void testLog10() {
checkNumeric("10*Log10(1000)", //
"30");
checkNumeric("Log10(Interval({1/3, 2}))", //
"Interval({-Log(3)/Log(10),Log(2)/Log(10)})");
check("N(Log10(45), 100)", //
Expand Down Expand Up @@ -13679,6 +13741,18 @@ public void testMap() {
"{a,{x({b,c}),d,{e,x({f,g})}}}");
}

@Test
public void testMapApply() {
check("MapApply(h, {{a, b}, {c, d}})", //
"{h(a,b),h(c,d)}");
check("h@@@{{a,b},{c,d}}", //
"{h(a,b),h(c,d)}");
check("MapApply(h)[{{a, b}, {c}, {d, e}}]", //
"{h(a,b),h(c),h(d,e)}");
check("MapApply(h, p(x)[q(y)], Heads -> True)", //
"h(x)[h(y)]");
}

@Test
public void testMapAt() {
check("MapAt(f, {{a, b, c}, {d, e}}, {All, 2})", //
Expand Down Expand Up @@ -15986,6 +16060,17 @@ public void testNothing() {
"{b,d,e,f,g}");
}

@Test
public void testNumberDigit() {
check("RealDigits(123456)", //
"{{1,2,3,4,5,6},6}");
check("NumberDigit(123456, 2)", //
"4");
// TODO
// check("NumberDigit(12.3456, -1)", //
// "4");
}

@Test
public void testNumberQ() {
check("NumberQ(3,4)", //
Expand Down Expand Up @@ -17191,6 +17276,13 @@ public void testPi() {

@Test
public void testPick() {
check("Pick({a, b, c}, {False, True, False})", //
"{b}");
check("Pick(f(g(1, 2), h(3, 4)), {{True, False}, {False, True}})", //
"f(g(1),h(4))");
check("Pick({a, b, c, d, e}, {1, 2, 3.5, 4, 5.5}, _Integer)", //
"{a,b,d}");

// check(
// "Pick(<|s1-><|a->0,b:>1|>,s2:><|a->0,b:>1|>|>,(1+Sqrt(5))/2,5)", //
// "{RuleDelayed(Association(0))}");
Expand Down Expand Up @@ -17457,6 +17549,8 @@ public void testPlusMinus() {
public void testPolyLog() {
// check("PolyLog(10007,-1.5707963267948966)", //
// "");
check("PolyLog(-7.0, I)", //
"136.0");
check("PolyLog(1, 3, z)", //
"Pi^4/90-1/6*Log(1-z)^3*Log(z)-1/2*Log(1-z)^2*PolyLog(2,1-z)+Log(1-z)*PolyLog(3,1-z)-PolyLog(\n" //
+ "4,1-z)");
Expand Down Expand Up @@ -21345,6 +21439,8 @@ public void testSelectFirst() {

@Test
public void testSequence() {
check("Sequence( )", //
"Identity()");
check("Sequence(a,b,c)", //
"Identity(a,b,c)");
check("{Sequence( ),a}", //
Expand Down Expand Up @@ -22309,6 +22405,29 @@ public void testSort() {
"{1.0,3+I,4,a}");
}

@Test
public void testReverseSort() {
check("ReverseSort({4, 1.0, a, 3+I})", //
"{a,4,3+I,1.0}");

check("ReverseSort({c, b, d, a})", //
"{d,c,b,a}");
check("ReverseSort({-42,0,17,11,3,4,9})", //
"{17,11,9,4,3,0,-42}");
// TODO sort `e` before `d`
check("ReverseSort(<|a -> 4, b -> 1, c -> 3, d -> 2, e -> 2|>)", //
"<|a->4,c->3,d->2,e->2,b->1|>");
check("ReverseSort({0, 11, 13, 4, 9}, Greater)", //
"{0,4,9,11,13}");
check("ReverseSort({c, b, d, a}, OrderedQ({#1, #2}) &)", //
"{d,c,b,a}");

// TODO define AlphabeticOrder
// check("ReverseSort({\"cat\", \"fish\", \"catfish\", \"Cat\"}, AlphabeticOrder(\"English\"))",
// //
// "{cat,fish,catfish,Cat}");
}

@Test
public void testSortBy() {
check("SortBy({{5, 1}, {10, -1}}, Last)", //
Expand Down Expand Up @@ -22539,6 +22658,8 @@ public void testStandardize() {

@Test
public void testSquaresR() {
check("Table(SquaresR(8, n), {n, 10})", //
"{16,112,448,1136,2016,3136,5504,9328,12112,14112}");
// TODO
// check("TimeConstrained(SquaresR({3},2147483647),3)", //
// "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apfloat.Apfloat;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Test;
Expand All @@ -27,7 +25,6 @@

@RunWith(JUnit4.class)
public class NumberTest {
private static final Logger LOGGER = LogManager.getLogger();

@Test
public void testComplexNum() {
Expand Down Expand Up @@ -75,7 +72,8 @@ public void testNumberFormat() {
fail();
}
} catch (RuntimeException rex) {
LOGGER.debug("NumberTest.testNumberFormat() failed", rex);
rex.printStackTrace();
fail("NumberTest.testNumberFormat() failed");
}
assertEquals(buf.toString(), "12345.12");
}
Expand Down
Loading

0 comments on commit 7e705e6

Please sign in to comment.