Bearsampp 2026.9.23
Loading...
Searching...
No Matches
BasicGraph Class Reference
Inheritance diagram for BasicGraph:
Collaboration diagram for BasicGraph:

Public Member Functions

 test_add_node ()
 test_connect_node ()
 test_create_graph ()
 test_data_references ()
 test_directed_degree ()
 test_metadata_key_exists ()
 test_metadata_references ()
 test_undirected_degree ()

Data Fields

 $_graph = null

Detailed Description

@access private

Definition at line 32 of file BasicGraphTest.php.

Member Function Documentation

◆ test_add_node()

test_add_node ( )

Definition at line 41 of file BasicGraphTest.php.

41 {
42 $this->_graph = new Structures_Graph();
43 $data = 1;
44 $node = new Structures_Graph_Node($data);
45 $this->_graph->addNode($node);
46 $node = new Structures_Graph_Node($data);
47 $this->_graph->addNode($node);
48 $node = new Structures_Graph_Node($data);
49 $this->_graph->addNode($node);
50 $this->assertTrue(true);
51 }

◆ test_connect_node()

test_connect_node ( )

Definition at line 53 of file BasicGraphTest.php.

53 {
54 $this->_graph = new Structures_Graph();
55 $data = 1;
56 $node1 = new Structures_Graph_Node($data);
57 $node2 = new Structures_Graph_Node($data);
58 $this->_graph->addNode($node1);
59 $this->_graph->addNode($node2);
60 $node1->connectTo($node2);
61
62 $node =& $this->_graph->getNodes();
63 $node =& $node[0];
64 $node = $node->getNeighbours();
65 $node =& $node[0];
66 /*
67 ZE1 == and === operators fail on $node,$node2 because of the recursion introduced
68 by the _graph field in the Node object. So, we'll use the stupid method for reference
69 testing
70 */
71 $node = true;
72 $this->assertTrue($node2);
73 $node = false;
74 $this->assertFalse($node2);
75 }

◆ test_create_graph()

test_create_graph ( )

Definition at line 36 of file BasicGraphTest.php.

36 {
37 $this->_graph = new Structures_Graph();
38 $this->assertTrue(is_a($this->_graph, 'Structures_Graph'));
39 }

◆ test_data_references()

test_data_references ( )

Definition at line 77 of file BasicGraphTest.php.

77 {
78 $this->_graph = new Structures_Graph();
79 $data = 1;
80 $node = new Structures_Graph_Node();
81 $node->setData($data);
82 $this->_graph->addNode($node);
83 $data = 2;
84 $dataInNode =& $this->_graph->getNodes();
85 $dataInNode =& $dataInNode[0];
86 $dataInNode =& $dataInNode->getData();
87 $this->assertEquals($data, $dataInNode);
88 }

◆ test_directed_degree()

test_directed_degree ( )

Definition at line 109 of file BasicGraphTest.php.

109 {
110 $this->_graph = new Structures_Graph(true);
111 $node = array();
112 $node[] = new Structures_Graph_Node();
113 $node[] = new Structures_Graph_Node();
114 $node[] = new Structures_Graph_Node();
115 $this->_graph->addNode($node[0]);
116 $this->_graph->addNode($node[1]);
117 $this->_graph->addNode($node[2]);
118 $this->assertEquals(0, $node[0]->inDegree(), 'inDegree test failed for node 0 with 0 arcs');
119 $this->assertEquals(0, $node[1]->inDegree(), 'inDegree test failed for node 1 with 0 arcs');
120 $this->assertEquals(0, $node[2]->inDegree(), 'inDegree test failed for node 2 with 0 arcs');
121 $this->assertEquals(0, $node[0]->outDegree(), 'outDegree test failed for node 0 with 0 arcs');
122 $this->assertEquals(0, $node[1]->outDegree(), 'outDegree test failed for node 1 with 0 arcs');
123 $this->assertEquals(0, $node[2]->outDegree(), 'outDegree test failed for node 2 with 0 arcs');
124 $node[0]->connectTo($node[1]);
125 $this->assertEquals(0, $node[0]->inDegree(), 'inDegree test failed for node 0 with 1 arc');
126 $this->assertEquals(1, $node[1]->inDegree(), 'inDegree test failed for node 1 with 1 arc');
127 $this->assertEquals(0, $node[2]->inDegree(), 'inDegree test failed for node 2 with 1 arc');
128 $this->assertEquals(1, $node[0]->outDegree(), 'outDegree test failed for node 0 with 1 arc');
129 $this->assertEquals(0, $node[1]->outDegree(), 'outDegree test failed for node 1 with 1 arc');
130 $this->assertEquals(0, $node[2]->outDegree(), 'outDegree test failed for node 2 with 1 arc');
131 $node[0]->connectTo($node[2]);
132 $this->assertEquals(0, $node[0]->inDegree(), 'inDegree test failed for node 0 with 2 arcs');
133 $this->assertEquals(1, $node[1]->inDegree(), 'inDegree test failed for node 1 with 2 arcs');
134 $this->assertEquals(1, $node[2]->inDegree(), 'inDegree test failed for node 2 with 2 arcs');
135 $this->assertEquals(2, $node[0]->outDegree(), 'outDegree test failed for node 0 with 2 arcs');
136 $this->assertEquals(0, $node[1]->outDegree(), 'outDegree test failed for node 1 with 2 arcs');
137 $this->assertEquals(0, $node[2]->outDegree(), 'outDegree test failed for node 2 with 2 arcs');
138 }

