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
private static void assertThatIsEqualToFails(float actual, float expected) { expectFailure(whenTesting -> whenTesting.that(actual).isEqualTo(expected)); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsEqualToFails
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 isNotEqualTo() { assertThatIsNotEqualToFails(GOLDEN); assertThat(GOLDEN).isNotEqualTo(JUST_OVER_GOLDEN); assertThatIsNotEqualToFails(POSITIVE_INFINITY); assertThatIsNotEqualToFails(NaN); assertThat(-0.0f).isNotEqualTo(0.0f); assertThatIsNotEqualToFails(null); assertThat(1.23f).isNotEqualTo(1.23); assertThat(1.0f).isNotEqualTo(2); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNotEqualTo
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("SelfAssertion") private static void assertThatIsNotEqualToFails(@Nullable Float value) { expectFailure(whenTesting -> whenTesting.that(value).isNotEqualTo(value)); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsNotEqualToFails
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 isZero() { assertThat(0.0f).isZero(); assertThat(-0.0f).isZero(); assertThatIsZeroFails(Float.MIN_VALUE); assertThatIsZeroFails(-1.23f); assertThatIsZeroFails(POSITIVE_INFINITY); assertThatIsZeroFails(NaN); assertThatIsZeroFails(null); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isZero
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 assertThatIsZeroFails(@Nullable Float value) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(value).isZero()); assertThat(failure).factKeys().containsExactly("expected zero", "but was").inOrder(); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsZeroFails
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 isNonZero() { assertThatIsNonZeroFails(0.0f, "expected not to be zero"); assertThatIsNonZeroFails(-0.0f, "expected not to be zero"); assertThat(Float.MIN_VALUE).isNonZero(); assertThat(-1.23f).isNonZero(); assertThat(POSITIVE_INFINITY).isNonZero(); assertThat(NaN).isNonZero(); assertThatIsNonZeroFails(null, "expected a float other than zero"); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNonZero
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 assertThatIsNonZeroFails(@Nullable Float value, String factKey) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(value).isNonZero()); assertThat(failure).factKeys().containsExactly(factKey, "but was").inOrder(); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsNonZeroFails
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 isPositiveInfinity() { assertThat(POSITIVE_INFINITY).isPositiveInfinity(); assertThatIsPositiveInfinityFails(1.23f); assertThatIsPositiveInfinityFails(NEGATIVE_INFINITY); assertThatIsPositiveInfinityFails(NaN); assertThatIsPositiveInfinityFails(null); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isPositiveInfinity
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 assertThatIsPositiveInfinityFails(@Nullable Float value) { expectFailure(whenTesting -> whenTesting.that(value).isPositiveInfinity()); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsPositiveInfinityFails
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 isNegativeInfinity() { assertThat(NEGATIVE_INFINITY).isNegativeInfinity(); assertThatIsNegativeInfinityFails(1.23f); assertThatIsNegativeInfinityFails(POSITIVE_INFINITY); assertThatIsNegativeInfinityFails(NaN); assertThatIsNegativeInfinityFails(null); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNegativeInfinity
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 assertThatIsNegativeInfinityFails(@Nullable Float value) { expectFailure(whenTesting -> whenTesting.that(value).isNegativeInfinity()); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsNegativeInfinityFails
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 isNaN() { assertThat(NaN).isNaN(); assertThatIsNaNFails(1.23f); assertThatIsNaNFails(POSITIVE_INFINITY); assertThatIsNaNFails(NEGATIVE_INFINITY); assertThatIsNaNFails(null); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNaN
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 assertThatIsNaNFails(@Nullable Float value) { expectFailure(whenTesting -> whenTesting.that(value).isNaN()); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsNaNFails
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 isFinite() { assertThat(1.23f).isFinite(); assertThat(Float.MAX_VALUE).isFinite(); assertThat(-1.0 * Float.MIN_VALUE).isFinite(); assertThatIsFiniteFails(POSITIVE_INFINITY); assertThatIsFiniteFails(NEGATIVE_INFINITY); assertThatIsFiniteFails(NaN); assertThatIsFiniteFails(null); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isFinite
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 assertThatIsFiniteFails(@Nullable Float value) { AssertionError failure = expectFailure(whenTesting -> whenTesting.that(value).isFinite()); assertThat(failure).factKeys().containsExactly("expected to be finite", "but was").inOrder(); }
Tests for Float Subjects. @author Kurt Alfred Kluever
assertThatIsFiniteFails
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 isNotNaN() { assertThat(1.23f).isNotNaN(); assertThat(Float.MAX_VALUE).isNotNaN(); assertThat(-1.0 * Float.MIN_VALUE).isNotNaN(); assertThat(POSITIVE_INFINITY).isNotNaN(); assertThat(NEGATIVE_INFINITY).isNotNaN(); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNotNaN
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 isNotNaNIsNaN() { expectFailure(whenTesting -> whenTesting.that(NaN).isNotNaN()); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNotNaNIsNaN
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 isNotNaNIsNull() { AssertionError e = expectFailure(whenTesting -> whenTesting.that((Float) null).isNotNaN()); assertFailureKeys(e, "expected a float other than NaN", "but was"); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isNotNaNIsNull
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 isGreaterThan_int_strictly() { expectFailure(whenTesting -> whenTesting.that(2.0f).isGreaterThan(3)); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isGreaterThan_int_strictly
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 isGreaterThan_int() { expectFailure(whenTesting -> whenTesting.that(2.0f).isGreaterThan(2)); assertThat(2.0f).isGreaterThan(1); assertThat(0x1.0p30f).isGreaterThan((1 << 30) - 1); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isGreaterThan_int
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 isLessThan_int_strictly() { expectFailure(whenTesting -> whenTesting.that(2.0f).isLessThan(1)); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isLessThan_int_strictly
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 isLessThan_int() { expectFailure(whenTesting -> whenTesting.that(2.0f).isLessThan(2)); assertThat(2.0f).isLessThan(3); assertThat(0x1.0p30f).isLessThan((1 << 30) + 1); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isLessThan_int
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 isAtLeast_int() { expectFailure(whenTesting -> whenTesting.that(2.0f).isAtLeast(3)); assertThat(2.0f).isAtLeast(2); assertThat(2.0f).isAtLeast(1); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isAtLeast_int
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 isAtLeast_int_withNoExactFloatRepresentation() { expectFailure(whenTesting -> whenTesting.that(0x1.0p30f).isAtLeast((1 << 30) + 1)); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isAtLeast_int_withNoExactFloatRepresentation
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 isAtMost_int() { expectFailure(whenTesting -> whenTesting.that(2.0f).isAtMost(1)); assertThat(2.0f).isAtMost(2); assertThat(2.0f).isAtMost(3); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isAtMost_int
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 isAtMost_int_withNoExactFloatRepresentation() { expectFailure(whenTesting -> whenTesting.that(0x1.0p30f).isAtMost((1 << 30) - 1)); }
Tests for Float Subjects. @author Kurt Alfred Kluever
isAtMost_int_withNoExactFloatRepresentation
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 maximumCardinalityBipartiteMatching_empty() { TestInstance.empty().testAgainstKnownSize(0); }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_empty
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void maximumCardinalityBipartiteMatching_exhaustive3x4() { for (int edgeCombination = 1; edgeCombination < (1L << (3 * 4)); edgeCombination++) { TestInstance.fromBits(3, 4, intBits(edgeCombination)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_exhaustive3x4
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test @GwtIncompatible("slow") public void maximumCardinalityBipartiteMatching_exhaustive4x4() { if (Platform.isAndroid()) { return; // slow } for (int edgeCombination = 1; edgeCombination < (1L << (4 * 4)); edgeCombination++) { TestInstance.fromBits(4, 4, intBits(edgeCombination)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_exhaustive4x4
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test @GwtIncompatible("slow") public void maximumCardinalityBipartiteMatching_exhaustive3x5() { if (Platform.isAndroid()) { return; // slow } for (int edgeCombination = 1; edgeCombination < (1L << (3 * 5)); edgeCombination++) { TestInstance.fromBits(3, 5, intBits(edgeCombination)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_exhaustive3x5
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test @GwtIncompatible("slow") public void maximumCardinalityBipartiteMatching_exhaustive5x3() { if (Platform.isAndroid()) { return; // slow } for (int edgeCombination = 1; edgeCombination < (1L << (5 * 3)); edgeCombination++) { TestInstance.fromBits(5, 3, intBits(edgeCombination)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_exhaustive5x3
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void maximumCardinalityBipartiteMatching_fullyConnected8x8() { TestInstance.fullyConnected(8, 8).testAgainstKnownSize(8); }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_fullyConnected8x8
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void maximumCardinalityBipartiteMatching_random8x8() { Random rng = new Random(0x5ca1ab1e); for (int i = 0; i < 100; i++) { // Set each bit with probability 0.25, giving an average of 2 of the possible 8 edges per // vertex. By observation, the maximal matching most commonly has cardinality 6 (although // occasionally you do see a complete matching i.e. cardinality 8). TestInstance.fromBits(8, 8, randomBits(8 * 8, 0.25, rng)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_random8x8
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void maximumCardinalityBipartiteMatching_randomSparse8x8() { Random rng = new Random(0x0ddba11); for (int i = 0; i < 100; i++) { // Set each bit with probability 0.125, giving an average of 1 of the possible 8 edges per // vertex. By observation, the maximal matching most commonly has cardinality 4. TestInstance.fromBits(8, 8, randomBits(8 * 8, 0.125, rng)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_randomSparse8x8
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test @GwtIncompatible("slow") public void maximumCardinalityBipartiteMatching_randomDense8x8() { if (Platform.isAndroid()) { return; // slow } Random rng = new Random(0x5add1e5); for (int i = 0; i < 100; i++) { // Set each bit with probability 0.5, giving an average of 4 of the possible 8 edges per // vertex. By observation, a complete matching is almost always possible (although // occasionally you do see a maximum cardinality of 7 or even fewer). TestInstance.fromBits(8, 8, randomBits(8 * 8, 0.5, rng)).testAgainstBruteForce(); } }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_randomDense8x8
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void maximumCardinalityBipartiteMatching_failsWithNullLhs() { ListMultimap<String, String> edges = LinkedListMultimap.create(); edges.put(null, "R1"); assertThrows(NullPointerException.class, () -> maximumCardinalityBipartiteMatching(edges)); }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_failsWithNullLhs
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void maximumCardinalityBipartiteMatching_failsWithNullRhs() { ListMultimap<String, String> edges = LinkedListMultimap.create(); edges.put("L1", null); assertThrows(NullPointerException.class, () -> maximumCardinalityBipartiteMatching(edges)); }
Tests for {@link GraphMatching}. @author Pete Gillin
maximumCardinalityBipartiteMatching_failsWithNullRhs
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
static TestInstance empty() { return new TestInstance(ImmutableListMultimap.<String, String>of()); }
Generates a test instance with an empty bipartite graph.
empty
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
static TestInstance fullyConnected(int lhsSize, int rhsSize) { ImmutableListMultimap.Builder<String, String> edges = ImmutableListMultimap.builder(); for (int lhs = 0; lhs < lhsSize; lhs++) { for (int rhs = 0; rhs < rhsSize; rhs++) { edges.put("L" + lhs, "R" + rhs); } } return new TestInstance(edges.build()); }
Generates a test instance with a fully-connected bipartite graph where there are {@code lhsSize} elements in one set of vertices (which we call the LHS) and {@code rhsSize} elements in the other (the RHS).
fullyConnected
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
static TestInstance fromBits(int lhsSize, int rhsSize, BitSet bits) { ImmutableListMultimap.Builder<String, String> edges = ImmutableListMultimap.builder(); for (int lhs = 0; lhs < lhsSize; lhs++) { for (int rhs = 0; rhs < rhsSize; rhs++) { if (bits.get(lhs * rhsSize + rhs)) { edges.put("L" + lhs, "R" + rhs); } } } return new TestInstance(edges.build()); }
Generates a test instance with a bipartite graph where there are {@code lhsSize} elements in one set of vertices (which we call the LHS) and {@code rhsSize} elements in the other (the RHS) and whether or not each of the {@code lhsSize * rhsSize} possible edges is included or not according to whether one of the first {@code lhsSize * rhsSize} bits of {@code bits} is set or not.
fromBits
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
void testAgainstBruteForce() { ImmutableBiMap<String, String> actual = maximumCardinalityBipartiteMatching(edges); for (Map.Entry<String, String> entry : actual.entrySet()) { assertWithMessage( "The returned bimap <%s> was not a matching of the bipartite graph <%s>", actual, edges) .that(edges) .containsEntry(entry.getKey(), entry.getValue()); } ImmutableBiMap<String, String> expected = bruteForceMaximalMatching(); assertWithMessage( "The returned matching for the bipartite graph <%s> was not the same size as " + "the brute-force maximal matching <%s>", edges, expected) .that(actual) .hasSize(expected.size()); }
Finds the maximum bipartite matching using the method under test and asserts both that it is actually a matching of this bipartite graph and that it has the same size as a maximum bipartite matching found by a brute-force approach.
testAgainstBruteForce
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
void testAgainstKnownSize(int expectedSize) { ImmutableBiMap<String, String> actual = maximumCardinalityBipartiteMatching(edges); for (Map.Entry<String, String> entry : actual.entrySet()) { assertWithMessage( "The returned bimap <%s> was not a matching of the bipartite graph <%s>", actual, edges) .that(edges) .containsEntry(entry.getKey(), entry.getValue()); } assertWithMessage( "The returned matching for the bipartite graph <%s> had the wrong size", edges) .that(actual) .hasSize(expectedSize); }
Finds the maximum bipartite matching using the method under test and asserts both that it is actually a matching of this bipartite graph and that it has the expected size.
testAgainstKnownSize
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
private ImmutableBiMap<String, String> bruteForceMaximalMatching() { ImmutableBiMap<String, String> best = ImmutableBiMap.of(); Matching candidate = new Matching(); while (candidate.valid()) { if (candidate.size() > best.size()) { best = candidate.asBiMap(); } candidate.advance(); } return best; }
Returns a maximal bipartite matching of the bipartite graph, performing a brute force evaluation of every possible matching.
bruteForceMaximalMatching
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
boolean valid() { // When advance() has advanced through all the non-empty maps, the final state is that // selectedEdges is empty, so we use that state as a marker of the final invalid cursor. return !selectedEdges.isEmpty(); }
Returns whether this cursor is valid. Returns true if it has been advanced past the end of the sequence.
valid
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
ImmutableBiMap<String, String> asBiMap() { Preconditions.checkState(valid()); return ImmutableBiMap.copyOf(selectedEdges); }
Returns an immutable representation of the current state of the matching as a bimap giving the edges used in the matching, where the keys identify the vertices in the first set and the values identify the vertices in the second set. The bimap is guaranteed not to be empty. Fails if this cursor is invalid.
asBiMap
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
int size() { Preconditions.checkState(valid()); return selectedEdges.size(); }
Returns the size (i.e. the number of edges in) the current matching, which is guaranteed to be positive (not zer). Fails if this cursor is invalid.
size
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
void advance() { Preconditions.checkState(valid()); // We essentially do a depth-first traversal through the possible matchings. // First we try to add an edge. Edge lastEdge = edgeStack.getLast(); Edge nextEdge = new Edge(lastEdge); nextEdge.advance(); if (nextEdge.valid()) { edgeStack.addLast(nextEdge); nextEdge.addToSelected(); return; } // We can't add an edge, so we try to advance the edge at the top of the stack. If we can't // advance that edge, we remove it and attempt to advance the new top of stack instead. while (valid()) { lastEdge = edgeStack.getLast(); lastEdge.removeFromSelected(); lastEdge.advance(); if (lastEdge.valid()) { lastEdge.addToSelected(); return; } else { edgeStack.removeLast(); } } // We have reached the end of the sequence, and edgeStack is empty. }
Advances to the next matching in the sequence, or invalidates the cursor if this was the last. Fails if this cursor is invalid.
advance
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
boolean valid() { // When advance() has advanced through all the edges, the final state is that lhsIndex == // lhsVertices.size(), so we use that state as a marker of the final invalid cursor. return lhsIndex < lhsVertices.size(); }
Returns whether this cursor is valid. Returns true if it has been advanced past the end of the sequence.
valid
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
void addToSelected() { Preconditions.checkState(valid()); Preconditions.checkState(!selectedEdges.containsKey(lhsVertex())); Preconditions.checkState(!selectedEdges.containsValue(rhsVertex())); selectedEdges.put(lhsVertex(), rhsVertex()); }
Adds the current edge to the matching. Fails if either of the vertices in the edge is already in the matching. Fails if this cursor is invalid.
addToSelected
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
void removeFromSelected() { Preconditions.checkState(valid()); Preconditions.checkState(selectedEdges.containsKey(lhsVertex())); Preconditions.checkState(selectedEdges.get(lhsVertex()).equals(rhsVertex())); selectedEdges.remove(lhsVertex()); }
Removes the current edge from the matching. Fails if this edge is not in the matching. Fails if this cursor is invalid.
removeFromSelected
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
void advance() { Preconditions.checkState(valid()); // We iterate over the possible edges in a lexicographical order with the LHS index as the // most significant part and the RHS index as the least significant. So we first try // advancing to the next RHS index for the current LHS index, and if we can't we advance // to the next LHS index in the map and the first RHS index for that. ++rhsIndexForLhs; while (lhsIndex < lhsVertices.size()) { if (!selectedEdges.containsKey(lhsVertex())) { while (rhsIndexForLhs < edges.get(lhsVertex()).size()) { if (!selectedEdges.containsValue(rhsVertex())) { return; } ++rhsIndexForLhs; } } ++lhsIndex; rhsIndexForLhs = 0; } // We have reached the end of the sequence, and lhsIndex == lhsVertices.size(). }
Advances to the next edge in the sequence, or invalidates the cursor if this was the last. Skips over edges which cannot be added to the matching because either vertex is already in it. Fails if this cursor is invalid.
advance
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
private String lhsVertex() { return lhsVertices.get(lhsIndex); }
Advances to the next edge in the sequence, or invalidates the cursor if this was the last. Skips over edges which cannot be added to the matching because either vertex is already in it. Fails if this cursor is invalid.
lhsVertex
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
private String rhsVertex() { return edges.get(lhsVertex()).get(rhsIndexForLhs); }
Advances to the next edge in the sequence, or invalidates the cursor if this was the last. Skips over edges which cannot be added to the matching because either vertex is already in it. Fails if this cursor is invalid.
rhsVertex
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
private static BitSet intBits(int intValue) { BitSet bits = new BitSet(); for (int bitIndex = 0; bitIndex < Integer.SIZE; bitIndex++) { bits.set(bitIndex, (intValue & (1L << bitIndex)) != 0); } return bits; }
Returns a bitset corresponding to the binary representation of the given integer.
intBits
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
private static BitSet randomBits(int maxBits, double bitProbability, Random rng) { BitSet bits = new BitSet(); for (int bitIndex = 0; bitIndex < maxBits; bitIndex++) { bits.set(bitIndex, rng.nextDouble() < bitProbability); } return bits; }
Returns a bitset of up to {@code maxBits} bits where each bit is set with a probability {@code bitProbability} using the given RNG.
randomBits
java
google/truth
core/src/test/java/com/google/common/truth/GraphMatchingTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GraphMatchingTest.java
Apache-2.0
@Test public void isPresent() { assertThat(Optional.of("foo")).isPresent(); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
isPresent
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void isPresentFailing() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(Optional.absent()).isPresent()); assertFailureKeys(e, "expected to be present"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
isPresentFailing
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void isPresentFailingNull() { AssertionError e = expectFailure(whenTesting -> whenTesting.that((Optional<?>) null).isPresent()); assertFailureKeys(e, "expected present optional", "but was"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
isPresentFailingNull
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void isAbsent() { assertThat(Optional.absent()).isAbsent(); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
isAbsent
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void isAbsentFailing() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(Optional.of("foo")).isAbsent()); assertFailureKeys(e, "expected to be absent", "but was present with value"); assertFailureValue(e, "but was present with value", "foo"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
isAbsentFailing
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void isAbsentFailingNull() { AssertionError e = expectFailure(whenTesting -> whenTesting.that((Optional<?>) null).isAbsent()); assertFailureKeys(e, "expected absent optional", "but was"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
isAbsentFailingNull
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void hasValue() { assertThat(Optional.of("foo")).hasValue("foo"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
hasValue
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void hasValue_failingWithAbsent() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(Optional.absent()).hasValue("foo")); assertFailureKeys(e, "expected to have value", "but was absent"); assertFailureValue(e, "expected to have value", "foo"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
hasValue_failingWithAbsent
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void hasValue_failingWithNullParameter() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(Optional.of("foo")).hasValue(null)); assertFailureKeys(e, "expected an optional with a null value, but that is impossible", "was"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
hasValue_failingWithNullParameter
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test public void hasValue_failingWithWrongValue() { AssertionError e = expectFailure(whenTesting -> whenTesting.that(Optional.of("foo")).hasValue("boo")); assertFailureValue(e, "value of", "optional.get()"); }
Tests for Guava {@link Optional} Subjects. @author Christian Gruber ([email protected])
hasValue_failingWithWrongValue
java
google/truth
core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/GuavaOptionalSubjectTest.java
Apache-2.0
@Test @SuppressWarnings("TruthSelfEquals") public void simpleEquality() { assertThat(4).isEqualTo(4); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
simpleEquality
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void simpleInequality() { assertThat(4).isNotEqualTo(5); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
simpleInequality
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void equalityWithLongs() { assertThat(0).isEqualTo(0L); expectFailure(whenTesting -> whenTesting.that(0).isNotEqualTo(0L)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
equalityWithLongs
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void equalityFail() { expectFailure(whenTesting -> whenTesting.that(4).isEqualTo(5)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
equalityFail
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@SuppressWarnings("SelfAssertion") @Test public void inequalityFail() { expectFailure(whenTesting -> whenTesting.that(4).isNotEqualTo(4)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
inequalityFail
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void equalityOfNulls() { assertThat((Integer) null).isEqualTo(null); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
equalityOfNulls
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void equalityOfNullsFail_nullActual() { expectFailure(whenTesting -> whenTesting.that((Integer) null).isEqualTo(5)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
equalityOfNullsFail_nullActual
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void equalityOfNullsFail_nullExpected() { expectFailure(whenTesting -> whenTesting.that(5).isEqualTo(null)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
equalityOfNullsFail_nullExpected
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void inequalityOfNulls() { assertThat(4).isNotEqualTo(null); assertThat((Integer) null).isNotEqualTo(4); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
inequalityOfNulls
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void inequalityOfNullsFail() { expectFailure(whenTesting -> whenTesting.that((Integer) null).isNotEqualTo(null)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
inequalityOfNullsFail
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void overflowOnPrimitives() { assertThat(Long.MIN_VALUE).isNotEqualTo(Integer.MIN_VALUE); assertThat(Long.MAX_VALUE).isNotEqualTo(Integer.MAX_VALUE); assertThat(Integer.MIN_VALUE).isNotEqualTo(Long.MIN_VALUE); assertThat(Integer.MAX_VALUE).isNotEqualTo(Long.MAX_VALUE); assertThat(Integer.MIN_VALUE).isEqualTo((long) Integer.MIN_VALUE); assertThat(Integer.MAX_VALUE).isEqualTo((long) Integer.MAX_VALUE); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
overflowOnPrimitives
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void overflowOnPrimitives_shouldBeEqualAfterCast_min() { expectFailure( whenTesting -> whenTesting.that(Integer.MIN_VALUE).isNotEqualTo((long) Integer.MIN_VALUE)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
overflowOnPrimitives_shouldBeEqualAfterCast_min
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void overflowOnPrimitives_shouldBeEqualAfterCast_max() { expectFailure( whenTesting -> whenTesting.that(Integer.MAX_VALUE).isNotEqualTo((long) Integer.MAX_VALUE)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
overflowOnPrimitives_shouldBeEqualAfterCast_max
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void overflowBetweenIntegerAndLong_shouldBeDifferent_min() { expectFailure(whenTesting -> whenTesting.that(Integer.MIN_VALUE).isEqualTo(Long.MIN_VALUE)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
overflowBetweenIntegerAndLong_shouldBeDifferent_min
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void overflowBetweenIntegerAndLong_shouldBeDifferent_max() { expectFailure(whenTesting -> whenTesting.that(Integer.MAX_VALUE).isEqualTo(Long.MAX_VALUE)); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
overflowBetweenIntegerAndLong_shouldBeDifferent_max
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void isWithinOf() { assertThat(20000).isWithin(0).of(20000); assertThat(20000).isWithin(1).of(20000); assertThat(20000).isWithin(10000).of(20000); assertThat(20000).isWithin(10000).of(30000); assertThat(Integer.MIN_VALUE).isWithin(1).of(Integer.MIN_VALUE + 1); assertThat(Integer.MAX_VALUE).isWithin(1).of(Integer.MAX_VALUE - 1); assertThat(Integer.MAX_VALUE / 2).isWithin(Integer.MAX_VALUE).of(-Integer.MAX_VALUE / 2); assertThat(-Integer.MAX_VALUE / 2).isWithin(Integer.MAX_VALUE).of(Integer.MAX_VALUE / 2); assertThatIsWithinFails(20000, 9999, 30000); assertThatIsWithinFails(20000, 10000, 30001); assertThatIsWithinFails(Integer.MIN_VALUE, 0, Integer.MAX_VALUE); assertThatIsWithinFails(Integer.MAX_VALUE, 0, Integer.MIN_VALUE); assertThatIsWithinFails(Integer.MIN_VALUE, 1, Integer.MIN_VALUE + 2); assertThatIsWithinFails(Integer.MAX_VALUE, 1, Integer.MAX_VALUE - 2); // Don't fall for rollover assertThatIsWithinFails(Integer.MIN_VALUE, 1, Integer.MAX_VALUE); assertThatIsWithinFails(Integer.MAX_VALUE, 1, Integer.MIN_VALUE); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
isWithinOf
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
private static void assertThatIsWithinFails(int actual, int tolerance, int 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 Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
assertThatIsWithinFails
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void isNotWithinOf() { assertThatIsNotWithinFails(20000, 0, 20000); assertThatIsNotWithinFails(20000, 1, 20000); assertThatIsNotWithinFails(20000, 10000, 20000); assertThatIsNotWithinFails(20000, 10000, 30000); assertThatIsNotWithinFails(Integer.MIN_VALUE, 1, Integer.MIN_VALUE + 1); assertThatIsNotWithinFails(Integer.MAX_VALUE, 1, Integer.MAX_VALUE - 1); assertThatIsNotWithinFails(Integer.MAX_VALUE / 2, Integer.MAX_VALUE, -Integer.MAX_VALUE / 2); assertThatIsNotWithinFails(-Integer.MAX_VALUE / 2, Integer.MAX_VALUE, Integer.MAX_VALUE / 2); assertThat(20000).isNotWithin(9999).of(30000); assertThat(20000).isNotWithin(10000).of(30001); assertThat(Integer.MIN_VALUE).isNotWithin(0).of(Integer.MAX_VALUE); assertThat(Integer.MAX_VALUE).isNotWithin(0).of(Integer.MIN_VALUE); assertThat(Integer.MIN_VALUE).isNotWithin(1).of(Integer.MIN_VALUE + 2); assertThat(Integer.MAX_VALUE).isNotWithin(1).of(Integer.MAX_VALUE - 2); // Don't fall for rollover assertThat(Integer.MIN_VALUE).isNotWithin(1).of(Integer.MAX_VALUE); assertThat(Integer.MAX_VALUE).isNotWithin(1).of(Integer.MIN_VALUE); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
isNotWithinOf
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
private static void assertThatIsNotWithinFails(int actual, int tolerance, int 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 Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
assertThatIsNotWithinFails
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test public void isWithinNegativeTolerance() { isWithinNegativeToleranceFails(0, -10, 0); isWithinNegativeToleranceFails(0, -10, 0); isNotWithinNegativeToleranceFails(0, -10, 0); isNotWithinNegativeToleranceFails(0, -10, 0); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
isWithinNegativeTolerance
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
private static void isWithinNegativeToleranceFails(int actual, int tolerance, int expected) { AssertionError e = expectFailure(whenTesting -> whenTesting.that(actual).isWithin(tolerance).of(expected)); assertFailureKeys( e, "could not perform approximate-equality check because tolerance is negative", "expected", "was", "tolerance"); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
isWithinNegativeToleranceFails
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
private static void isNotWithinNegativeToleranceFails(int actual, int tolerance, int expected) { AssertionError e = expectFailure(whenTesting -> whenTesting.that(actual).isNotWithin(tolerance).of(expected)); assertFailureKeys( e, "could not perform approximate-equality check because tolerance is negative", "expected", "was", "tolerance"); }
Tests for Integer Subjects. @author David Saff @author Christian Gruber @author Kurt Alfred Kluever
isNotWithinNegativeToleranceFails
java
google/truth
core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntegerSubjectTest.java
Apache-2.0
@Test @SuppressWarnings("TruthSelfEquals") public void testIsEqualTo() { IntStream stream = IntStream.of(42); assertThat(stream).isEqualTo(stream); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsEqualTo
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testIsEqualToList() { IntStream stream = IntStream.of(42); List<Integer> list = asList(42); AssertionError unused = expectFailure(whenTesting -> whenTesting.that(stream).isEqualTo(list)); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsEqualToList
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testNullStream_fails() { IntStream nullStream = null; assertThrows(NullPointerException.class, () -> assertThat(nullStream).isEmpty()); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testNullStream_fails
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testNullStreamIsNull() { IntStream nullStream = null; assertThat(nullStream).isNull(); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testNullStreamIsNull
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test @SuppressWarnings("TruthSelfEquals") public void testIsSameInstanceAs() { IntStream stream = IntStream.of(1); assertThat(stream).isSameInstanceAs(stream); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsSameInstanceAs
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testIsEmpty() { assertThat(IntStream.of()).isEmpty(); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsEmpty
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testIsEmpty_fails() { AssertionError unused = expectFailure(whenTesting -> whenTesting.that(IntStream.of(42)).isEmpty()); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsEmpty_fails
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testIsNotEmpty() { assertThat(IntStream.of(42)).isNotEmpty(); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsNotEmpty
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testIsNotEmpty_fails() { AssertionError unused = expectFailure(whenTesting -> whenTesting.that(IntStream.of()).isNotEmpty()); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testIsNotEmpty_fails
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testHasSize() { assertThat(IntStream.of(42)).hasSize(1); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testHasSize
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testHasSize_fails() { AssertionError unused = expectFailure(whenTesting -> whenTesting.that(IntStream.of(42)).hasSize(2)); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testHasSize_fails
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testContainsNoDuplicates() { assertThat(IntStream.of(42)).containsNoDuplicates(); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testContainsNoDuplicates
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0
@Test public void testContainsNoDuplicates_fails() { AssertionError unused = expectFailure(whenTesting -> whenTesting.that(IntStream.of(42, 42)).containsNoDuplicates()); }
Tests for {@link IntStream} Subjects. @author Kurt Alfred Kluever
testContainsNoDuplicates_fails
java
google/truth
core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/IntStreamSubjectTest.java
Apache-2.0