<commit_before>/*
 * Copyright (C) 2014 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.common.graph;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.google.common.testing.EqualsTester;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Tests for a directed {@link ConfigurableGraph} with default graph properties.
 */
@RunWith(JUnit4.class)
public class ConfigurableDirectedGraphTest extends ConfigurableSimpleDirectedGraphTest {

  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.directed().build();
  }

  @Test
  public void adjacentNodes_selfLoop() {
    addEdge(N1, N1);
    addEdge(N1, N2);
    assertThat(graph.adjacentNodes(N1)).containsExactly(N1, N2);
  }

  @Test
  public void predecessors_selfLoop() {
    addEdge(N1, N1);
    assertThat(graph.predecessors(N1)).containsExactly(N1);
    addEdge(N4, N1);
    assertThat(graph.predecessors(N1)).containsExactly(N1, N4);
  }

  @Test
  public void successors_selfLoop() {
    addEdge(N1, N1);
    assertThat(graph.successors(N1)).containsExactly(N1);
    addEdge(N1, N2);
    assertThat(graph.successors(N1)).containsExactly(N1, N2);
  }

  @Test
  public void degree_selfLoop() {
    addEdge(N1, N1);
    assertEquals(1, graph.degree(N1));
    addEdge(N1, N2);
    assertEquals(2, graph.degree(N1));
  }

  @Test
  public void inDegree_selfLoop() {
    addEdge(N1, N1);
    assertEquals(1, graph.inDegree(N1));
    addEdge(N4, N1);
    assertEquals(2, graph.inDegree(N1));
  }

  @Test
  public void outDegree_selfLoop() {
    addEdge(N1, N1);
    assertEquals(1, graph.outDegree(N1));
    addEdge(N1, N2);
    assertEquals(2, graph.outDegree(N1));
  }

  @Override
  @Test
  public void addEdge_selfLoop() {
    assertTrue(addEdge(N1, N1));
    assertThat(graph.successors(N1)).containsExactly(N1);
    assertThat(graph.predecessors(N1)).containsExactly(N1);
  }

  @Test
  public void addEdge_existingSelfLoopEdgeBetweenSameNodes() {
    addEdge(N1, N1);
    assertFalse(addEdge(N1, N1));
  }

  @Test
  public void removeNode_existingNodeWithSelfLoopEdge() {
    addNode(N1);
    addEdge(N1, N1);
    assertTrue(graph.removeNode(N1));
    assertThat(graph.nodes()).isEmpty();
  }

  @Test
  public void removeEdge_existingSelfLoopEdge() {
    addEdge(N1, N1);
    assertTrue(graph.removeEdge(N1, N1));
    assertThat(graph.nodes()).containsExactly(N1);
    assertThat(graph.successors(N1)).isEmpty();
  }

  // TODO(kak): Can't we ditch this and just use PackageSanityTests?
  @Test
  public void testEquals() {
    MutableGraph<Integer> graphA = createGraph();
    graphA.addNode(N1);
    MutableGraph<Integer> graphB = createGraph();
    graphA.addNode(N2);

    new EqualsTester()
        .addEqualityGroup(graphA)
        .addEqualityGroup(graphB)
        .testEquals();
  }
}<commit_msg>Followup to "Let PackageSanityTests run over the entire package (and stop special casing)." ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119501361<commit_after>/*
 * Copyright (C) 2014 The Guava Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.common.graph;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Tests for a directed {@link ConfigurableGraph} with default graph properties.
 */
@RunWith(JUnit4.class)
public class ConfigurableDirectedGraphTest extends ConfigurableSimpleDirectedGraphTest {

  @Override
  public MutableGraph<Integer> createGraph() {
    return GraphBuilder.directed().build();
  }

  @Test
  public void adjacentNodes_selfLoop() {
    addEdge(N1, N1);
    addEdge(N1, N2);
    assertThat(graph.adjacentNodes(N1)).containsExactly(N1, N2);
  }

  @Test
  public void predecessors_selfLoop() {
    addEdge(N1, N1);
    assertThat(graph.predecessors(N1)).containsExactly(N1);
    addEdge(N4, N1);
    assertThat(graph.predecessors(N1)).containsExactly(N1, N4);
  }

  @Test
  public void successors_selfLoop() {
    addEdge(N1, N1);
    assertThat(graph.successors(N1)).containsExactly(N1);
    addEdge(N1, N2);
    assertThat(graph.successors(N1)).containsExactly(N1, N2);
  }

  @Test
  public void degree_selfLoop() {
    addEdge(N1, N1);
    assertEquals(1, graph.degree(N1));
    addEdge(N1, N2);
    assertEquals(2, graph.degree(N1));
  }

  @Test
  public void inDegree_selfLoop() {
    addEdge(N1, N1);
    assertEquals(1, graph.inDegree(N1));
    addEdge(N4, N1);
    assertEquals(2, graph.inDegree(N1));
  }

  @Test
  public void outDegree_selfLoop() {
    addEdge(N1, N1);
    assertEquals(1, graph.outDegree(N1));
    addEdge(N1, N2);
    assertEquals(2, graph.outDegree(N1));
  }

  @Override
  @Test
  public void addEdge_selfLoop() {
    assertTrue(addEdge(N1, N1));
    assertThat(graph.successors(N1)).containsExactly(N1);
    assertThat(graph.predecessors(N1)).containsExactly(N1);
  }

  @Test
  public void addEdge_existingSelfLoopEdgeBetweenSameNodes() {
    addEdge(N1, N1);
    assertFalse(addEdge(N1, N1));
  }

  @Test
  public void removeNode_existingNodeWithSelfLoopEdge() {
    addNode(N1);
    addEdge(N1, N1);
    assertTrue(graph.removeNode(N1));
    assertThat(graph.nodes()).isEmpty();
  }

  @Test
  public void removeEdge_existingSelfLoopEdge() {
    addEdge(N1, N1);
    assertTrue(graph.removeEdge(N1, N1));
    assertThat(graph.nodes()).containsExactly(N1);
    assertThat(graph.successors(N1)).isEmpty();
  }
}
{'fraction_non_alphanumeric': 0.12329570444216391, 'fraction_numerical': 0.024776425744025804, 'mean_word_length': 4.1721000758150115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4443901', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2244, 'n_words': 507}