◆ test_metadata_key_exists()

test_metadata_key_exists ( )

Definition at line 100 of file BasicGraphTest.php.

100 {
101 $this->_graph = new Structures_Graph();
102 $data = 1;
103 $node = new Structures_Graph_Node();
104 $node->setMetadata('5', $data);
105 $this->assertTrue($node->metadataKeyExists('5'));
106 $this->assertFalse($node->metadataKeyExists('1'));
107 }

◆ test_metadata_references()

test_metadata_references ( )

Definition at line 90 of file BasicGraphTest.php.

90 {
91 $this->_graph = new Structures_Graph();
92 $data = 1;
93 $node = new Structures_Graph_Node();
94 $node->setMetadata('5', $data);
95 $data = 2;
96 $dataInNode =& $node->getMetadata('5');
97 $this->assertEquals($data, $dataInNode);
98 }

◆ test_undirected_degree()

test_undirected_degree ( )

Definition at line 140 of file BasicGraphTest.php.

140 {
141 $this->_graph = new Structures_Graph(false);
142 $node = array();
143 $node[] = new Structures_Graph_Node();
144 $node[] = new Structures_Graph_Node();
145 $node[] = new Structures_Graph_Node();
146 $this->_graph->addNode($node[0]);
147 $this->_graph->addNode($node[1]);
148 $this->_graph->addNode($node[2]);
149 $this->assertEquals(0, $node[0]->inDegree(), 'inDegree test failed for node 0 with 0 arcs');
150 $this->assertEquals(0, $node[1]->inDegree(), 'inDegree test failed for node 1 with 0 arcs');
151 $this->assertEquals(0, $node[2]->inDegree(), 'inDegree test failed for node 2 with 0 arcs');
152 $this->assertEquals(0, $node[0]->outDegree(), 'outDegree test failed for node 0 with 0 arcs');
153 $this->assertEquals(0, $node[1]->outDegree(), 'outDegree test failed for node 1 with 0 arcs');
154 $this->assertEquals(0, $node[2]->outDegree(), 'outDegree test failed for node 2 with 0 arcs');
155 $node[0]->connectTo($node[1]);
156 $this->assertEquals(1, $node[0]->inDegree(), 'inDegree test failed for node 0 with 1 arc');
157 $this->assertEquals(1, $node[1]->inDegree(), 'inDegree test failed for node 1 with 1 arc');
158 $this->assertEquals(0, $node[2]->inDegree(), 'inDegree test failed for node 2 with 1 arc');
159 $this->assertEquals(1, $node[0]->outDegree(), 'outDegree test failed for node 0 with 1 arc');
160 $this->assertEquals(1, $node[1]->outDegree(), 'outDegree test failed for node 1 with 1 arc');
161 $this->assertEquals(0, $node[2]->outDegree(), 'outDegree test failed for node 2 with 1 arc');
162 $node[0]->connectTo($node[2]);
163 $this->assertEquals(2, $node[0]->inDegree(), 'inDegree test failed for node 0 with 2 arcs');
164 $this->assertEquals(1, $node[1]->inDegree(), 'inDegree test failed for node 1 with 2 arcs');
165 $this->assertEquals(1, $node[2]->inDegree(), 'inDegree test failed for node 2 with 2 arcs');
166 $this->assertEquals(2, $node[0]->outDegree(), 'outDegree test failed for node 0 with 2 arcs');
167 $this->assertEquals(1, $node[1]->outDegree(), 'outDegree test failed for node 1 with 2 arcs');
168 $this->assertEquals(1, $node[2]->outDegree(), 'outDegree test failed for node 2 with 2 arcs');
169 }

Field Documentation

◆ $_graph

$_graph = null

Definition at line 34 of file BasicGraphTest.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/tests/Structures_Graph/tests/BasicGraphTest.php