<commit_before>/* ==========================================
 * JGraphT : a free Java graph-theory library
 * ==========================================
 *
 * Project Info:  http://jgrapht.sourceforge.net/
 * Project Creator:  <NAME> (http://sourceforge.net/users/barak_naveh)
 *
 * (C) Copyright 2003-2008, by <NAME> and Contributors.
 *
 * This program and the accompanying materials are dual-licensed under
 * either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation, or (at your option) any
 * later version.
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */
/* ------------------
 * DOTImporterTest.java
 * ------------------
 * (C) Copyright 2015-2016, by  <NAME> and Contributors.
 *
 * Original Author:  <NAME> <<EMAIL>>
 * Contributor(s): <NAME>
 *
 * Changes
 * -------
 * 2015 : Initial revision (WS);
 * 19-Aug-2016: Always provide id to vertex providers (DM);
 * 
 */
package org.jgrapht.ext;

import java.io.StringWriter;
import java.util.Map;

import junit.framework.*;
import org.jgrapht.graph.*;

public class DOTImporterTest extends TestCase
{

   public void testUndirectedWithLabels() throws ImportException {
      String input = "graph G {\n"
                     + "  1 [ \"label\"=\"abc123\" ];\n"
                     + "  2 [ label=\"fred\" ];\n"
                     + "  1 -- 2;\n"
                     + "}";

      Multigraph<String, DefaultEdge> expected
            = new Multigraph<String, DefaultEdge>(DefaultEdge.class);
      expected.addVertex("1");
      expected.addVertex("2");
      expected.addEdge("1", "2");


      DOTImporter<String, DefaultEdge> importer = buildImporter();

      Multigraph<String, DefaultEdge> result
            = new Multigraph<String, DefaultEdge>(DefaultEdge.class);
      importer.read(input, result);

      Assert.assertEquals(expected.toString(), result.toString());

      Assert.assertEquals(2, result.vertexSet().size());
      Assert.assertEquals(1, result.edgeSet().size());

   }

   public void testDirectedNoLabels() throws ImportException {
      String input = "digraph graphname {\r\n"
                     + "     a -> b -> c;\r\n"
                     + "     b -> d;\r\n"
                     + " }";

      DirectedMultigraph<String, DefaultEdge> expected
            = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
      expected.addVertex("a");
      expected.addVertex("b");
      expected.addVertex("c");
      expected.addVertex("d");
      expected.addEdge("a", "b");
      expected.addEdge("b", "c");
      expected.addEdge("b", "d");


      DOTImporter<String, DefaultEdge> importer = buildImporter();

      DirectedMultigraph<String, DefaultEdge> result
            = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
      importer.read(input, result);

      Assert.assertEquals(expected.toString(), result.toString());

      Assert.assertEquals(4, result.vertexSet().size());
      Assert.assertEquals(3, result.edgeSet().size());

   }
   
   public void testDirectedSameLabels() throws ImportException {
       String input =   "digraph sample {\n"
                      + "  a -> b;"
                      + "  b -> c;\n"
                      + "  a [ label=\"Test\"];\n"
                      + "  b [ label=\"Test\"];\n"
                      + "  c [ label=\"Test\"];\n"
                      + "}";

       DirectedMultigraph<String, DefaultEdge> expected
             = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
       expected.addVertex("a");
       expected.addVertex("b");
       expected.addVertex("c");
       expected.addEdge("a", "b");
       expected.addEdge("b", "c");

        DOTImporter<String, DefaultEdge> importer = new DOTImporter<String, DefaultEdge>(
            new VertexProvider<String>()
            {
                @Override
                public String buildVertex(
                    String label,
                    Map<String, String> attributes)
                {
                    return label;
                }
            },
            new EdgeProvider<String, DefaultEdge>()
            {
                @Override
                public DefaultEdge buildEdge(
                    String from,
                    String to,
                    String label,
                    Map<String, String> attributes)
                {
                    return new DefaultEdge();
                }
            },
            new VertexUpdater<String>()
            {
                @Override
                public void updateVertex(
                    String vertex,
                    Map<String, String> attributes)
                {
                }
            });

       DirectedMultigraph<String, DefaultEdge> result
             = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
       importer.read(input, result);

       Assert.assertEquals(expected.toString(), result.toString());

       Assert.assertEquals(3, result.vertexSet().size());
       Assert.assertEquals(2, result.edgeSet().size());
    }

