
org.jeometry.math.solver.GaussEliminationSolverTest Maven / Gradle / Ivy
package org.jeometry.math.solver;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.jeometry.factory.GeometryFactory;
import org.jeometry.math.Matrix;
import org.jeometry.math.MatrixTestData;
import org.jeometry.math.Vector;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* A Gauss Elimination based solver test.
*
* Usage:
*
* Create a class that extends this one and add the method:
*
* {@literal @}BeforeClass
* public static void initClass() {
* solver = [the solver to test];
* }
*
*
* Julien Seinturier - COMEX S.A. - [email protected] - https://github.com/jorigin/jeometryseint
*/
public class GaussEliminationSolverTest {
protected static Solver solver = null;
/**
* Initialize the test static context.
*/
@BeforeClass
public static void initClass() {
fail("method public static void init() has to be set up with @BeforeClass annotation");
}
/**
* Test the underlying solver
*/
@Test
public void solveTest() {
assertNotNull("Solver is not initialized", solver);
Matrix a = GeometryFactory.createMatrix(MatrixTestData.SOLVER_GAUSS_ELIMINATION_A);
Vector b = GeometryFactory.createVector(MatrixTestData.SOLVER_GAUSS_ELIMINATION_B);
Vector x;
try {
x = solver.solve(a, b);
assertNotNull("No solution found", x);
assertEquals("Invalid x size", a.getRowsCount(), x.getDimension());
assertEquals("Invalid x vector ("+x.getVectorComponent(0)+", "+x.getVectorComponent(1)+", "+x.getVectorComponent(2)+")", MatrixTestData.SOLVER_GAUSS_ELIMINATION_X[0], x.getVectorComponent(0), 0.000000000001d);
assertEquals("Invalid x vector ("+x.getVectorComponent(0)+", "+x.getVectorComponent(1)+", "+x.getVectorComponent(2)+")", MatrixTestData.SOLVER_GAUSS_ELIMINATION_X[1], x.getVectorComponent(1), 0.000000000001d);
assertEquals("Invalid x vector ("+x.getVectorComponent(0)+", "+x.getVectorComponent(1)+", "+x.getVectorComponent(2)+")", MatrixTestData.SOLVER_GAUSS_ELIMINATION_X[2], x.getVectorComponent(2), 0.000000000001d);
} catch (Exception e) {
fail("Unexpected excpetion "+e.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy