public abstract class AbstractDoubleArrayAssert<SELF extends AbstractDoubleArrayAssert<SELF>> extends AbstractArrayAssert<SELF,double[],Double>
Modifier and Type | Field and Description |
---|---|
protected DoubleArrays |
arrays |
actual, info, myself, throwUnsupportedExceptionOnEquals
Constructor and Description |
---|
AbstractDoubleArrayAssert(double[] actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
SELF |
contains(double... values)
Verifies that the actual array contains the given values, in any order.
|
SELF |
contains(double[] values,
Offset<Double> precision)
Verifies that the actual array contains the given values, in any order,
the comparison is done at the given precision/offset set with
Assertions.withPrecision(Double) . |
SELF |
contains(double value,
Index index)
Verifies that the actual array contains the given value at the given index.
|
SELF |
contains(double value,
Index index,
Offset<Double> precision)
Verifies that the actual array contains the given value at the given index.
|
SELF |
containsAnyOf(double... values)
Verifies that the actual array contains at least one of the given values.
|
SELF |
containsExactly(double... values)
Verifies that the actual group contains only the given values and nothing else, in order.
|
SELF |
containsExactly(double[] values,
Offset<Double> precision)
Verifies that the actual group contains only the given values and nothing else, in order.
|
SELF |
containsExactlyInAnyOrder(double... values)
Verifies that the actual group contains exactly the given values and nothing else, in any order.
|
SELF |
containsOnly(double... values)
Verifies that the actual array contains only the given values and nothing else, in any order.
|
SELF |
containsOnly(double[] values,
Offset<Double> precision)
Verifies that the actual array contains only the given values and nothing else, in any order.
|
SELF |
containsOnlyOnce(double... values)
Verifies that the actual array contains the given values only once.
|
SELF |
containsOnlyOnce(double[] values,
Offset<Double> precision)
Verifies that the actual array contains the given values only once.
|
SELF |
containsSequence(double... sequence)
Verifies that the actual array contains the given sequence, without any other values between them.
|
SELF |
containsSequence(double[] sequence,
Offset<Double> precision)
Verifies that the actual array contains the given sequence, without any other values between them.
|
SELF |
containsSubsequence(double... subsequence)
Verifies that the actual array contains the given subsequence (possibly with other values between them).
|
SELF |
containsSubsequence(double[] subsequence,
Offset<Double> precision)
Verifies that the actual array contains the given subsequence (possibly with other values between them).
|
SELF |
doesNotContain(double... values)
Verifies that the actual array does not contain the given values.
|
SELF |
doesNotContain(double[] values,
Offset<Double> precision)
Verifies that the actual array does not contain the given values.
|
SELF |
doesNotContain(double value,
Index index)
Verifies that the actual array does not contain the given value at the given index.
|
SELF |
doesNotContain(double value,
Index index,
Offset<Double> precision)
Verifies that the actual array does not contain the given value at the given index.
|
SELF |
doesNotHaveDuplicates()
Verifies that the actual array does not contain duplicates.
|
SELF |
doesNotHaveDuplicates(Offset<Double> precision)
Verifies that the actual array does not contain duplicates.
|
SELF |
endsWith(double... sequence)
Verifies that the actual array ends with the given sequence of values, without any other values between them.
|
SELF |
endsWith(double[] values,
Offset<Double> precision)
Verifies that the actual array ends with the given sequence of values, without any other values between them.
|
SELF |
hasSameSizeAs(Iterable<?> other)
Verifies that the actual group has the same size as given
Iterable . |
SELF |
hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.
|
SELF |
hasSizeBetween(int lowerBoundary,
int higherBoundary)
Verifies that the number of values in the actual group is between the given boundaries (inclusive).
|
SELF |
hasSizeGreaterThan(int boundary)
Verifies that the number of values in the actual array is greater than the given boundary.
|
SELF |
hasSizeGreaterThanOrEqualTo(int boundary)
Verifies that the number of values in the actual array is greater than or equal to the given boundary.
|
SELF |
hasSizeLessThan(int boundary)
Verifies that the number of values in the actual array is less than the given boundary.
|
SELF |
hasSizeLessThanOrEqualTo(int boundary)
Verifies that the number of values in the actual array is less than or equal to the given boundary.
|
void |
isEmpty()
Verifies that the actual group of values is empty.
|
SELF |
isNotEmpty()
Verifies that the actual group of values is not empty.
|
void |
isNullOrEmpty()
Verifies that the actual group of values is
null or empty. |
SELF |
isSorted()
Verifies that the actual array is sorted in ascending order according to the natural ordering of its elements.
|
SELF |
isSortedAccordingTo(Comparator<? super Double> comparator)
Verifies that the actual array is sorted according to the given comparator.
Empty arrays are considered sorted whatever the comparator is. One element arrays are considered sorted if the element is compatible with comparator, otherwise an AssertionError is thrown. |
SELF |
startsWith(double... sequence)
Verifies that the actual array starts with the given sequence of values, without any other values between them.
|
SELF |
startsWith(double[] values,
Offset<Double> precision)
Verifies that the actual array starts with the given sequence of values, without any other values between them.
|
SELF |
usingComparatorWithPrecision(Double precision)
Create a
Double comparator which compares double at the given precision and pass it to usingElementComparator(Comparator) . |
SELF |
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.
|
SELF |
usingElementComparator(Comparator<? super Double> customComparator)
Use given custom comparator instead of relying on actual type A
equals method to compare group
elements for incoming assertion checks. |
hasSameSizeAs, inBinary, inHexadecimal
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
protected DoubleArrays arrays
public AbstractDoubleArrayAssert(double[] actual, Class<?> selfType)
public void isNullOrEmpty()
null
or empty.
Example:
// assertions will pass
List<String> strings = new ArrayList<>();
assertThat(strings).isNullOrEmpty();
assertThat(new int[] { }).isNullOrEmpty();
// assertions will fail
assertThat(new String[] { "a", "b"}).isNullOrEmpty();
assertThat(Arrays.asList(1, 2, 3)).isNullOrEmpty();
public void isEmpty()
Example:
// assertions will pass
assertThat(new ArrayList()).isEmpty();
assertThat(new int[] { }).isEmpty();
// assertions will fail
assertThat(new String[] { "a", "b" }).isEmpty();
assertThat(Arrays.asList(1, 2, 3)).isEmpty();
public SELF isNotEmpty()
Example:
// assertions will pass
assertThat(new String[] { "a", "b" }).isNotEmpty();
assertThat(Arrays.asList(1, 2, 3)).isNotEmpty();
// assertions will fail
assertThat(new ArrayList()).isNotEmpty();
assertThat(new int[] { }).isNotEmpty();
this
assertion object.public SELF hasSize(int expected)
Example:
// assertions will pass
assertThat(new String[] { "a", "b" }).hasSize(2);
assertThat(Arrays.asList(1, 2, 3)).hasSize(3);
// assertions will fail
assertThat(new ArrayList()).hasSize(1);
assertThat(new int[] { 1, 2, 3 }).hasSize(2);
Examples :
// assertion will pass
assertThat(new double[] { 1.0, 2.0, 3.0 }).hasSize(3);
// assertion will fail
assertThat(new double[] { 1.0, 2.0, 1.0 }).hasSize(2);
expected
- the expected number of values in the actual group.this
assertion object.public SELF hasSizeGreaterThan(int boundary)
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0 }).hasSizeGreaterThan(1);
// assertion will fail
assertThat(new double[] { 1.0 }).hasSizeGreaterThan(1);
boundary
- the given value to compare the actual size to.this
assertion object.AssertionError
- if the number of values of the actual array is not greater than the boundary.public SELF hasSizeGreaterThanOrEqualTo(int boundary)
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0 }).hasSizeGreaterThanOrEqualTo(1)
.hasSizeGreaterThanOrEqualTo(2);
// assertion will fail
assertThat(new double[] { 1.0 }).hasSizeGreaterThanOrEqualTo(2);
boundary
- the given value to compare the actual size to.this
assertion object.AssertionError
- if the number of values of the actual array is not greater than or equal to the boundary.public SELF hasSizeLessThan(int boundary)
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0 }).hasSizeLessThan(3);
// assertion will fail
assertThat(new double[] { 1.0, 2.0 }).hasSizeLessThan(1);
boundary
- the given value to compare the actual size to.this
assertion object.AssertionError
- if the number of values of the actual array is not less than the boundary.public SELF hasSizeLessThanOrEqualTo(int boundary)
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0 }).hasSizeLessThanOrEqualTo(3)
.hasSizeLessThanOrEqualTo(2);
// assertion will fail
assertThat(new double[] { 1.0, 2.0 }).hasSizeLessThanOrEqualTo(1);
boundary
- the given value to compare the actual size to.this
assertion object.AssertionError
- if the number of values of the actual array is not less than or equal to the boundary.public SELF hasSizeBetween(int lowerBoundary, int higherBoundary)
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0 }).hasSizeBetween(1, 3)
.hasSizeBetween(2, 2);
// assertion will fail
assertThat(new double[] { 1.0, 2.0 }).hasSizeBetween(4, 5);
lowerBoundary
- the lower boundary compared to which actual size should be greater than or equal to.higherBoundary
- the higher boundary compared to which actual size should be less than or equal to.this
assertion object.AssertionError
- if the number of values of the actual array is not between the boundaries.public SELF hasSameSizeAs(Iterable<?> other)
Iterable
.
Examples :
// assertion will pass
assertThat(new double[] { 1.0, 2.0, 3.0 }).hasSameSizeAs(Arrays.asList(1, 2, 3));
// assertion will fail
assertThat(new double[] { 1.0, 2.0, 1.0 }).hasSameSizeAs(Arrays.asList(1, 2));
other
- the Iterable
to compare size with actual group.this
assertion object.public SELF contains(double... values)
If you want to set a precision for the comparison either use contains(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).contains(1.0, 3.0, 2.0)
.contains(3.0, 1.0)
.usingComparatorWithPrecision(0.5)
.contains(1.1, 2.1);
// assertions will fail
assertThat(values).contains(1.0, 4.0);
assertThat(values).usingComparatorWithPrecision(0.01)
.contains(1.1, 2.1);
values
- the given values.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not contain the given values.public SELF contains(double[] values, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).contains(new double[] {1.01, 3.01, 2.0}, withPrecision(0.02));
// assertions will fail
assertThat(values).contains(new double[] {1.0, 4.0}, withPrecision(0.5));
assertThat(values).contains(new double[] {4.0, 7.0}, withPrecision(2));
values
- the given values.precision
- the precision under which the value may varythis
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not contain the given values.public SELF containsOnly(double... values)
If you want to set a precision for the comparison either use containsOnly(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsOnly(1.0, 2.0, 3.0)
.containsOnly(2.0, 3.0, 1.0)
.usingComparatorWithPrecision(0.5)
.containsOnly(1.1, 3.1, 2.1);
// assertions will fail
assertThat(values).containsOnly(1.0, 4.0, 2.0, 3.0);
assertThat(values).containsOnly(4.0, 7.0);
assertThat(values).containsOnly(1.1, 2.1, 3.1);
assertThat(values).usingComparatorWithPrecision(0.01)
.containsOnly(1.1, 2.1, 3.1);
values
- the given values.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not contain the given values, i.e. the actual array contains some
or none of the given values, or the actual array contains more values than the given ones.public SELF containsOnly(double[] values, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsOnly(new double[] {1.0, 2.0, 3.0}, withPrecision(0.00001))
.containsOnly(new double[] {2.0, 3.0, 0.7}, withPrecision(0.5));
// assertions will fail
assertThat(values).containsOnly(new double[] {1.0, 4.0, 2.0, 3.0}, withPrecision(0.5));
assertThat(values).containsOnly(new double[] {4.0, 7.0}, withPrecision(0.2));
values
- the given values.precision
- the precision under which the value may varythis
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not contain the given values, i.e. the actual array contains some
or none of the given values, or the actual array contains more values than the given ones.public SELF containsOnlyOnce(double... values)
If you want to set a precision for the comparison either use containsOnlyOnce(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Examples :
// assertion will pass
assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(1.0, 2.0)
.usingComparatorWithPrecision(0.5)
.containsOnlyOnce(1.1, 3.1, 2.1);
// assertions will fail
assertThat(new double[] { 1.0, 2.0, 1.0 }).containsOnlyOnce(1.0);
assertThat(new double[] { 1.0, 2.0, 1.0 }).containsOnlyOnce(1.0, 2.0);
assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(4.0);
assertThat(new double[] { 1.0, 2.0, 3.0 }).usingComparatorWithPrecision(0.05)
.containsOnlyOnce(1.1, 2.1);
values
- the given values.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual group does not contain the given values, i.e. the actual group contains some
or none of the given values, or the actual group contains more than once these values.public SELF containsOnlyOnce(double[] values, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Examples :
// assertion will pass
assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(new double[] {1.1, 2.0}, withPrecision(0.2));
// assertions will fail
assertThat(new double[] { 1.0, 2.0, 1.0 }).containsOnlyOnce(new double[] {1.05}, withPrecision(0.1));
assertThat(new double[] { 1.0, 2.0, 3.0 }).containsOnlyOnce(new double[] {4.0}, withPrecision(0.1));
assertThat(new double[] { 1.0, 2.0, 3.0, 3.0 }).containsOnlyOnce(new double[] {0.1, 0.9, 2.0, 3.11, 4.0, 5.0}, withPrecision(0.2));
values
- the given values.precision
- the precision under which the value may varythis
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual group does not contain the given values, i.e. the actual group contains some
or none of the given values, or the actual group contains more than once these values.public SELF containsSequence(double... sequence)
If you want to set a precision for the comparison either use containsSequence(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsSequence(1.0, 2.0)
.containsSequence(1.0, 2.0, 3.0)
.containsSequence(2.0, 3.0)
.usingComparatorWithPrecision(0.5)
.containsSequence(1.1, 2.1);
// assertions will fail
assertThat(values).containsSequence(1.0, 3.0);
assertThat(values).containsSequence(4.0, 7.0);
assertThat(values).usingComparatorWithPrecision(0.01)
.containsSequence(1.1, 2.0, 3.0);
sequence
- the sequence of values to look for.this
assertion object.AssertionError
- if the actual array is null
.AssertionError
- if the given array is null
.AssertionError
- if the actual array does not contain the given sequence.public SELF containsSequence(double[] sequence, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsSequence(new double[] {1.07, 2.0}, withPrecision(0.1))
.containsSequence(new double[] {1.1, 2.1, 3.0}, withPrecision(0.2))
.containsSequence(new double[] {2.2, 3.0}, withPrecision(0.3));
// assertions will fail
assertThat(values).containsSequence(new double[] {1.0, 3.0}, withPrecision(0.2));
assertThat(values).containsSequence(new double[] {4.0, 7.0}, withPrecision(0.1));
sequence
- the sequence of values to look for.precision
- the precision under which the value may varythis
assertion object.AssertionError
- if the actual array is null
.AssertionError
- if the given array is null
.AssertionError
- if the actual array does not contain the given sequence.public SELF containsSubsequence(double... subsequence)
If you want to set a precision for the comparison either use containsSubsequence(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsSubsequence(1.0, 2.0);
.containsSubsequence(1.0, 2.0, 3.0)
.containsSubsequence(1.0, 3.0)
.usingComparatorWithPrecision(0.5)
.containsSubsequence(1.1, 2.1);
// assertions will fail
assertThat(values).containsSubsequence(3.0, 1.0);
assertThat(values).containsSubsequence(4.0, 7.0);
assertThat(values).usingComparatorWithPrecision(0.01)
.containsSubsequence(1.1, 2.0);
subsequence
- the subsequence of values to look for.this
assertion object.AssertionError
- if the actual array is null
.AssertionError
- if the given array is null
.AssertionError
- if the actual array does not contain the given subsequence.public SELF containsSubsequence(double[] subsequence, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Examples :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsSubsequence(new double[] {1.0, 2.0}, withPrecision(0.1))
.containsSubsequence(new double[] {1.0, 2.07, 3.0}, withPrecision(0.1))
.containsSubsequence(new double[] {2.1, 2.9}, withPrecision(0.2));
// assertions will fail
assertThat(values).containsSubsequence(new double[] {1.0, 3.0}, withPrecision(0.1));
assertThat(values).containsSubsequence(new double[] {4.0, 7.0}, withPrecision(0.1));
subsequence
- the subsequence of values to look for.precision
- the precision under which the value may vary.this
assertion object.AssertionError
- if the actual array is null
.AssertionError
- if the given array is null
.AssertionError
- if the actual array does not contain the given subsequence.public SELF contains(double value, Index index)
If you want to set a precision for the comparison either use contains(double, Index, Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).contains(1.0, atIndex(O))
.contains(3.0, atIndex(2))
.usingComparatorWithPrecision(0.5)
.contains(3.1, atIndex(2));
// assertions will fail
assertThat(values).contains(1.0, atIndex(1));
assertThat(values).contains(4.0, atIndex(2));
assertThat(values).usingComparatorWithPrecision(0.01)
.contains(3.1, atIndex(2));
value
- the value to look for.index
- the index where the value should be stored in the actual array.this
assertion object.AssertionError
- if the actual array is null
or empty.NullPointerException
- if the given Index
is null
.IndexOutOfBoundsException
- if the value of the given Index
is equal to or greater than the size of
the actual array.AssertionError
- if the actual array does not contain the given value at the given index.public SELF contains(double value, Index index, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).contains(1.0, atIndex(O), withPrecision(0.01))
.contains(3.3, atIndex(2), withPrecision(0.5));
// assertions will fail
assertThat(values).contains(1.0, atIndex(1), withPrecision(0.2));
assertThat(values).contains(4.5, atIndex(2), withPrecision(0.1));
value
- the value to look for.index
- the index where the value should be stored in the actual array.precision
- the precision under which the value may vary.this
assertion object.AssertionError
- if the actual array is null
or empty.NullPointerException
- if the given Index
is null
.IndexOutOfBoundsException
- if the value of the given Index
is equal to or greater than the size of
the actual array.AssertionError
- if the actual array does not contain the given value at the given index.public SELF doesNotContain(double... values)
If you want to set a precision for the comparison either use doesNotContain(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).doesNotContain(4.0, 8.0)
.usingComparatorWithPrecision(0.0001)
.doesNotContain(1.01, 2.01);
// assertions will fail
assertThat(values).doesNotContain(1.0, 4.0, 8.0);
assertThat(values).usingComparatorWithPrecision(0.1)
.doesNotContain(1.001, 2.001);
values
- the given values.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array contains any of the given values.public SELF doesNotContain(double[] values, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).doesNotContain(new double[] {4.0, 8.0}, withPrecision(0.5));
// assertion will fail
assertThat(values).doesNotContain(new double[] {1.05, 4.0, 8.0}, withPrecision(0.1));
values
- the given values.precision
- the precision under which the values may vary.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array contains any of the given values.public SELF doesNotContain(double value, Index index)
If you want to set a precision for the comparison either use doesNotContain(double, Index, Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).doesNotContain(1.0, atIndex(1))
.doesNotContain(2.0, atIndex(0))
.usingComparatorWithPrecision(0.001)
.doesNotContain(1.1, atIndex(0));
// assertions will fail
assertThat(values).doesNotContain(1.0, atIndex(0));
assertThat(values).usingComparatorWithPrecision(0.1)
.doesNotContain(1.001, atIndex(0));
value
- the value to look for.index
- the index where the value should be stored in the actual array.this
assertion object.AssertionError
- if the actual array is null
.NullPointerException
- if the given Index
is null
.AssertionError
- if the actual array contains the given value at the given index.public SELF doesNotContain(double value, Index index, Offset<Double> precision)
Assertions.withPrecision(Double)
.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).doesNotContain(1.01, atIndex(1), withPrecision(0.0001))
.doesNotContain(2.05, atIndex(0), withPrecision(0.1));
// assertion will fail
assertThat(values).doesNotContain(1.01, atIndex(0), withPrecision(0.1));
value
- the value to look for.index
- the index where the value should be stored in the actual array.precision
- the precision under which the values may vary.this
assertion object.AssertionError
- if the actual array is null
.NullPointerException
- if the given Index
is null
.AssertionError
- if the actual array contains the given value at the given index.public SELF doesNotHaveDuplicates()
If you want to set a precision for the comparison either use doesNotHaveDuplicates(Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0, 3.0 }).doesNotHaveDuplicates();
assertThat(new double[] { 1.0, 1.1 }).usingComparatorWithPrecision(0.01)
.doesNotHaveDuplicates();
// assertion will fail
assertThat(new double[] { 1.0, 1.0, 2.0, 3.0 }).doesNotHaveDuplicates();
assertThat(new double[] { 1.0, 1.1 }).usingComparatorWithPrecision(0.5)
.doesNotHaveDuplicates();
this
assertion object.AssertionError
- if the actual array is null
.AssertionError
- if the actual array contains duplicates.public SELF doesNotHaveDuplicates(Offset<Double> precision)
Assertions.withPrecision(Double)
.
Example:
// assertion will pass
assertThat(new double[] { 1.0, 2.0, 3.0 }).doesNotHaveDuplicates(withPrecision(0.1));
assertThat(new double[] { 1.1, 1.2, 1.3 }).doesNotHaveDuplicates(withPrecision(0.05));
// assertion will fail
assertThat(new double[] { 1.0, 1.01, 2.0 }).doesNotHaveDuplicates(withPrecision(0.1));
precision
- the precision under which the values may vary.this
assertion object.AssertionError
- if the actual array is null
.AssertionError
- if the actual array contains duplicates.public SELF startsWith(double... sequence)
containsSequence(double...)
, but it also verifies that the first element in the
sequence is also first element of the actual array.
If you want to set a precision for the comparison either use startsWith(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).startsWith(1.0, 2.0)
.usingComparatorWithPrecision(0.5)
.startsWith(1.1, 2.1);
// assertion will fail
assertThat(values).startsWith(2.0, 3.0);
sequence
- the sequence of values to look for.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not start with the given sequence.public SELF startsWith(double[] values, Offset<Double> precision)
containsSequence(double...)
, but it also verifies that the first element in the
sequence is also first element of the actual array.
The comparison is done at the given precision/offset set with Assertions.withPrecision(Double)
.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).startsWith(new double[] {1.01, 2.01}, withPrecision(0.1));
// assertions will fail
assertThat(values).startsWith(new double[] {2.0, 1.0}, withPrecision(0.1))
assertThat(values).startsWith(new double[] {1.1, 2.1}, withPrecision(0.5))
values
- the sequence of values to look for.precision
- the precision under which the values may vary.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not end with the given sequence.public SELF endsWith(double... sequence)
containsSequence(double...)
, but it also verifies that the last element in the
sequence is also last element of the actual array.
If you want to set a precision for the comparison either use endsWith(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).endsWith(2.0, 3.0)
.usingComparatorWithPrecision(0.5)
.endsWith(2.1, 3.1);
// assertion will fail
assertThat(values).endsWith(1.0, 3.0);
sequence
- the sequence of values to look for.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not end with the given sequence.public SELF endsWith(double[] values, Offset<Double> precision)
containsSequence(double...)
, but it also verifies that the last element in the
sequence is also last element of the actual array.
The comparison is done at the given precision/offset set with Assertions.withPrecision(Double)
.
Example:
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).endsWith(new double[] {2.01, 3.01}, withPrecision(0.1));
// assertion will fail
assertThat(values).endsWith(new double[] {3.0, 2.0}, withPrecision(0.1))
assertThat(values).endsWith(new double[] {2.1, 3.1}, withPrecision(0.5))
values
- the sequence of values to look for.precision
- the precision under which the values may vary.this
assertion object.NullPointerException
- if the given argument is null
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual array is null
.AssertionError
- if the actual array does not end with the given sequence.public SELF isSorted()
All array elements must be primitive or implement the Comparable
interface and must be mutually comparable (that is,
e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array), examples :
this
assertion object.public SELF isSortedAccordingTo(Comparator<? super Double> comparator)
comparator
- the Comparator
used to compare array elementsthis
assertion object.public SELF usingElementComparator(Comparator<? super Double> customComparator)
equals
method to compare group
elements for incoming assertion checks.
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples : // compares invoices by payee
assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList);
// compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice);
// as assertThat(invoiceList) creates a new assertion, it falls back to standard comparison strategy
// based on Invoice's equal method to compare invoiceList elements to lowestInvoice.
assertThat(invoiceList).contains(lowestInvoice);
// standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ...
assertThat(fellowshipOfTheRing).contains(gandalf)
.doesNotContain(sauron);
// ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf.
assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator)
.contains(sauron);
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public SELF usingDefaultElementComparator()
This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator)
.
this
assertion object.public SELF containsExactly(double... values)
Verifies that the actual group contains only the given values and nothing else, in order.
If you want to set a precision for the comparison either use containsExactly(double[], Offset)
or usingComparatorWithPrecision(Double)
before calling the assertion.
Example :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertions will pass
assertThat(values).containsExactly(1.0, 2.0, 3.0)
.usingComparatorWithPrecision(0.2)
.containsExactly(1.1, 2.1, 2.9);
// assertion will fail as actual and expected order differ
assertThat(values).containsExactly(2.0, 1.0, 3.0);
values
- the given values.this
assertion object.NullPointerException
- if the given argument is null
.AssertionError
- if the actual group is null
.AssertionError
- if the actual group does not contain the given values with same order, i.e. the actual group
contains some or none of the given values, or the actual group contains more values than the given ones
or values are the same but the order is not.public SELF containsExactlyInAnyOrder(double... values)
Example :
// assertions will pass
assertThat(new double[] { 1.0, 2.0 }).containsExactlyInAnyOrder(1.0, 2.0);
assertThat(new double[] { 1.0, 2.0, 1.0 }).containsExactlyInAnyOrder(1.0, 1.0, 2.0);
// assertions will fail
assertThat(new double[] { 1.0, 2.0 }).containsExactlyInAnyOrder(1.0);
assertThat(new double[] { 1.0 }).containsExactlyInAnyOrder(1.0, 2.0);
assertThat(new double[] { 1.0, 2.0, 1.0 }).containsExactlyInAnyOrder(1.0, 2.0);
values
- the given values.this
assertion object.NullPointerException
- if the given argument is null
.AssertionError
- if the actual group is null
.AssertionError
- if the actual group does not contain the given values, i.e. the actual group
contains some or none of the given values, or the actual group contains more values than the given ones.public SELF containsExactly(double[] values, Offset<Double> precision)
Example :
double[] values = new double[] { 1.0, 2.0, 3.0 };
// assertion will pass
assertThat(values).containsExactly(new double[] {1.0, 1.98, 3.01}, withPrecision(0.05));
// assertion fails because |1.0 -1.1| > 0.05 (precision).
assertThat(values).containsExactly(new double[] {1.1, 2.0, 3.01}, withPrecision(0.05));
// assertion will fail as actual and expected order differ
assertThat(values).containsExactly(new double[] {1.98, 1.0, 3.01}, withPrecision(0.05));
values
- the given values.precision
- the precision under which the values may vary.this
assertion object.NullPointerException
- if the given argument is null
.AssertionError
- if the actual group is null
.AssertionError
- if the actual group does not contain the given values within the specified precision
with same order, i.e. the actual group contains some or none of the given values, or the actual group contains
more values than the given ones or values are the same but the order is not.public SELF usingComparatorWithPrecision(Double precision)
Double
comparator which compares double at the given precision and pass it to usingElementComparator(Comparator)
.
All the following assertions will use this comparator to compare double[] elements.precision
- precision used to compare Double
.this
assertion object.public SELF containsAnyOf(double... values)
Example :
double[] oneTwoThree = { 1.0, 2.0, 3.0 };
// assertions will pass
assertThat(oneTwoThree).containsAnyOf(2.0)
.containsAnyOf(2.0, 3.0)
.containsAnyOf(1.0, 2.0, 3.0)
.containsAnyOf(1.0, 2.0, 3.0, 4.0)
.containsAnyOf(5.0, 6.0, 7.0, 2.0);
// assertions will fail
assertThat(oneTwoThree).containsAnyOf(4.0);
assertThat(oneTwoThree).containsAnyOf(4.0, 5.0, 6.0, 7.0);
values
- the values whose at least one which is expected to be in the array under test.this
assertion object.NullPointerException
- if the array of values is null
.IllegalArgumentException
- if the array of values is empty and the array under test is not empty.AssertionError
- if the array under test is null
.AssertionError
- if the array under test does not contain any of the given values
.Copyright © 2014–2019 AssertJ. All rights reserved.