Code Duplication    Length = 84-84 lines in 2 locations

Grafizzi/Graph/Tests/IG20bTest.php 1 location

@@ 42-125 (lines=84) @@
39
 *
40
 * "Graph definition taken from GraphViz documentation"
41
 */
42
class IG20bTest extends BaseGraphTest {
43
44
  public function setUp() : void {
45
    // not strict by default.
46
    parent::setUpExtended();
47
    $graph = $this->Graph;
48
    $dic = $this->dic;
49
    $graph->setDirected(true);
50
    $graph->setAttributes(array(
51
      new Attribute($dic, 'compound', true),
52
    ));
53
54
    $nullTitle = array(new Attribute($dic, 'title', NULL));
55
    $nodes = array();
56
57
    $graph->addChild($cluster0 = new Cluster($dic, 0, $nullTitle));
58
    foreach (array('a', 'b', 'c', 'd') as $name) {
59
      $cluster0->addChild($nodes[$name] = new Node($dic, $name));
60
    }
61
62
    $graph->addChild($cluster1 = new Cluster($dic, 1, $nullTitle));
63
    foreach (array('e', 'f', 'g') as $name) {
64
      $cluster1->addChild($nodes[$name] = new Node($dic, $name));
65
    }
66
67
    $graph->addChild(new Edge($dic, $nodes['a'], $nodes['b']));
68
    $graph->addChild(new Edge($dic, $nodes['a'], $nodes['c']));
69
    $graph->addChild(new Edge($dic, $nodes['b'], $nodes['d']));
70
71
    // Note how we use getBuildName() instead of getName() for lhead/ltail,
72
    // because this are the strings GraphViz expects.
73
    $graph->addChild(new Edge($dic, $nodes['b'], $nodes['f'], array(
74
      new Attribute($dic, 'lhead', $cluster1->getBuildName()),
75
    )));
76
    $graph->addChild(new Edge($dic, $nodes['c'], $nodes['d']));
77
    $graph->addChild(new Edge($dic, $nodes['c'], $nodes['g'], array(
78
      new Attribute($dic, 'ltail', $cluster0->getBuildName()),
79
      new Attribute($dic, 'lhead', $cluster1->getBuildName()),
80
    )));
81
    $graph->addChild(new Edge($dic, $nodes['c'],  $nodes['e'], array(
82
      new Attribute($dic, 'ltail', $cluster0->getBuildName()),
83
    )));
84
    $graph->addChild(new Edge($dic, $nodes['e'], $nodes['g']));
85
    $graph->addChild(new Edge($dic, $nodes['e'], $nodes['f']));
86
    $graph->addChild(new Edge($dic, $nodes['d'], $nodes['e']));
87
    $graph->addChild(new Edge($dic, $nodes['d'], $nodes['h'] = new Node($dic, 'h', array('implicit' => true))));
88
  }
89
90
  /**
91
   * Tests g->build()
92
   */
93
  public function testBuild() {
94
    $expected = <<<'EOT'
95
digraph G {
96
  compound=true;
97
98
  subgraph cluster_0 {
99
    a;
100
    b;
101
    c;
102
    d;
103
  } /* /subgraph cluster_0 */
104
  subgraph cluster_1 {
105
    e;
106
    f;
107
    g;
108
  } /* /subgraph cluster_1 */
109
  a -> b;
110
  a -> c;
111
  b -> d;
112
  b -> f [ lhead=cluster_1 ];
113
  c -> d;
114
  c -> g [ ltail=cluster_0, lhead=cluster_1 ];
115
  c -> e [ ltail=cluster_0 ];
116
  e -> g;
117
  e -> f;
118
  d -> e;
119
  d -> h;
120
} /* /digraph G */
121
122
EOT;
123
    $this->check($expected, "Image_graphViz test 20b passed.");
124
  }
125
}
126

Grafizzi/Graph/Tests/IG20Test.php 1 location

@@ 42-125 (lines=84) @@
39
 *
40
 * "Graph definition taken from GraphViz documentation"
41
 */
42
class IG20Test extends BaseGraphTest {
43
44
  public function setUp() : void {
45
    // not strict by default.
46
    parent::setUpExtended();
47
    $graph = $this->Graph;
48
    $dic = $this->dic;
49
    $graph->setDirected(true);
50
    $graph->setAttributes(array(
51
      new Attribute($dic, 'compound', true),
52
    ));
53
54
    $nullTitle = array(new Attribute($dic, 'title', NULL));
55
    $nodes = array();
56
57
    $graph->addChild($cluster0 = new Cluster($dic, 'cluster0', $nullTitle));
58
    foreach (array('a', 'b', 'c', 'd') as $name) {
59
      $cluster0->addChild($nodes[$name] = new Node($dic, $name));
60
    }
61
62
    $graph->addChild($cluster1 = new Cluster($dic, 'cluster1', $nullTitle));
63
    foreach (array('e', 'f', 'g') as $name) {
64
      $cluster1->addChild($nodes[$name] = new Node($dic, $name));
65
    }
66
67
    $graph->addChild(new Edge($dic, $nodes['a'], $nodes['b']));
68
    $graph->addChild(new Edge($dic, $nodes['a'], $nodes['c']));
69
    $graph->addChild(new Edge($dic, $nodes['b'], $nodes['d']));
70
71
    // Note how we use getBuildName() instead of getName() for lhead/ltail,
72
    // because this are the strings GraphViz expects.
73
    $graph->addChild(new Edge($dic, $nodes['b'], $nodes['f'], array(
74
      new Attribute($dic, 'lhead', $cluster1->getBuildName()),
75
    )));
76
    $graph->addChild(new Edge($dic, $nodes['c'], $nodes['d']));
77
    $graph->addChild(new Edge($dic, $nodes['c'], $nodes['g'], array(
78
      new Attribute($dic, 'ltail', $cluster0->getBuildName()),
79
      new Attribute($dic, 'lhead', $cluster1->getBuildName()),
80
    )));
81
    $graph->addChild(new Edge($dic, $nodes['c'],  $nodes['e'], array(
82
      new Attribute($dic, 'ltail', $cluster0->getBuildName()),
83
    )));
84
    $graph->addChild(new Edge($dic, $nodes['e'], $nodes['g']));
85
    $graph->addChild(new Edge($dic, $nodes['e'], $nodes['f']));
86
    $graph->addChild(new Edge($dic, $nodes['d'], $nodes['e']));
87
    $graph->addChild(new Edge($dic, $nodes['d'], $nodes['h'] = new Node($dic, 'h', array('implicit' => true))));
88
  }
89
90
  /**
91
   * Tests g->build()
92
   */
93
  public function testBuild() {
94
    $expected = <<<'EOT'
95
digraph G {
96
  compound=true;
97
98
  subgraph cluster0 {
99
    a;
100
    b;
101
    c;
102
    d;
103
  } /* /subgraph cluster0 */
104
  subgraph cluster1 {
105
    e;
106
    f;
107
    g;
108
  } /* /subgraph cluster1 */
109
  a -> b;
110
  a -> c;
111
  b -> d;
112
  b -> f [ lhead=cluster1 ];
113
  c -> d;
114
  c -> g [ ltail=cluster0, lhead=cluster1 ];
115
  c -> e [ ltail=cluster0 ];
116
  e -> g;
117
  e -> f;
118
  d -> e;
119
  d -> h;
120
} /* /digraph G */
121
122
EOT;
123
    $this->check($expected, "Image_graphViz test 20 passed.");
124
  }
125
}
126