public class Validate
extends org.junit.Assert
The purpose of this class is to automate the logging of deviations in order to see their evolution. This way, the developers can more easily ensure that a class is still valid even if its components or the classes it uses evolve. This is an extension of the continuous integration to validation.
For each useful method of Assert, Validate provides an implementation that will compute and store the deviation, then call the Assert method. At the end of the test (usually in an @AfterClass method), produceLog() has to be called, otherwise the validation results are not written.
This class is intended as a replacement of the org.junit.Assert class for validation purposes. Its use is similar to the Assert methods of JUnit.
Assert
Constructor and Description |
---|
Validate(Class<?> testClassIn)
constructor of the Validate object.
|
Modifier and Type | Method and Description |
---|---|
void |
assertEquals(double actual,
double nonRegExpected,
double nonRegEps,
double externalRefExpected,
double externalRefEps,
String deviationDescription)
Works as a replacement to the
Assert.assertEquals(double, double, double) method. |
void |
assertEqualsArray(double[] actual,
double[] nonRegExpected,
double nonRegEps,
double[] externalRefExpected,
double externalRefEps,
String deviationDescription)
Compute the deviation of each table value
and store it to be put in the logs by the produceLogs method.
|
void |
assertEqualsArrayWithRelativeTolerance(double[] actual,
double[] nonRegExpected,
double nonRegEps,
double[] externalRefExpected,
double externalRefEps,
String deviationDescription)
Compute the deviation of each table value
and store it to be put in the logs by the produceLogs method,
but with a relative tolerance.
|
void |
assertEqualsWithRelativeTolerance(double actual,
double nonRegExpected,
double nonRegEps,
double externalRefExpected,
double externalRefEps,
String deviationDescription)
Works as a replacement to
the
Assert.assertEquals(double, double, double) method
for a relative comparison. |
static boolean |
equals(double x,
double y,
double eps)
Returns
true if there is no double value strictly between the
arguments or the difference between them is within the range of allowed
error (inclusive). |
static boolean |
equals(double x,
double y,
int maxUlps)
Returns true if both arguments are equal or within the range of allowed
error (inclusive).
|
static boolean |
equalsWithRelativeTolerance(double x,
double y,
double eps)
Returns
true if there is no double value strictly between the
arguments or the reltaive difference between them is smaller or equal
to the given tolerance. |
void |
produceLog()
prints the log in the console and in files.
|
void |
produceLog(String logDir)
prints the log in the console and in files.
|
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public Validate(Class<?> testClassIn) throws IOException
testClassIn
- the test class, which name will be stored to be printed in the logs.IOException
- if an error occurs during the reading of the filepublic final void assertEquals(double actual, double nonRegExpected, double nonRegEps, double externalRefExpected, double externalRefEps, String deviationDescription)
Assert.assertEquals(double, double, double)
method.
Compute the deviation and store it to be put in the logs by
the produceLogs method. If the test fails, the deviation is still stored,
but " : test failed" is added to the message.actual
- the value obtained in the testnonRegExpected
- the value expected by the non-regression referencenonRegEps
- the epsilon allowed with regard to the non-regression referenceexternalRefExpected
- the value expected by the external referenceexternalRefEps
- the epsilon allowed with regard to the external referencedeviationDescription
- the description of the deviationAssert.assertEquals(double, double, double)
public final void assertEqualsArray(double[] actual, double[] nonRegExpected, double nonRegEps, double[] externalRefExpected, double externalRefEps, String deviationDescription)
actual
- the array values obtained in the testnonRegExpected
- the array values expected by the non-regression referencenonRegEps
- the epsilon allowed with regard to the non-regression referenceexternalRefExpected
- the array values expected by the external referenceexternalRefEps
- the epsilon allowed with regard to the external referencedeviationDescription
- the description of the deviationAssert.assertEquals(double, double, double)
public final void assertEqualsWithRelativeTolerance(double actual, double nonRegExpected, double nonRegEps, double externalRefExpected, double externalRefEps, String deviationDescription)
Assert.assertEquals(double, double, double)
method
for a relative comparison.
Compute the deviation and store it to be put in the logs by
the produceLogs method. If the test fails,
the deviation is still stored, but " : test failed" is added
to the message.actual
- the value obtained in the testnonRegExpected
- the value expected by the non-regression referencenonRegEps
- the epsilon allowed with regard to the non-regression referenceexternalRefExpected
- the value expected by the external referenceexternalRefEps
- the epsilon allowed with regard to the external referencedeviationDescription
- the description of the deviationAssert.assertEquals(double, double, double)
public final void produceLog() throws IOException, URISyntaxException
IOException
- if there was an error in the manipulation of the filesURISyntaxException
- if there was an error in the parsing of the URI of the filespublic final void produceLog(String logDir) throws IOException, URISyntaxException
logDir
- name of log fileIOException
- if there was an error in the manipulation of the filesURISyntaxException
- if there was an error in the parsing of the URI of the filespublic final void assertEqualsArrayWithRelativeTolerance(double[] actual, double[] nonRegExpected, double nonRegEps, double[] externalRefExpected, double externalRefEps, String deviationDescription)
actual
- the array values obtained in the testnonRegExpected
- the array values expected by the non-regression referencenonRegEps
- the epsilon allowed with regard to the non-regression referenceexternalRefExpected
- the array values expected by the external referenceexternalRefEps
- the epsilon allowed with regard to the external referencedeviationDescription
- the description of the deviationAssert.assertEquals(double, double, double)
public static boolean equals(double x, double y, double eps)
true
if there is no double value strictly between the
arguments or the difference between them is within the range of allowed
error (inclusive).
(method from Commons-Math).x
- First value.y
- Second value.eps
- Amount of allowed absolute error.true
if the values are two adjacent floating point
numbers or they are within range of each other.public static boolean equals(double x, double y, int maxUlps)
(maxUlps - 1)
(or fewer) floating point numbers between them, i.e. two adjacent floating
point numbers are considered equal.
Adapted from
Bruce Dawsonx
- first valuey
- second valuemaxUlps
- (maxUlps - 1)
is the number of floating point
values between x
and y
.true
if there are fewer than maxUlps
floating
point values between x
and y
.public static boolean equalsWithRelativeTolerance(double x, double y, double eps)
true
if there is no double value strictly between the
arguments or the reltaive difference between them is smaller or equal
to the given tolerance.
(method from Commons-Math).x
- First value.y
- Second value.eps
- Amount of allowed relative error.true
if the values are two adjacent floating point
numbers or they are within range of each other.Copyright © 2018 CNES. All Rights Reserved.