Skip to content

Commit

Permalink
Update toString() for Endpoints in undirected case. Also, change test…
Browse files Browse the repository at this point in the history
… to use EqualsTester, which gives us coverage for hashCode().

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125174596
  • Loading branch information
Bezier89 authored and cpovirk committed Jun 17, 2016
1 parent 7e9055f commit 3a70f36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
20 changes: 14 additions & 6 deletions guava-tests/test/com/google/common/graph/EndpointsTest.java
Expand Up @@ -18,6 +18,8 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.common.testing.EqualsTester;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,23 +31,27 @@
public final class EndpointsTest {

@Test
public void directedEndpoints() {
public void testDirectedEndpoints() {
Endpoints<String> directed = Endpoints.ofDirected("source", "target");
assertThat(directed.source()).isEqualTo("source");
assertThat(directed.target()).isEqualTo("target");
assertThat(directed).containsExactly("source", "target").inOrder();
assertThat(directed.toString()).isEqualTo("<source -> target>");
}

@Test
public void undirectedEndpoints() {
public void testUndirectedEndpoints() {
Endpoints<String> undirected = Endpoints.ofUndirected("chicken", "egg");
assertThat(undirected).containsExactly("chicken", "egg");
assertThat(undirected.toString()).contains("chicken");
assertThat(undirected.toString()).contains("egg");
}

@Test
public void selfLoop() {
public void testSelfLoop() {
Endpoints<String> undirected = Endpoints.ofUndirected("node", "node");
assertThat(undirected).hasSize(2);
assertThat(undirected.toString()).isEqualTo("[node, node]");
}

@Test
Expand All @@ -55,8 +61,10 @@ public void testEquals() {
Endpoints<String> undirected = Endpoints.ofUndirected("a", "b");
Endpoints<String> undirectedMirror = Endpoints.ofUndirected("b", "a");

assertThat(directed).isNotEqualTo(undirected);
assertThat(directed).isNotEqualTo(directedMirror);
assertThat(undirected).isEqualTo(undirectedMirror);
new EqualsTester()
.addEqualityGroup(directed)
.addEqualityGroup(directedMirror)
.addEqualityGroup(undirected, undirectedMirror)
.testEquals();
}
}
7 changes: 0 additions & 7 deletions guava/src/com/google/common/graph/Endpoints.java
Expand Up @@ -20,7 +20,6 @@
import static com.google.common.graph.GraphErrorMessageUtils.NOT_AVAILABLE_ON_UNDIRECTED;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.UnmodifiableIterator;

import java.util.AbstractCollection;
Expand Down Expand Up @@ -220,11 +219,5 @@ public boolean equals(Object obj) {
public int hashCode() {
return nodeA().hashCode() ^ nodeB().hashCode();
}

@Override
public String toString() {
// TODO(b/29393648): Update tests so we can remove this method (defer to AbstractCollection).
return ImmutableSet.copyOf(this).toString();
}
}
}

0 comments on commit 3a70f36

Please sign in to comment.