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 Mar 15, 2024
1 parent dd36d68 commit f9ed1ee
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -593,13 +593,15 @@ private static IExpr integrateAbs(IExpr function, final IExpr x) {
}

/**
* Given a <code>function</code> of a real variable <code>x</code> and an interval <code>
* [lower, upper]
* </code> of the real line, calculate the definite integral <code>F(upper)-F(lower)</code>.
* Given a continuous <code>function</code> of a real variable <code>x</code> and an interval
* <code>[lower, upper]</code> of the real line, calculate the definite integral
* <code>F(upper)-F(lower)</code>.
*
* <p>
* See: <a href="https://en.wikipedia.org/wiki/Integral">Wikipedia - Integral</a>
*
* <p>
* <b>Note:</b>: the method does not check whether the domain of integration is continuous.
*
* @param function a function of <code>x</code>
* @param xValueList a list of the form <code>{x, lower, upper}</code> with <code>3</code>
* arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,11 @@ public void testBinCounts() {

@Test
public void testBinomial() {
// issue #946
// message Binomial: BigInteger bit length `1` exceeded.
check("Binomial(12!, 9!)", //
"Binomial(12!,9!)");

check("N(Binomial(7/3, 1/5), 20)", //
"1.3331254244650286522");
check("Binomial(8.2211111111115000000, 4) ", //
Expand Down Expand Up @@ -13680,6 +13685,8 @@ public void testLevelQ() {
@Test
public void testLimit() {
// issue #931
check("Limit((-1/E^x+E^x)/(E^x+E^(-x)),x -> Infinity)", //
"1");
check("Limit((-1+Sqrt(x))/Sqrt(-1+x), x -> Infinity)", //
"1");

Expand Down Expand Up @@ -14344,6 +14351,10 @@ public void testLog() {

@Test
public void testLog10() {
check("Log10(Log10(Log(Log(Log(Log10(Log10(a)))))))", //
"Log(Log(Log(Log(Log(Log(Log(a)/Log(10))/Log(10)))))/Log(10))/Log(10)");
check("Log10(Log10(Log(Log(Log(Log10(Log10( )))))))", //
"Log(Log(Log(Log(Log(Log(Log10())/Log(10)))))/Log(10))/Log(10)");
check("Log10(1000)", //
"3");
checkNumeric("Log10({2., 5.})", //
Expand Down Expand Up @@ -17097,10 +17108,9 @@ public void testNumericalSort() {
check("NumericalSort({1,2,3,Infinity,-Infinity,E,Pi,GoldenRatio,Degree})", //
"{-Infinity,Pi/180,1,GoldenRatio,2,E,3,Pi,Infinity}");

// TODO fix Inifinity sort after quantities
check(
"NumericalSort({ Infinity, Sqrt[2], -1, 0, -Infinity, Quantity(1, \"Meters\"), Quantity(3, \"Feet\")})", //
"{-Infinity,-1,0,Sqrt(2),3[Feet],1[Meters],Infinity}");
"NumericalSort({ Infinity, Sqrt(2), -1, 0, -Infinity, Quantity(1, \"Meters\"), Quantity(3, \"Feet\")})", //
"{-Infinity,-1,0,Sqrt(2),Infinity,3[Feet],1[Meters]}");

check("NumericalSort({1, Pi, E, Infinity, -Sqrt[2], -Infinity})", //
"{-Infinity,-Sqrt(2),1,E,Pi,Infinity}");
Expand Down Expand Up @@ -19257,6 +19267,10 @@ public void testPossibleZeroQ() {

@Test
public void testPower() {
// check(
// "22610175337329362245620630780795110213748908671958118609721101133417890222511288803123590513070561131892027191395369936042326256168653778870546242363369977629202359754270184318045654379854509946171340376686223573580224107124150403623923011308302977397847548580593006903821021518558458596423345897023275437136962636706163753880297496880232736919213061706006731771987945729565465391441847486930782906711101531982421875^(1/500)
// //N", //
// "");
check("(2*x*y)^n", //
"2^n*(x*y)^n");
check("Sqrt(-d) // FullForm", //
Expand Down Expand Up @@ -20353,6 +20367,13 @@ public void testPrintableASCIIQ() {

@Test
public void testProductLog() {
check("ProductLog(9/2*Sqrt(3)*Log(3))", //
"3/2*Log(3)");
check("ProductLog(1/2*Sqrt(7)*Log(7))", //
"Log(7)/2");
check("ProductLog(1/2*Sqrt(-7)*Log(-7))", //
"ProductLog(I*1/2*Sqrt(7)*(I*Pi+Log(7)))");

// https://docs.sympy.org/latest/modules/functions/elementary.html#sympy.functions.elementary.exponential.LambertW
check("ProductLog(1.2)", //
"0.635564");
Expand All @@ -20364,8 +20385,7 @@ public void testProductLog() {
check("ProductLog(-1, -0.12)", //
"-3.32033");

check("ProductLog(9/2*Sqrt(3)*Log(3))", //
"3/2*Log(3)");

check("N(ProductLog(1/3), 100)", //
"0.2576276530497367042829162016260977909096926475032044915339511440663191292752043724596398879341002505");
check("Table(ProductLog(k, 2.3), {k, -2, 2})", //
Expand All @@ -20375,8 +20395,7 @@ public void testProductLog() {
check("ProductLog(9/3*Sqrt(5)*Log(5))", //
"ProductLog(3*Sqrt(5)*Log(5))");

check("ProductLog(1/2*Sqrt(7)*Log(7))", //
"Log(7)/2");


check("ProductLog(3*E^3)", //
"3");
Expand Down Expand Up @@ -24565,8 +24584,12 @@ public void testTakeLargest() {

@Test
public void testTakeLargestBy() {
check("TakeLargestBy({-1.5+I*0.8660254037844386,-1.5+I*(-0.8660254037844386),-1.0},Abs,3)", //
"{-1.5+I*0.8660254037844386,-1.5+I*(-0.8660254037844386),-1.0}");
// check("TakeLargestBy({-1.5+I*0.8660254037844386,-1.5+I*(-0.8660254037844386),-1.0},Abs,3)",
// //
// "{-1.5+I*0.8660254037844386,-1.5+I*(-0.8660254037844386),-1.0}");
checkNumeric("Abs(254/315+(14954373125000+I*7875000*Sqrt(9477810222))^(1/3)/31500+\n" //
+ " 1215035/63*2^(1/3)/(29908746250000+I*15750000*Sqrt(9477810222))^(1/3))//N", //
"2.3710652374514223");
check("TakeLargestBy({254/315+(14954373125000+I*7875000*Sqrt(9477810222))^(1/3)/31500+\n" //
+ " 1215035/63*2^(1/3)/(29908746250000+I*15750000*Sqrt(9477810222))^(1/3),254/315+\n" //
+ " 1215035/63*(-1+I*Sqrt(3))/(2^(2/3)*(29908746250000+I*15750000*Sqrt(9477810222))^(\n" //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,10 @@ public void testSystem040() {
"2.3715183290419594E-16+I*3.872983346207417");
checkNumeric(".5^.5", //
"0.7071067811865476");
check("N((-15)^(1/2))", //
"2.37152*10^-16+I*3.87298");
// checkNumeric("N((-15)^(1/2))", //
// "I*3.872983346207417");
checkNumeric("N((-15)^(1/2))", //
"2.3715183290419594E-16+I*3.872983346207417");
checkNumeric("N(Sin(1/2))", //
"0.479425538604203");
checkNumeric("N(1/6*(I*44^(1/2)+2))", //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ public void testGegenbauerC() {
"{ComplexInfinity,ComplexInfinity,1.17445+I*2.30854,ComplexInfinity}");
check("GegenbauerC(2, 0.5)", //
"-0.5");
// checkNumeric("GegenbauerC(5,1/8,7) //N", //
// "16839.531372070312");
checkNumeric("GegenbauerC(5,1/8,7) //N", //
"16839.53137207032");

checkNumeric("Table(GegenbauerC(10, x), {x, 1, 5})", //
"{1/5,262087/5,22619537/5,457470751/5,4517251249/5}");
check("GegenbauerC({1/3, 1/2}, 1/6, 0)", //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.matheclipse.core.system;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.Test;
import org.matheclipse.core.basic.Config;
import org.matheclipse.core.eval.EvalEngine;
Expand Down Expand Up @@ -393,6 +393,11 @@ public void testSolve() {
"{{x->-a},{x->b}}");

// github #261 - JUnit test for Apfloat switching to complex Power calculation
// checkNumeric("Solve(0.00004244131815783 == x^5 , x)", //
// "{{x->-0.10802279680851234+I*0.07848315587546606},"//
// + "{x->-0.10802279680851212+I*(-0.07848315587546606)},"//
// + "{x->0.04126103682102799+I*(-0.1269884137508598)},"//
// + "{x->0.04126103682102799+I*0.1269884137508598},{x->0.13352351997496842}}");
check("Solve(0.00004244131815783 == x^5 , x)", //
"{{x->-0.10802279680851234+I*0.07848315587546605},{x->-0.10802279680851212+I*(-0.07848315587546605)},"//
+ "{x->0.04126103682102799+I*(-0.1269884137508598)}," //
Expand Down Expand Up @@ -795,10 +800,17 @@ public void testNSolve() {
"{{x->3.0,y->5.0},{x->6.34781+I*(-1.02885),y->1.75806+I*(-2.7734)},{x->6.34781+I*1.02885,y->1.75806+I*2.7734},{x->4.30438,y->1.48389}}");

// github #261 - JUnit test for Apfloat switching to complex Power calculation
// checkNumeric("NSolve(0.00004244131815783 == x^5 , x)", //
// "{{x->-0.10802279680851234+I*0.07848315587546606}," //
// + "{x->-0.10802279680851212+I*(-0.07848315587546606)}," //
// + "{x->0.04126103682102799+I*(-0.1269884137508598)}," //
// + "{x->0.04126103682102799+I*0.1269884137508598},{x->0.13352351997496842}}");
check("NSolve(0.00004244131815783 == x^5 , x)", //
"{{x->-0.10802279680851234+I*0.07848315587546605},{x->-0.10802279680851212+I*(-0.07848315587546605)},{x->0.04126103682102799+I*(-0.1269884137508598)},"
//
+ "{x->0.04126103682102799+I*0.1269884137508598},{x->0.1335235199749684}}");


// github #247
check("NSolve((k+3)/(4)==(k)/2,{k})", //
"{{k->3.0}}");
Expand Down

0 comments on commit f9ed1ee

Please sign in to comment.