   public void testMultiLinksUndirected() throws ImportException {
      String input = "graph G {\n"
                     + "  1 [ label=\"bob\" ];\n"
                     + "  2 [ label=\"fred\" ];\n"
              // the extra label will be ignored but not cause any problems.
                     + "  1 -- 2 [ label=\"friend\"];\n"<commit_msg>Simplified graph equality test by using AbstractBaseGraph#toString()<commit_after>/* ==========================================
 * JGraphT : a free Java graph-theory library
 * ==========================================
 *
 * Project Info:  http://jgrapht.sourceforge.net/
 * Project Creator:  <NAME> (http://sourceforge.net/users/barak_naveh)
 *
 * (C) Copyright 2003-2008, by <NAME> and Contributors.
 *
 * This program and the accompanying materials are dual-licensed under
 * either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation, or (at your option) any
 * later version.
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */
/* ------------------
 * DOTImporterTest.java
 * ------------------
 * (C) Copyright 2015-2016, by  <NAME> and Contributors.
 *
 * Original Author:  <NAME> <<EMAIL>>
 * Contributor(s): <NAME>
 *
 * Changes
 * -------
 * 2015 : Initial revision (WS);
 * 19-Aug-2016: Always provide id to vertex providers (DM);
 * 
 */
package org.jgrapht.ext;

import java.io.StringWriter;
import java.util.Map;

import junit.framework.*;
import org.jgrapht.graph.*;

public class DOTImporterTest extends TestCase
{

   public void testUndirectedWithLabels() throws ImportException {
      String input = "graph G {\n"
                     + "  1 [ \"label\"=\"abc123\" ];\n"
                     + "  2 [ label=\"fred\" ];\n"
                     + "  1 -- 2;\n"
                     + "}";

      Multigraph<String, DefaultEdge> expected
            = new Multigraph<String, DefaultEdge>(DefaultEdge.class);
      expected.addVertex("1");
      expected.addVertex("2");
      expected.addEdge("1", "2");


      DOTImporter<String, DefaultEdge> importer = buildImporter();

      Multigraph<String, DefaultEdge> result
            = new Multigraph<String, DefaultEdge>(DefaultEdge.class);
      importer.read(input, result);

      Assert.assertEquals(expected.toString(), result.toString());

      Assert.assertEquals(2, result.vertexSet().size());
      Assert.assertEquals(1, result.edgeSet().size());

   }

   public void testDirectedNoLabels() throws ImportException {
      String input = "digraph graphname {\r\n"
                     + "     a -> b -> c;\r\n"
                     + "     b -> d;\r\n"
                     + " }";

      DirectedMultigraph<String, DefaultEdge> expected
            = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
      expected.addVertex("a");
      expected.addVertex("b");
      expected.addVertex("c");
      expected.addVertex("d");
      expected.addEdge("a", "b");
      expected.addEdge("b", "c");
      expected.addEdge("b", "d");


      DOTImporter<String, DefaultEdge> importer = buildImporter();

      DirectedMultigraph<String, DefaultEdge> result
            = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
      importer.read(input, result);

      Assert.assertEquals(expected.toString(), result.toString());

      Assert.assertEquals(4, result.vertexSet().size());
      Assert.assertEquals(3, result.edgeSet().size());

   }
   
   public void testDirectedSameLabels() throws ImportException {
       String input =   "digraph sample {\n"
                      + "  a -> b;"
                      + "  b -> c;\n"
                      + "  a [ label=\"Test\"];\n"
                      + "  b [ label=\"Test\"];\n"
                      + "  c [ label=\"Test\"];\n"
                      + "}";

       DirectedMultigraph<String, DefaultEdge> expected
             = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
       expected.addVertex("a");
       expected.addVertex("b");
       expected.addVertex("c");
       expected.addEdge("a", "b");
       expected.addEdge("b", "c");

        DOTImporter<String, DefaultEdge> importer = new DOTImporter<String, DefaultEdge>(
            new VertexProvider<String>()
            {
                @Override
                public String buildVertex(
                    String label,
                    Map<String, String> attributes)
                {
                    return label;
                }
            },
            new EdgeProvider<String, DefaultEdge>()
            {
                @Override
                public DefaultEdge buildEdge(
                    String from,
                    String to,
                    String label,
                    Map<String, String> attributes)
                {
                    return new DefaultEdge();
                }
            },
            new VertexUpdater<String>()
            {
                @Override
                public void updateVertex(
                    String vertex,
                    Map<String, String> attributes)
                {
                }
            });

       DirectedMultigraph<String, DefaultEdge> result
             = new DirectedMultigraph<String, DefaultEdge>(DefaultEdge.class);
       importer.read(input, result);

       Assert.assertEquals(expected.toString(), result.toString());
    }

   public void testMultiLinksUndirected() throws ImportException {
      String input = "graph G {\n"
                     + "  1 [ label=\"bob\" ];\n"
                     + "  2 [ label=\"fred\" ];\n"
              // the extra label will be ignored but not cause any problems.
                     + "  1 -- 2 [ label=\"friend\"];\n"
{'fraction_non_alphanumeric': 0.14685631454973727, 'fraction_numerical': 0.00905961224859576, 'mean_word_length': 1.8628112033195021, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5935200', 'n_tokens_mistral': 3065, 'n_tokens_neox': 2829, 'n_words': 681}