code
stringlengths 23
201k
| docstring
stringlengths 17
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
72
| path
stringlengths 11
317
| url
stringlengths 57
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
@Test
public void negativeTolerances() {
isWithinNegativeToleranceThrows(-0.5);
isNotWithinNegativeToleranceThrows(-0.5);
// You know what's worse than zero? Negative zero.
isWithinNegativeToleranceThrows(-0.0);
isNotWithinNegativeToleranceThrows(-0.0);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
negativeTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void isWithinNegativeToleranceThrows(double tolerance) {
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(5.0).isWithin(tolerance).of(5.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is negative",
"expected",
"was",
"tolerance");
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isWithinNegativeToleranceThrows
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void isNotWithinNegativeToleranceThrows(double tolerance) {
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(5.0).isNotWithin(tolerance).of(5.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is negative",
"expected not to be",
"was",
"tolerance");
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotWithinNegativeToleranceThrows
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void nanTolerances() {
{
AssertionError e = expectFailure(whenTesting -> whenTesting.that(1.0).isWithin(NaN).of(1.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected",
"was",
"tolerance");
}
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0).isNotWithin(NaN).of(1.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected not to be",
"was",
"tolerance");
}
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
nanTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void positiveInfinityTolerances() {
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0).isWithin(POSITIVE_INFINITY).of(1.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected",
"was",
"tolerance");
}
{
AssertionError e =
expectFailure(
whenTesting -> whenTesting.that(1.0).isNotWithin(POSITIVE_INFINITY).of(1.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected not to be",
"was",
"tolerance");
}
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
positiveInfinityTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@SuppressWarnings("FloatingPointAssertionWithinEpsilon") // test of a bogus call
@Test
public void negativeInfinityTolerances() {
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0).isWithin(NEGATIVE_INFINITY).of(1.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected",
"was",
"tolerance");
}
{
AssertionError e =
expectFailure(
whenTesting -> whenTesting.that(1.0).isNotWithin(NEGATIVE_INFINITY).of(1.0));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected not to be",
"was",
"tolerance");
}
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
negativeInfinityTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinOfZero() {
assertThat(+0.0).isWithin(0.00001).of(+0.0);
assertThat(+0.0).isWithin(0.00001).of(-0.0);
assertThat(-0.0).isWithin(0.00001).of(+0.0);
assertThat(-0.0).isWithin(0.00001).of(-0.0);
assertThat(+0.0).isWithin(0.0).of(+0.0);
assertThat(+0.0).isWithin(0.0).of(-0.0);
assertThat(-0.0).isWithin(0.0).of(+0.0);
assertThat(-0.0).isWithin(0.0).of(-0.0);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isWithinOfZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinOfZero() {
assertThat(+0.0).isNotWithin(0.00001).of(+1.0);
assertThat(+0.0).isNotWithin(0.00001).of(-1.0);
assertThat(-0.0).isNotWithin(0.00001).of(+1.0);
assertThat(-0.0).isNotWithin(0.00001).of(-1.0);
assertThat(+1.0).isNotWithin(0.00001).of(+0.0);
assertThat(+1.0).isNotWithin(0.00001).of(-0.0);
assertThat(-1.0).isNotWithin(0.00001).of(+0.0);
assertThat(-1.0).isNotWithin(0.00001).of(-0.0);
assertThat(+1.0).isNotWithin(0.0).of(+0.0);
assertThat(+1.0).isNotWithin(0.0).of(-0.0);
assertThat(-1.0).isNotWithin(0.0).of(+0.0);
assertThat(-1.0).isNotWithin(0.0).of(-0.0);
assertThatIsNotWithinFails(-0.0, 0.0, 0.0);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotWithinOfZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinZeroTolerance() {
double max = Double.MAX_VALUE;
assertThat(max).isWithin(0.0).of(max);
assertThat(NEARLY_MAX).isWithin(0.0).of(NEARLY_MAX);
assertThatIsWithinFails(max, 0.0, NEARLY_MAX);
assertThatIsWithinFails(NEARLY_MAX, 0.0, max);
double negativeMax = -1.0 * Double.MAX_VALUE;
assertThat(negativeMax).isWithin(0.0).of(negativeMax);
assertThat(NEGATIVE_NEARLY_MAX).isWithin(0.0).of(NEGATIVE_NEARLY_MAX);
assertThatIsWithinFails(negativeMax, 0.0, NEGATIVE_NEARLY_MAX);
assertThatIsWithinFails(NEGATIVE_NEARLY_MAX, 0.0, negativeMax);
double min = Double.MIN_VALUE;
assertThat(min).isWithin(0.0).of(min);
assertThat(OVER_MIN).isWithin(0.0).of(OVER_MIN);
assertThatIsWithinFails(min, 0.0, OVER_MIN);
assertThatIsWithinFails(OVER_MIN, 0.0, min);
double negativeMin = -1.0 * Double.MIN_VALUE;
assertThat(negativeMin).isWithin(0.0).of(negativeMin);
assertThat(UNDER_NEGATIVE_MIN).isWithin(0.0).of(UNDER_NEGATIVE_MIN);
assertThatIsWithinFails(negativeMin, 0.0, UNDER_NEGATIVE_MIN);
assertThatIsWithinFails(UNDER_NEGATIVE_MIN, 0.0, negativeMin);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isWithinZeroTolerance
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinZeroTolerance() {
double max = Double.MAX_VALUE;
assertThatIsNotWithinFails(max, 0.0, max);
assertThatIsNotWithinFails(NEARLY_MAX, 0.0, NEARLY_MAX);
assertThat(max).isNotWithin(0.0).of(NEARLY_MAX);
assertThat(NEARLY_MAX).isNotWithin(0.0).of(max);
double min = Double.MIN_VALUE;
assertThatIsNotWithinFails(min, 0.0, min);
assertThatIsNotWithinFails(OVER_MIN, 0.0, OVER_MIN);
assertThat(min).isNotWithin(0.0).of(OVER_MIN);
assertThat(OVER_MIN).isNotWithin(0.0).of(min);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotWithinZeroTolerance
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinNonFinite() {
assertThatIsWithinFailsForNonFiniteExpected(NaN, 0.00001, NaN);
assertThatIsWithinFailsForNonFiniteExpected(NaN, 0.00001, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(NaN, 0.00001, NEGATIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001, +0.0);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001, -0.0);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001, +1.0);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001, -0.0);
assertThatIsWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001, NEGATIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, +0.0);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, -0.0);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, +1.0);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, -0.0);
assertThatIsWithinFailsForNonFiniteExpected(NEGATIVE_INFINITY, 0.00001, NEGATIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, +0.0);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, -0.0);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, +1.0);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, -0.0);
assertThatIsWithinFailsForNonFiniteExpected(+1.0, 0.00001, NaN);
assertThatIsWithinFailsForNonFiniteExpected(+1.0, 0.00001, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(+1.0, 0.00001, NEGATIVE_INFINITY);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isWithinNonFinite
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinNonFinite() {
assertThatIsNotWithinFailsForNonFiniteExpected(NaN, 0.00001, NaN);
assertThatIsNotWithinFailsForNonFiniteExpected(NaN, 0.00001, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(NaN, 0.00001, NEGATIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001, +0.0);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001, -0.0);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001, +1.0);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001, -0.0);
assertThatIsNotWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001, NEGATIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, +0.0);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, -0.0);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, +1.0);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001, -0.0);
assertThatIsNotWithinFailsForNonFiniteExpected(NEGATIVE_INFINITY, 0.00001, NEGATIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, +0.0);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, -0.0);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, +1.0);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001, -0.0);
assertThatIsNotWithinFailsForNonFiniteExpected(+1.0, 0.00001, NaN);
assertThatIsNotWithinFailsForNonFiniteExpected(+1.0, 0.00001, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(+1.0, 0.00001, NEGATIVE_INFINITY);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotWithinNonFinite
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@SuppressWarnings({"TruthSelfEquals", "PositiveInfinity", "NaN"})
@Test
public void isEqualTo() {
assertThat(1.23).isEqualTo(1.23);
assertThatIsEqualToFails(GOLDEN, OVER_GOLDEN);
assertThat(POSITIVE_INFINITY).isEqualTo(POSITIVE_INFINITY);
assertThat(NaN).isEqualTo(NaN);
assertThat((Double) null).isEqualTo(null);
assertThat(1.0).isEqualTo(1);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isEqualTo
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsEqualToFails(double actual, double expected) {
expectFailure(whenTesting -> whenTesting.that(actual).isEqualTo(expected));
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsEqualToFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotEqualTo() {
assertThatIsNotEqualToFails(1.23);
assertThat(GOLDEN).isNotEqualTo(OVER_GOLDEN);
assertThatIsNotEqualToFails(POSITIVE_INFINITY);
assertThatIsNotEqualToFails(NaN);
assertThat(-0.0).isNotEqualTo(0.0);
assertThatIsNotEqualToFails(null);
assertThat(1.23).isNotEqualTo(1.23f);
assertThat(1.0).isNotEqualTo(2);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotEqualTo
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@SuppressWarnings("SelfAssertion")
private static void assertThatIsNotEqualToFails(@Nullable Double value) {
expectFailure(whenTesting -> whenTesting.that(value).isNotEqualTo(value));
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNotEqualToFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isZero() {
assertThat(0.0).isZero();
assertThat(-0.0).isZero();
assertThatIsZeroFails(Double.MIN_VALUE);
assertThatIsZeroFails(-1.23);
assertThatIsZeroFails(POSITIVE_INFINITY);
assertThatIsZeroFails(NaN);
assertThatIsZeroFails(null);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsZeroFails(@Nullable Double value) {
AssertionError failure = expectFailure(whenTesting -> whenTesting.that(value).isZero());
assertThat(failure).factKeys().containsExactly("expected zero", "but was").inOrder();
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsZeroFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNonZero() {
assertThatIsNonZeroFails(0.0, "expected not to be zero");
assertThatIsNonZeroFails(-0.0, "expected not to be zero");
assertThat(Double.MIN_VALUE).isNonZero();
assertThat(-1.23).isNonZero();
assertThat(POSITIVE_INFINITY).isNonZero();
assertThat(NaN).isNonZero();
assertThatIsNonZeroFails(null, "expected a double other than zero");
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNonZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsNonZeroFails(@Nullable Double value, String factKey) {
AssertionError failure = expectFailure(whenTesting -> whenTesting.that(value).isNonZero());
assertThat(failure).factKeys().containsExactly(factKey, "but was").inOrder();
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNonZeroFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isPositiveInfinity() {
assertThat(POSITIVE_INFINITY).isPositiveInfinity();
assertThatIsPositiveInfinityFails(1.23);
assertThatIsPositiveInfinityFails(NEGATIVE_INFINITY);
assertThatIsPositiveInfinityFails(NaN);
assertThatIsPositiveInfinityFails(null);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isPositiveInfinity
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsPositiveInfinityFails(@Nullable Double value) {
expectFailure(whenTesting -> whenTesting.that(value).isPositiveInfinity());
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsPositiveInfinityFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNegativeInfinity() {
assertThat(NEGATIVE_INFINITY).isNegativeInfinity();
assertThatIsNegativeInfinityFails(1.23);
assertThatIsNegativeInfinityFails(POSITIVE_INFINITY);
assertThatIsNegativeInfinityFails(NaN);
assertThatIsNegativeInfinityFails(null);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNegativeInfinity
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsNegativeInfinityFails(@Nullable Double value) {
expectFailure(whenTesting -> whenTesting.that(value).isNegativeInfinity());
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNegativeInfinityFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNaN() {
assertThat(NaN).isNaN();
assertThatIsNaNFails(1.23);
assertThatIsNaNFails(POSITIVE_INFINITY);
assertThatIsNaNFails(NEGATIVE_INFINITY);
assertThatIsNaNFails(null);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNaN
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsNaNFails(@Nullable Double value) {
expectFailure(whenTesting -> whenTesting.that(value).isNaN());
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNaNFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isFinite() {
assertThat(1.23).isFinite();
assertThat(Double.MAX_VALUE).isFinite();
assertThat(-1.0 * Double.MIN_VALUE).isFinite();
assertThatIsFiniteFails(POSITIVE_INFINITY);
assertThatIsFiniteFails(NEGATIVE_INFINITY);
assertThatIsFiniteFails(NaN);
assertThatIsFiniteFails(null);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isFinite
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsFiniteFails(@Nullable Double value) {
AssertionError failure = expectFailure(whenTesting -> whenTesting.that(value).isFinite());
assertThat(failure).factKeys().containsExactly("expected to be finite", "but was").inOrder();
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
assertThatIsFiniteFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotNaN() {
assertThat(1.23).isNotNaN();
assertThat(Double.MAX_VALUE).isNotNaN();
assertThat(-1.0 * Double.MIN_VALUE).isNotNaN();
assertThat(POSITIVE_INFINITY).isNotNaN();
assertThat(NEGATIVE_INFINITY).isNotNaN();
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotNaN
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotNaNIsNaN() {
expectFailure(whenTesting -> whenTesting.that(NaN).isNotNaN());
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotNaNIsNaN
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotNaNIsNull() {
AssertionError e = expectFailure(whenTesting -> whenTesting.that((Double) null).isNotNaN());
assertFailureKeys(e, "expected a double other than NaN", "but was");
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isNotNaNIsNull
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isGreaterThan_int_strictly() {
expectFailure(whenTesting -> whenTesting.that(2.0).isGreaterThan(3));
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isGreaterThan_int_strictly
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isGreaterThan_int() {
expectFailure(whenTesting -> whenTesting.that(2.0).isGreaterThan(2));
assertThat(2.0).isGreaterThan(1);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isGreaterThan_int
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isLessThan_int_strictly() {
expectFailure(whenTesting -> whenTesting.that(2.0).isLessThan(1));
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isLessThan_int_strictly
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isLessThan_int() {
expectFailure(whenTesting -> whenTesting.that(2.0).isLessThan(2));
assertThat(2.0).isLessThan(3);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isLessThan_int
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isAtLeast_int() {
expectFailure(whenTesting -> whenTesting.that(2.0).isAtLeast(3));
assertThat(2.0).isAtLeast(2);
assertThat(2.0).isAtLeast(1);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isAtLeast_int
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void isAtMost_int() {
expectFailure(whenTesting -> whenTesting.that(2.0).isAtMost(1));
assertThat(2.0).isAtMost(2);
assertThat(2.0).isAtMost(3);
}
|
Tests for Double Subjects.
@author Kurt Alfred Kluever
|
isAtMost_int
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java
|
Apache-2.0
|
@Test
public void testExpectFailure() {
AssertionError failure1 = expectFailure(whenTesting -> whenTesting.that(4).isEqualTo(5));
assertThat(failure1).factValue("expected").isEqualTo("5");
// verify multiple independent failures can be caught in the same test
AssertionError failure2 = expectFailure(whenTesting -> whenTesting.that(5).isEqualTo(4));
assertThat(failure2).factValue("expected").isEqualTo("4");
}
|
Tests of {@link ExpectFailure}'s Java 8 support.
|
testExpectFailure
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailure8Test.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailure8Test.java
|
Apache-2.0
|
@Test
public void testExpectFailureAbout() {
AssertionError unused =
expectFailureAbout(
StringSubject::new,
(SimpleSubjectBuilderCallback<StringSubject, String>)
whenTesting -> whenTesting.that("foo").contains("bar"));
}
|
Tests of {@link ExpectFailure}'s Java 8 support.
|
testExpectFailureAbout
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailure8Test.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailure8Test.java
|
Apache-2.0
|
@Test
public void testExpect_userThrowExceptionInSubject_shouldPropagate() throws Exception {
List<Failure> reportedFailure = new ArrayList<>();
RunNotifier runNotifier = new RunNotifier();
runNotifier.addListener(
new RunListener() {
@Override
public void testFailure(Failure failure) {
reportedFailure.add(failure);
}
});
Runner runner = new JUnit4(ExpectFailureThrowInSubject.class);
runner.run(runNotifier);
assertThat(reportedFailure).hasSize(2);
assertThat(reportedFailure.get(0).getException())
.hasMessageThat()
.contains("Throw deliberately");
assertThat(reportedFailure.get(1).getException())
.hasMessageThat()
.contains("ExpectFailure.whenTesting() invoked, but no failure was caught.");
}
|
Tests for {@link ExpectFailure} not used as JUnit's TestRule.
|
testExpect_userThrowExceptionInSubject_shouldPropagate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Override
public void testFailure(Failure failure) {
reportedFailure.add(failure);
}
|
Tests for {@link ExpectFailure} not used as JUnit's TestRule.
|
testFailure
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Test
public void testExpect_userThrowExceptionAfterSubject_shouldPropagate() throws Exception {
List<Failure> reportedFailure = new ArrayList<>();
RunNotifier runNotifier = new RunNotifier();
runNotifier.addListener(
new RunListener() {
@Override
public void testFailure(Failure failure) {
reportedFailure.add(failure);
}
});
Runner runner = new JUnit4(ExpectFailureThrowAfterSubject.class);
runner.run(runNotifier);
assertThat(reportedFailure).hasSize(2);
assertThat(reportedFailure.get(0).getException())
.hasMessageThat()
.contains("Throw deliberately");
assertThat(reportedFailure.get(1).getException())
.hasMessageThat()
.contains("ExpectFailure.whenTesting() invoked, but no failure was caught.");
}
|
Tests for {@link ExpectFailure} not used as JUnit's TestRule.
|
testExpect_userThrowExceptionAfterSubject_shouldPropagate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Override
public void testFailure(Failure failure) {
reportedFailure.add(failure);
}
|
Tests for {@link ExpectFailure} not used as JUnit's TestRule.
|
testFailure
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Before
public void setupExpectFailure() {
expectFailure.enterRuleContext();
}
|
A test supporting test class which will fail because method in a subject will throw exception.
|
setupExpectFailure
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@After
public void ensureFailureCaught() {
expectFailure.ensureFailureCaught();
expectFailure.leaveRuleContext();
}
|
A test supporting test class which will fail because method in a subject will throw exception.
|
ensureFailureCaught
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Test
public void testExpect_throwInSubject_shouldPropagate() {
expectFailure.whenTesting().that(throwingMethod()).isEqualTo(4);
}
|
A test supporting test class which will fail because method in a subject will throw exception.
|
testExpect_throwInSubject_shouldPropagate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Before
public void setupExpectFailure() {
expectFailure.enterRuleContext();
}
|
A test supporting test class which will fail because method after a subject will throw
exception.
|
setupExpectFailure
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@After
public void ensureFailureCaught() {
expectFailure.ensureFailureCaught();
expectFailure.leaveRuleContext();
}
|
A test supporting test class which will fail because method after a subject will throw
exception.
|
ensureFailureCaught
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void testExpect_throwInSubject_shouldPropagate() {
expectFailure.whenTesting().that(4).isEqualTo(4); // No failure being caught
long unused = throwingMethod();
}
|
A test supporting test class which will fail because method after a subject will throw
exception.
|
testExpect_throwInSubject_shouldPropagate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
private static long throwingMethod() {
throw new RuntimeException("Throw deliberately");
}
|
A test supporting test class which will fail because method after a subject will throw
exception.
|
throwingMethod
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureNonRuleTest.java
|
Apache-2.0
|
@Test
public void expectFail_captureFailureAsExpected() {
expectFailure.whenTesting().withMessage("abc").fail();
assertThat(expectFailure.getFailure()).hasMessageThat().isEqualTo("abc");
}
|
Tests for {@link ExpectFailure} used as JUnit {@link Rule}.
|
expectFail_captureFailureAsExpected
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void expectFail_passesIfUnused() {
assertThat(4).isEqualTo(4);
}
|
Tests for {@link ExpectFailure} used as JUnit {@link Rule}.
|
expectFail_passesIfUnused
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void expectFail_failsAfterTest() {
expectFailure.whenTesting().that(4).isEqualTo(4);
thrown.expectMessage("ExpectFailure.whenTesting() invoked, but no failure was caught.");
}
|
Tests for {@link ExpectFailure} used as JUnit {@link Rule}.
|
expectFail_failsAfterTest
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
Apache-2.0
|
@Test
public void expectFail_throwInSubject_shouldPropagateOriginalException() {
thrown.expectMessage("Throwing deliberately");
expectFailure.whenTesting().that(throwingMethod()).isEqualTo(2);
}
|
Tests for {@link ExpectFailure} used as JUnit {@link Rule}.
|
expectFail_throwInSubject_shouldPropagateOriginalException
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void expectFail_throwAfterSubject_shouldPropagateOriginalException() {
expectFailure.whenTesting().that(2).isEqualTo(2);
thrown.expectMessage("Throwing deliberately");
throwingMethod();
}
|
Tests for {@link ExpectFailure} used as JUnit {@link Rule}.
|
expectFail_throwAfterSubject_shouldPropagateOriginalException
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
Apache-2.0
|
private static long throwingMethod() {
throw new RuntimeException("Throwing deliberately");
}
|
Tests for {@link ExpectFailure} used as JUnit {@link Rule}.
|
throwingMethod
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureRuleTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void expectTwoFailures() {
failToExpect.delegate.that(4).isNotEqualTo(4);
failToExpect.delegate.that("abc").contains("x");
}
|
Test that stack traces are included in the error message created by Expect.
|
expectTwoFailures
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
Apache-2.0
|
@Override
public Statement apply(Statement base, Description description) {
Statement s = delegate.apply(base, description);
return new Statement() {
@Override
public void evaluate() throws Throwable {
String failureMessage = "";
try {
s.evaluate();
} catch (AssertionError e) {
failureMessage = e.getMessage();
}
// Check that error message contains stack traces. Method name should appear twice,
// once for each expect error.
int firstIndex = failureMessage.indexOf(METHOD_NAME);
assertThat(firstIndex).isGreaterThan(0);
int secondIndex = failureMessage.indexOf(METHOD_NAME, firstIndex + 1);
assertThat(secondIndex).isGreaterThan(firstIndex);
}
};
}
|
Expect class that can examine the error message
|
apply
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
Apache-2.0
|
@Override
public void evaluate() throws Throwable {
String failureMessage = "";
try {
s.evaluate();
} catch (AssertionError e) {
failureMessage = e.getMessage();
}
// Check that error message contains stack traces. Method name should appear twice,
// once for each expect error.
int firstIndex = failureMessage.indexOf(METHOD_NAME);
assertThat(firstIndex).isGreaterThan(0);
int secondIndex = failureMessage.indexOf(METHOD_NAME, firstIndex + 1);
assertThat(secondIndex).isGreaterThan(firstIndex);
}
|
Expect class that can examine the error message
|
evaluate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectFailureWithStackTraceTest.java
|
Apache-2.0
|
@Override
public void evaluate() throws Throwable {
base.evaluate();
testMethodComplete.countDown();
taskToAwait.get();
}
|
Tests (and effectively sample code) for the Expect verb (implemented as a rule)
@author David Saff
@author Christian Gruber (cgruber@israfil.net)
|
evaluate
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void expectTrue() {
expect.that(4).isEqualTo(4);
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectTrue
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void singleExpectationFails() {
thrown.expectMessage("1 expectation failed:");
thrown.expectMessage("1. x");
expect.withMessage("x").fail();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
singleExpectationFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFail() {
thrown.expectMessage("3 expectations failed:");
thrown.expectMessage("1. x");
thrown.expectMessage("2. y");
thrown.expectMessage("3. z");
expect.withMessage("x").fail();
expect.withMessage("y").fail();
expect.withMessage("z").fail();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFail
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFail10Aligned() {
thrown.expectMessage("10 expectations failed:");
thrown.expectMessage(" 1. x");
thrown.expectMessage("10. x");
for (int i = 0; i < 10; i++) {
expect.withMessage("x").fail();
}
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFail10Aligned
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFail10WrappedAligned() {
thrown.expectMessage("10 expectations failed:");
thrown.expectMessage(" 1. abc\n xyz");
thrown.expectMessage("10. abc\n xyz");
for (int i = 0; i < 10; i++) {
expect.withMessage("abc\nxyz").fail();
}
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFail10WrappedAligned
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFailWithExceptionNoMessage() {
thrown.expectMessage("3 expectations failed:");
thrown.expectMessage("1. x");
thrown.expectMessage("2. y");
thrown.expectMessage("3. Also, after those failures, an exception was thrown:");
expect.withMessage("x").fail();
expect.withMessage("y").fail();
throw new IllegalStateException();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFailWithExceptionNoMessage
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFailWithExceptionWithMessage() {
thrown.expectMessage("3 expectations failed:");
thrown.expectMessage("1. x");
thrown.expectMessage("2. y");
thrown.expectMessage("3. Also, after those failures, an exception was thrown:");
expect.withMessage("x").fail();
expect.withMessage("y").fail();
throw new IllegalStateException("testing");
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFailWithExceptionWithMessage
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFailWithExceptionBeforeExpectFailures() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("testing");
throwException();
expect.withMessage("x").fail();
expect.withMessage("y").fail();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFailWithExceptionBeforeExpectFailures
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
private static void throwException() {
throw new IllegalStateException("testing");
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
throwException
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectFailWithFailuresBeforeAssume() {
thrown.expectMessage("3 expectations failed:");
thrown.expectMessage("1. x");
thrown.expectMessage("2. y");
thrown.expectMessage("3. Also, after those failures, an assumption was violated:");
expect.withMessage("x").fail();
expect.withMessage("y").fail();
assume().withMessage("testing").fail();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectFailWithFailuresBeforeAssume
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void expectSuccessWithFailuresAfterAssume() {
assume().withMessage("testing").fail();
expect.withMessage("x").fail();
expect.withMessage("y").fail();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
expectSuccessWithFailuresAfterAssume
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
@SuppressWarnings("TruthSelfEquals")
public void warnWhenExpectIsNotRule() {
String message = "Assertion made on Expect instance, but it's not enabled as a @Rule.";
thrown.expectMessage(message);
oopsNotARule.that(true).isEqualTo(true);
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
warnWhenExpectIsNotRule
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void bash() throws Exception {
Runnable task = () -> expect.that(3).isEqualTo(4);
List<Future<?>> results = new ArrayList<>();
ExecutorService executor = newFixedThreadPool(10);
for (int i = 0; i < 1000; i++) {
results.add(executor.submit(task));
}
executor.shutdown();
for (Future<?> result : results) {
result.get();
}
thrown.expectMessage("1000 expectations failed:");
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
bash
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void failWhenCallingThatAfterTest() {
ExecutorService executor = newSingleThreadExecutor();
taskToAwait =
executor.submit(
() -> {
awaitUninterruptibly(testMethodComplete);
assertThrows(IllegalStateException.class, () -> expect.that(3));
});
executor.shutdown();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
failWhenCallingThatAfterTest
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
@Test
public void failWhenCallingFailingAssertionMethodAfterTest() {
ExecutorService executor = newSingleThreadExecutor();
/*
* We wouldn't expect people to do this exactly. The point is that, if someone were to call
* expect.that(3).isEqualTo(4), we would always either fail the test or throw an
* IllegalStateException, not record a "failure" that we never read.
*/
IntegerSubject expectThat3 = expect.that(3);
taskToAwait =
executor.submit(
() -> {
awaitUninterruptibly(testMethodComplete);
IllegalStateException expected =
assertThrows(IllegalStateException.class, () -> expectThat3.isEqualTo(4));
assertThat(expected).hasCauseThat().isInstanceOf(AssertionError.class);
});
executor.shutdown();
}
|
A task that the main thread will await, to be provided by tests that do work in other threads.
|
failWhenCallingFailingAssertionMethodAfterTest
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/ExpectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ExpectTest.java
|
Apache-2.0
|
static void assertFailureValueIndexed(AssertionError e, String key, int index, String value) {
assertThat(e).factValue(key, index).isEqualTo(value);
}
|
Convenience methods for {@link Subject} tests.
|
assertFailureValueIndexed
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FailureAssertions.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FailureAssertions.java
|
Apache-2.0
|
@Test
@GwtIncompatible("Math.nextAfter")
public void testFloatConstants_matchNextAfter() {
assertThat(Math.nextAfter(Float.MAX_VALUE, 0.0f)).isEqualTo(NEARLY_MAX);
assertThat(Math.nextAfter(-1.0f * Float.MAX_VALUE, 0.0f)).isEqualTo(NEGATIVE_NEARLY_MAX);
assertThat(Math.nextAfter(Float.MIN_VALUE, 1.0f)).isEqualTo(JUST_OVER_MIN);
assertThat(Math.nextAfter(-1.0f * Float.MIN_VALUE, -1.0f)).isEqualTo(JUST_UNDER_NEGATIVE_MIN);
assertThat(1.23f).isEqualTo(GOLDEN);
assertThat(Math.nextAfter(1.23f, POSITIVE_INFINITY)).isEqualTo(JUST_OVER_GOLDEN);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
testFloatConstants_matchNextAfter
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void testJ2clCornerCaseZero() {
// GWT considers -0.0 to be equal to 0.0. But we've added a special workaround inside Truth.
assertThatIsEqualToFails(-0.0f, 0.0f);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
testJ2clCornerCaseZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
@GwtIncompatible("GWT behavior difference")
public void j2clCornerCaseDoubleVsFloat() {
// Under GWT, 1.23f.toString() is different than 1.23d.toString(), so the message omits types.
// TODO(b/35377736): Consider making Truth add the types manually.
AssertionError e = expectFailure(whenTesting -> whenTesting.that(1.23f).isEqualTo(1.23));
assertFailureKeys(e, "expected", "an instance of", "but was", "an instance of");
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
j2clCornerCaseDoubleVsFloat
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinOf() {
assertThat(2.0f).isWithin(0.0f).of(2.0f);
assertThat(2.0f).isWithin(0.00001f).of(2.0f);
assertThat(2.0f).isWithin(1000.0f).of(2.0f);
assertThat(2.0f).isWithin(1.00001f).of(3.0f);
assertThatIsWithinFails(2.0f, 0.99999f, 3.0f);
assertThatIsWithinFails(2.0f, 1000.0f, 1003.0f);
assertThatIsWithinFailsForNonFiniteExpected(2.0f, 1000.0f, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(2.0f, 1000.0f, NaN);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 1000.0f, 2.0f);
assertThatIsWithinFailsForNonFiniteActual(NaN, 1000.0f, 2.0f);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isWithinOf
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsWithinFails(float actual, float tolerance, float expected) {
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected));
assertThat(failure)
.factKeys()
.containsExactly("expected", "but was", "outside tolerance")
.inOrder();
assertThat(failure).factValue("expected").isEqualTo(formatNumericValue(expected));
assertThat(failure).factValue("but was").isEqualTo(formatNumericValue(actual));
assertThat(failure).factValue("outside tolerance").isEqualTo(formatNumericValue(tolerance));
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
assertThatIsWithinFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsWithinFailsForNonFiniteExpected(
float actual, float tolerance, float expected) {
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected));
assertThat(failure)
.factKeys()
.containsExactly(
"could not perform approximate-equality check because expected value is not finite",
"expected",
"was",
"tolerance")
.inOrder();
assertThat(failure).factValue("expected").isEqualTo(formatNumericValue(expected));
assertThat(failure).factValue("was").isEqualTo(formatNumericValue(actual));
assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance));
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
assertThatIsWithinFailsForNonFiniteExpected
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsWithinFailsForNonFiniteActual(
float actual, float tolerance, float expected) {
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected));
assertThat(failure)
.factKeys()
.containsExactly("expected a finite value near", "but was", "tolerance")
.inOrder();
assertThat(failure)
.factValue("expected a finite value near")
.isEqualTo(formatNumericValue(expected));
assertThat(failure).factValue("but was").isEqualTo(formatNumericValue(actual));
assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance));
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
assertThatIsWithinFailsForNonFiniteActual
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinOf() {
assertThatIsNotWithinFails(2.0f, 0.0f, 2.0f);
assertThatIsNotWithinFails(2.0f, 0.00001f, 2.0f);
assertThatIsNotWithinFails(2.0f, 1000.0f, 2.0f);
assertThatIsNotWithinFails(2.0f, 1.00001f, 3.0f);
assertThat(2.0f).isNotWithin(0.99999f).of(3.0f);
assertThat(2.0f).isNotWithin(1000.0f).of(1003.0f);
assertThatIsNotWithinFailsForNonFiniteExpected(2.0f, 0.0f, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(2.0f, 0.0f, NaN);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 1000.0f, 2.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 1000.0f, 2.0f);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isNotWithinOf
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsNotWithinFails(float actual, float tolerance, float expected) {
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected));
assertThat(failure).factValue("expected not to be").isEqualTo(formatNumericValue(expected));
assertThat(failure).factValue("within tolerance").isEqualTo(formatNumericValue(tolerance));
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNotWithinFails
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsNotWithinFailsForNonFiniteExpected(
float actual, float tolerance, float expected) {
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected));
assertThat(failure)
.factKeys()
.containsExactly(
"could not perform approximate-equality check because expected value is not finite",
"expected not to be",
"was",
"tolerance");
assertThat(failure).factValue("expected not to be").isEqualTo(formatNumericValue(expected));
assertThat(failure).factValue("was").isEqualTo(formatNumericValue(actual));
assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance));
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNotWithinFailsForNonFiniteExpected
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void assertThatIsNotWithinFailsForNonFiniteActual(
float actual, float tolerance, float expected) {
AssertionError failure =
expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected));
assertThat(failure)
.factValue("expected a finite value that is not near")
.isEqualTo(formatNumericValue(expected));
assertThat(failure).factValue("tolerance").isEqualTo(formatNumericValue(tolerance));
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
assertThatIsNotWithinFailsForNonFiniteActual
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void negativeTolerances() {
isWithinNegativeToleranceThrows(-0.5f);
isNotWithinNegativeToleranceThrows(-0.5f);
// You know what's worse than zero? Negative zero.
isWithinNegativeToleranceThrows(-0.0f);
isNotWithinNegativeToleranceThrows(-0.0f);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
negativeTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void isWithinNegativeToleranceThrows(float tolerance) {
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(5.0f).isWithin(tolerance).of(5.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is negative",
"expected",
"was",
"tolerance");
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isWithinNegativeToleranceThrows
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
private static void isNotWithinNegativeToleranceThrows(float tolerance) {
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(5.0f).isNotWithin(tolerance).of(5.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is negative",
"expected not to be",
"was",
"tolerance");
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isNotWithinNegativeToleranceThrows
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void nanTolerances() {
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0f).isWithin(NaN).of(1.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected",
"was",
"tolerance");
}
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0f).isNotWithin(NaN).of(1.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected not to be",
"was",
"tolerance");
}
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
nanTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void positiveInfinityTolerances() {
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0f).isWithin(POSITIVE_INFINITY).of(1.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected",
"was",
"tolerance");
}
{
AssertionError e =
expectFailure(
whenTesting -> whenTesting.that(1.0f).isNotWithin(POSITIVE_INFINITY).of(1.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected not to be",
"was",
"tolerance");
}
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
positiveInfinityTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@SuppressWarnings("FloatingPointAssertionWithinEpsilon") // test of a bogus call
@Test
public void negativeInfinityTolerances() {
{
AssertionError e =
expectFailure(whenTesting -> whenTesting.that(1.0f).isWithin(NEGATIVE_INFINITY).of(1.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected",
"was",
"tolerance");
}
{
AssertionError e =
expectFailure(
whenTesting -> whenTesting.that(1.0f).isNotWithin(NEGATIVE_INFINITY).of(1.0f));
assertFailureKeys(
e,
"could not perform approximate-equality check because tolerance is not finite",
"expected not to be",
"was",
"tolerance");
}
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
negativeInfinityTolerances
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinOfZero() {
assertThat(+0.0f).isWithin(0.00001f).of(+0.0f);
assertThat(+0.0f).isWithin(0.00001f).of(-0.0f);
assertThat(-0.0f).isWithin(0.00001f).of(+0.0f);
assertThat(-0.0f).isWithin(0.00001f).of(-0.0f);
assertThat(+0.0f).isWithin(0.0f).of(+0.0f);
assertThat(+0.0f).isWithin(0.0f).of(-0.0f);
assertThat(-0.0f).isWithin(0.0f).of(+0.0f);
assertThat(-0.0f).isWithin(0.0f).of(-0.0f);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isWithinOfZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinOfZero() {
assertThat(+0.0f).isNotWithin(0.00001f).of(+1.0f);
assertThat(+0.0f).isNotWithin(0.00001f).of(-1.0f);
assertThat(-0.0f).isNotWithin(0.00001f).of(+1.0f);
assertThat(-0.0f).isNotWithin(0.00001f).of(-1.0f);
assertThat(+1.0f).isNotWithin(0.00001f).of(+0.0f);
assertThat(+1.0f).isNotWithin(0.00001f).of(-0.0f);
assertThat(-1.0f).isNotWithin(0.00001f).of(+0.0f);
assertThat(-1.0f).isNotWithin(0.00001f).of(-0.0f);
assertThat(+1.0f).isNotWithin(0.0f).of(+0.0f);
assertThat(+1.0f).isNotWithin(0.0f).of(-0.0f);
assertThat(-1.0f).isNotWithin(0.0f).of(+0.0f);
assertThat(-1.0f).isNotWithin(0.0f).of(-0.0f);
assertThatIsNotWithinFails(-0.0f, 0.0f, 0.0f);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isNotWithinOfZero
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinZeroTolerance() {
float max = Float.MAX_VALUE;
assertThat(max).isWithin(0.0f).of(max);
assertThat(NEARLY_MAX).isWithin(0.0f).of(NEARLY_MAX);
assertThatIsWithinFails(max, 0.0f, NEARLY_MAX);
assertThatIsWithinFails(NEARLY_MAX, 0.0f, max);
float negativeMax = -1.0f * Float.MAX_VALUE;
assertThat(negativeMax).isWithin(0.0f).of(negativeMax);
assertThat(NEGATIVE_NEARLY_MAX).isWithin(0.0f).of(NEGATIVE_NEARLY_MAX);
assertThatIsWithinFails(negativeMax, 0.0f, NEGATIVE_NEARLY_MAX);
assertThatIsWithinFails(NEGATIVE_NEARLY_MAX, 0.0f, negativeMax);
float min = Float.MIN_VALUE;
assertThat(min).isWithin(0.0f).of(min);
assertThat(JUST_OVER_MIN).isWithin(0.0f).of(JUST_OVER_MIN);
assertThatIsWithinFails(min, 0.0f, JUST_OVER_MIN);
assertThatIsWithinFails(JUST_OVER_MIN, 0.0f, min);
float negativeMin = -1.0f * Float.MIN_VALUE;
assertThat(negativeMin).isWithin(0.0f).of(negativeMin);
assertThat(JUST_UNDER_NEGATIVE_MIN).isWithin(0.0f).of(JUST_UNDER_NEGATIVE_MIN);
assertThatIsWithinFails(negativeMin, 0.0f, JUST_UNDER_NEGATIVE_MIN);
assertThatIsWithinFails(JUST_UNDER_NEGATIVE_MIN, 0.0f, negativeMin);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isWithinZeroTolerance
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinZeroTolerance() {
float max = Float.MAX_VALUE;
assertThatIsNotWithinFails(max, 0.0f, max);
assertThatIsNotWithinFails(NEARLY_MAX, 0.0f, NEARLY_MAX);
assertThat(max).isNotWithin(0.0f).of(NEARLY_MAX);
assertThat(NEARLY_MAX).isNotWithin(0.0f).of(max);
float min = Float.MIN_VALUE;
assertThatIsNotWithinFails(min, 0.0f, min);
assertThatIsNotWithinFails(JUST_OVER_MIN, 0.0f, JUST_OVER_MIN);
assertThat(min).isNotWithin(0.0f).of(JUST_OVER_MIN);
assertThat(JUST_OVER_MIN).isNotWithin(0.0f).of(min);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isNotWithinZeroTolerance
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isWithinNonFinite() {
assertThatIsWithinFailsForNonFiniteExpected(NaN, 0.00001f, NaN);
assertThatIsWithinFailsForNonFiniteExpected(NaN, 0.00001f, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(NaN, 0.00001f, NEGATIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001f, +0.0f);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001f, -0.0f);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001f, +1.0f);
assertThatIsWithinFailsForNonFiniteActual(NaN, 0.00001f, -0.0f);
assertThatIsWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001f, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001f, NEGATIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, +0.0f);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, +1.0f);
assertThatIsWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsWithinFailsForNonFiniteExpected(NEGATIVE_INFINITY, 0.00001f, NEGATIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, +0.0f);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, +1.0f);
assertThatIsWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsWithinFailsForNonFiniteExpected(+1.0f, 0.00001f, NaN);
assertThatIsWithinFailsForNonFiniteExpected(+1.0f, 0.00001f, POSITIVE_INFINITY);
assertThatIsWithinFailsForNonFiniteExpected(+1.0f, 0.00001f, NEGATIVE_INFINITY);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isWithinNonFinite
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@Test
public void isNotWithinNonFinite() {
assertThatIsNotWithinFailsForNonFiniteExpected(NaN, 0.00001f, NaN);
assertThatIsNotWithinFailsForNonFiniteExpected(NaN, 0.00001f, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(NaN, 0.00001f, NEGATIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001f, +0.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001f, -0.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001f, +1.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NaN, 0.00001f, -0.0f);
assertThatIsNotWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001f, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(POSITIVE_INFINITY, 0.00001f, NEGATIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, +0.0f);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, +1.0f);
assertThatIsNotWithinFailsForNonFiniteActual(POSITIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsNotWithinFailsForNonFiniteExpected(NEGATIVE_INFINITY, 0.00001f, NEGATIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, +0.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, +1.0f);
assertThatIsNotWithinFailsForNonFiniteActual(NEGATIVE_INFINITY, 0.00001f, -0.0f);
assertThatIsNotWithinFailsForNonFiniteExpected(+1.0f, 0.00001f, NaN);
assertThatIsNotWithinFailsForNonFiniteExpected(+1.0f, 0.00001f, POSITIVE_INFINITY);
assertThatIsNotWithinFailsForNonFiniteExpected(+1.0f, 0.00001f, NEGATIVE_INFINITY);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isNotWithinNonFinite
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
@SuppressWarnings("TruthSelfEquals")
@Test
public void isEqualTo() {
assertThat(GOLDEN).isEqualTo(GOLDEN);
assertThatIsEqualToFails(GOLDEN, JUST_OVER_GOLDEN);
assertThat(POSITIVE_INFINITY).isEqualTo(POSITIVE_INFINITY);
assertThat(NaN).isEqualTo(NaN);
assertThat((Float) null).isEqualTo(null);
assertThat(1.0f).isEqualTo(1);
}
|
Tests for Float Subjects.
@author Kurt Alfred Kluever
|
isEqualTo
|
java
|
google/truth
|
core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/FloatSubjectTest.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.