Skip to content

Commit 4b0fbb8

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 3dc0975 + 63c8423 commit 4b0fbb8

File tree

111 files changed

+2340
-951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2340
-951
lines changed

apache-commons-math/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.baeldung</groupId>
8+
<artifactId>apache-commons-math</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
13+
</properties>
14+
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>org.apache.maven.plugins</groupId>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<version>${maven-compiler-plugin.version}</version>
21+
<configuration>
22+
<source>1.8</source>
23+
<target>1.8</target>
24+
</configuration>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.apache.commons</groupId>
32+
<artifactId>commons-math3</artifactId>
33+
<version>3.6.1</version>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
<version>4.12</version>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.complex.Complex;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class ComplexTests {
8+
9+
@Test
10+
public void whenComplexPow_thenCorrect() {
11+
Complex first = new Complex(1.0, 3.0);
12+
Complex second = new Complex(2.0, 5.0);
13+
14+
Complex power = first.pow(second);
15+
16+
Assert.assertEquals(-0.007563724861696302, power.getReal(), 1e-7);
17+
Assert.assertEquals(0.01786136835085382, power.getImaginary(), 1e-7);
18+
}
19+
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.fraction.Fraction;
4+
import org.apache.commons.math3.fraction.FractionFormat;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
public class FractionTests {
9+
10+
@Test
11+
public void whenFractionAdd_thenCorrect() {
12+
Fraction lhs = new Fraction(1, 3);
13+
Fraction rhs = new Fraction(2, 5);
14+
Fraction sum = lhs.add(rhs);
15+
16+
Assert.assertEquals(11, sum.getNumerator());
17+
Assert.assertEquals(15, sum.getDenominator());
18+
}
19+
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.geometry.euclidean.twod.Line;
4+
import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
8+
public class GeometryTests {
9+
10+
@Test
11+
public void whenLineIntersection_thenCorrect() {
12+
Line l1 = new Line(new Vector2D(0, 0), new Vector2D(1, 1), 0);
13+
Line l2 = new Line(new Vector2D(0, 1), new Vector2D(1, 1.5), 0);
14+
15+
Vector2D intersection = l1.intersection(l2);
16+
17+
Assert.assertEquals(2, intersection.getX(), 1e-7);
18+
Assert.assertEquals(2, intersection.getY(), 1e-7);
19+
}
20+
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.analysis.UnivariateFunction;
4+
import org.apache.commons.math3.analysis.integration.SimpsonIntegrator;
5+
import org.apache.commons.math3.analysis.integration.UnivariateIntegrator;
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
public class IntegrationTests {
10+
11+
@Test
12+
public void whenUnivariateIntegratorIntegrate_thenCorrect() {
13+
final UnivariateFunction function = v -> v;
14+
final UnivariateIntegrator integrator = new SimpsonIntegrator(1.0e-12, 1.0e-8, 1, 32);
15+
16+
final double i = integrator.integrate(100, function, 0, 10);
17+
18+
Assert.assertEquals(16 + 2d/3d, i, 1e-7);
19+
}
20+
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.linear.*;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class LinearAlgebraTests {
8+
9+
@Test
10+
public void whenDecompositionSolverSolve_thenCorrect() {
11+
RealMatrix a =
12+
new Array2DRowRealMatrix(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } },
13+
false);
14+
RealVector b = new ArrayRealVector(new double[] { 1, -2, 1 }, false);
15+
16+
DecompositionSolver solver = new LUDecomposition(a).getSolver();
17+
18+
RealVector solution = solver.solve(b);
19+
20+
Assert.assertEquals(-0.3698630137, solution.getEntry(0), 1e-7);
21+
Assert.assertEquals(0.1780821918, solution.getEntry(1), 1e-7);
22+
Assert.assertEquals(-0.602739726, solution.getEntry(2), 1e-7);
23+
}
24+
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.distribution.NormalDistribution;
4+
import org.junit.Test;
5+
6+
public class ProbabilitiesTests {
7+
8+
@Test
9+
public void whenNormalDistributionSample_thenSuccess() {
10+
final NormalDistribution normalDistribution = new NormalDistribution(10, 3);
11+
12+
System.out.println(normalDistribution.sample());
13+
}
14+
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.analysis.UnivariateFunction;
4+
import org.apache.commons.math3.analysis.solvers.BracketingNthOrderBrentSolver;
5+
import org.apache.commons.math3.analysis.solvers.UnivariateSolver;
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
public class RootFindingTests {
10+
11+
@Test
12+
public void whenUnivariateSolverSolver_thenCorrect() {
13+
final UnivariateFunction function = v -> Math.pow(v, 2) - 2;
14+
UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-8, 5);
15+
double c = solver.solve(100, function, -10.0, 10.0, 0);
16+
17+
Assert.assertEquals(-Math.sqrt(2), c, 1e-7);
18+
}
19+
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.commons.math;
2+
3+
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
4+
import org.junit.Assert;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
public class StatisticsTests {
9+
10+
private double[] values;
11+
private DescriptiveStatistics descriptiveStatistics;
12+
13+
@Before
14+
public void setUp() {
15+
values = new double[] {65, 51 , 16, 11 , 6519, 191 ,0 , 98, 19854, 1, 32};
16+
17+
descriptiveStatistics = new DescriptiveStatistics();
18+
for(double v : values) {
19+
descriptiveStatistics.addValue(v);
20+
}
21+
}
22+
23+
@Test
24+
public void whenDescriptiveStatisticsGetMean_thenCorrect() {
25+
Assert.assertEquals(2439.8181818181815, descriptiveStatistics.getMean(), 1e-7);
26+
}
27+
28+
@Test
29+
public void whenDescriptiveStatisticsGetMedian_thenCorrect() {
30+
Assert.assertEquals(51, descriptiveStatistics.getPercentile(50), 1e-7);
31+
}
32+
33+
@Test
34+
public void whenDescriptiveStatisticsGetStandardDeviation_thenCorrect() {
35+
Assert.assertEquals(6093.054649651221, descriptiveStatistics.getStandardDeviation(), 1e-7);
36+
}
37+
38+
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<configuration>
2-
33
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
44
<encoder>
55
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
66
</pattern>
77
</encoder>
88
</appender>
99

10-
<!-- <logger name="org.springframework" level="WARN" /> -->
10+
<logger name="org.springframework" level="WARN" />
11+
<logger name="org.springframework.transaction" level="WARN" />
12+
13+
<!-- in order to debug some marshalling issues, this needs to be TRACE -->
14+
<logger name="org.springframework.web.servlet.mvc" level="WARN" />
1115

1216
<root level="INFO">
1317
<appender-ref ref="STDOUT" />
1418
</root>
15-
1619
</configuration>

0 commit comments

Comments
 (0)