Skip to content

Commit

Permalink
refact: rewrite static classes to increase test coverage (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfstatoil authored Aug 2, 2023
1 parent 47ef4f9 commit 9f2f2ce
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
12 changes: 9 additions & 3 deletions src/main/java/neqsim/MathLib/generalMath/TDMAsolve.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
* @author Even Solbraa
* @version $Id: $Id
*/
public class TDMAsolve {
public final class TDMAsolve {

/**
* Dummy constructor, not for use. Class is to be considered static.
*/
private TDMAsolve() {}

/**
* <p>
* solve.
Expand All @@ -26,11 +32,11 @@ public class TDMAsolve {
* @param r an array of {@link double} objects
* @return an array of {@link double} objects
*/
public static double[] solve(double a[], double b[], double c[], double r[]) {
public static double[] solve(double[] a, double[] b, double[] c, double[] r) {
int length = a.length;
double[] u = new double[length];
double bet = 0;
double gam[] = new double[length];
double[] gam = new double[length];

bet = b[0];
u[0] = r[0] / bet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
* @author Even Solbraa
* @version $Id: $Id
*/
public class NumericalDerivative implements java.io.Serializable {
public final class NumericalDerivative implements java.io.Serializable {
private static final long serialVersionUID = 1000;

final static double CON = 1.4;
final static double CON2 = CON * CON;
final static double BIG = 1 * Math.pow(10, 30);
final static int NTAB = 100;
final static double SAFE = 2;
static final double CON = 1.4;
static final double CON2 = CON * CON;
static final double BIG = 1 * Math.pow(10, 30);
static final int NTAB = 100;
static final double SAFE = 2;

/**
* <p>
* Constructor for NumericalDerivative.
* </p>
* Dummy constructor, not for use. Class is to be considered static.
*/
public NumericalDerivative() {}
private NumericalDerivative() {}

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
* @author ESOL
* @version $Id: $Id
*/
public class ChemicalReactionFactory {
public final class ChemicalReactionFactory {
static Logger logger = LogManager.getLogger(ChemicalReactionFactory.class);

/**
* <p>
* Constructor for ChemicalReactionFactory.
* </p>
* Dummy constructor, not for use. Class is to be considered static.
*/
public ChemicalReactionFactory() {}
private ChemicalReactionFactory() {}

/**
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
* @author Even Solbraa
* @version $Id: $Id
*/
public class NumericalDerivative implements java.io.Serializable {
public final class NumericalDerivative implements java.io.Serializable {
private static final long serialVersionUID = 1000;

final static double CON = 1.4;
final static double CON2 = CON * CON;
final static double BIG = 1.0e30;
final static int NTAB = 10;
final static double SAFE = 2.0;
static final double CON = 1.4;
static final double CON2 = CON * CON;
static final double BIG = 1.0e30;
static final int NTAB = 10;
static final double SAFE = 2.0;

/**
* <p>
* Constructor for NumericalDerivative.
* </p>
* Dummy constructor, not for use. Class is to be considered static.
*/
public NumericalDerivative() {}
private NumericalDerivative() {}

/**
* <p>
Expand All @@ -42,15 +40,16 @@ public NumericalDerivative() {}
*/
public static double calcDerivative(StatisticsBaseClass system, int sampleNumber,
int parameterNumber) {
double errt, fac, hh, ans, err;
double errt;
double fac;
double hh;
double h = Math.abs(system.getSampleSet().getSample(sampleNumber).getFunction()
.getFittingParams(parameterNumber)) / 1.0e3;
if (h == 0.0) {
System.out.println("h must be larger than 0!");
System.out.println("setting it to 1.0e-10");
h = 1.0e-10;
}
double[][] a = new double[NTAB][NTAB];

hh = h;
// System.out.println("hh " + hh);
Expand All @@ -65,9 +64,10 @@ public static double calcDerivative(StatisticsBaseClass system, int sampleNumber
system.getSampleSet().getSample(sampleNumber).getFunction().setFittingParams(parameterNumber,
oldFittingParam1);

double[][] a = new double[NTAB][NTAB];
a[0][0] = (val1 - val2) / (2.0 * hh);
ans = a[0][0];
err = BIG;
double ans = a[0][0];
double err = BIG;

for (int i = 1; i <= 0 * NTAB - 1; i++) {
hh /= CON;
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/neqsim/thermo/FluidCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
import neqsim.thermo.system.SystemInterface;

/**
* Used to generate fluids of type SystemInterface
* <p>
* FluidCreator class.
* </p>
* Used to generate fluids of type SystemInterface.
*
* @author esol
* @version $Id: $Id
*/
public class FluidCreator {
/** Constant <code>hasWater=false</code> */
public final class FluidCreator {
/** Constant <code>hasWater=false</code>. */
public static boolean hasWater = false;
/** Constant <code>autoSelectModel=false</code> */
/** Constant <code>autoSelectModel=false</code>. */
public static boolean autoSelectModel = false;
/** Constant <code>thermoModel="srk"</code> */
/** Constant <code>thermoModel="srk"</code>. */
public static String thermoModel = "srk";
/** Constant <code>thermoMixingRule="classic"</code> */
/** Constant <code>thermoMixingRule="classic"</code>. */
public static String thermoMixingRule = "classic";


/**
* Dummy constructor, not for use. Class is to be considered static.
*/
private FluidCreator() {}

/**
* Create SystemInterface.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DifferentialLiberationTest {

@Test
void testRunCalc() {
SystemInterface tempSystem = new FluidCreator().create("black oil");
SystemInterface tempSystem = FluidCreator.create("black oil");

DifferentialLiberation CVDsim = new DifferentialLiberation(tempSystem);
CVDsim.setPressures(new double[] {300.0, 250.0, 200.0, 150.0, 100.0, 70.0, 50.0, 30.0, 10.0});
Expand Down

0 comments on commit 9f2f2ce

Please sign in to comment.