public abstract class AbstractDoubleArrayAssert<S extends AbstractDoubleArrayAssert<S>> extends AbstractArrayAssert<S,double[],Double>
Modifier and Type | Field and Description |
---|---|
protected DoubleArrays |
arrays |
actual, info, myself
Constructor and Description |
---|
AbstractDoubleArrayAssert(double[] actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
contains(double... values)
Verifies that the actual array contains the given values, in any order.
|
S |
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) . |
S |
contains(double value,
Index index)
Verifies that the actual array contains the given value at the given index.
|
S |
contains(double value,
Index index,
Offset<Double> precision)
Verifies that the actual array contains the given value at the given index.
|
S |
containsExactly(double... values)
Verifies that the actual group contains only the given values and nothing else, in order.
|
S |
containsExactly(double[] values,
Offset<Double> precision)
Verifies that the actual group contains only the given values and nothing else, in order.
|
S |
containsOnly(double... values)
Verifies that the actual array contains only the given values and nothing else, in any order.
|
S |
containsOnly(double[] values,
Offset<Double> precision)
Verifies that the actual array contains only the given values and nothing else, in any order.
|
S |
containsOnlyOnce(double... values)
Verifies that the actual array contains the given values only once.
|
S |
containsOnlyOnce(double[] values,
Offset<Double> precision)
Verifies that the actual array contains the given values only once.
|
S |
containsSequence(double... sequence)
Verifies that the actual array contains the given sequence, without any other values between them.
|
S |
containsSequence(double[] sequence,
Offset<Double> precision)
Verifies that the actual array contains the given sequence, without any other values between them.
|
S |
containsSubsequence(double... subsequence)
Verifies that the actual array contains the given subsequence (possibly with other values between them).
|
S |
containsSubsequence(double[] subsequence,
Offset<Double> precision)
Verifies that the actual array contains the given subsequence (possibly with other values between them).
|
S |
doesNotContain(double... values)
Verifies that the actual array does not contain the given values.
|
S |
doesNotContain(double[] values,
Offset<Double> precision)
Verifies that the actual array does not contain the given values.
|
S |
doesNotContain(double value,
Index index)
Verifies that the actual array does not contain the given value at the given index.
|
S |
doesNotContain(double value,
Index index,
Offset<Double> precision)
Verifies that the actual array does not contain the given value at the given index.
|
S |
doesNotHaveDuplicates()
Verifies that the actual array does not contain duplicates.
|
S |
doesNotHaveDuplicates(Offset<Double> precision)
Verifies that the actual array does not contain duplicates.
|
S |
endsWith(double... sequence)
Verifies that the actual array ends with the given sequence of values, without any other values between them.
|
S |
endsWith(double[] values,
Offset<Double> precision)
Verifies that the actual array ends with the given sequence of values, without any other values between them.
|
S |
hasSameSizeAs(Iterable<?> other)
Verifies that the actual group has the same size as given
Iterable . |
S |
hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.
|
void |
isEmpty()
Verifies that the actual group of values is empty.
|
S |
isNotEmpty()
Verifies that the actual group of values is not empty.
|
void |
isNullOrEmpty()
Verifies that the actual group of values is
null or empty. |
S |
isSorted()
Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.
|
S |
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 element is compatible with comparator, otherwise an AssertionError is thrown. |
S |
startsWith(double... sequence)
Verifies that the actual array starts with the given sequence of values, without any other values between them.
|
S |
startsWith(double[] values,
Offset<Double> precision)
Verifies that the actual array starts with the given sequence of values, without any other values between them.
|
S |
usingComparatorWithPrecision(Double precision)
Create a
Double comparator which compares double at the given precision and pass it to usingElementComparator(Comparator) . |
S |
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.
|
S |
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, hasToString, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, setCustomRepresentation, throwAssertionError, 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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 S 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))
sequence
- 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 S 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 S 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))
sequence
- 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 S 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 S isSortedAccordingTo(Comparator<? super Double> comparator)
comparator
- the Comparator
used to compare array elementsthis
assertion object.public S 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 S usingDefaultElementComparator()
This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator)
.
this
assertion object.public S 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 S 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 S 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
- precisin used to compare Double
.this
assertion object.Copyright © 2014–2016 AssertJ. All rights reserved.