forked from AnotherSkyBoi/COSC-4353-Group-A
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testAddEdges.py
67 lines (61 loc) · 4.22 KB
/
testAddEdges.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from classes import *
def testAddEdges():
'''
testAddEdge:
if undirected
number of weights between source and destination should increase by 1 after addEdge() AND
number of weights between destination and source should increase by 1 after addEdge()
else //it's directed
number of weights between source and destination should increase by 1 after addEdge() AND
number of weights between destination and source should NOT CHANGE after addEdge()
'''
possibleCases = [True, False]
counter = 1
for isMultiGraph in possibleCases:
for isDirected in possibleCases:
for isWeighted in possibleCases:
for n in range(2, 21):
numNodes = n
if isDirected:
numConnections = n * (n - 1) - 1 # we subtract 1 because we need space to add an edge when isMultiGraph = False AND isDirected = False
else:
numConnections = floor(n * (n - 1) / 2) - 1 # we subtract 1 because we need space to add an edge when isMultiGraph = False AND isDirected = False
g = Graph(seed=2, numNodes=numNodes, numConnections=numConnections, name=f"Graph{counter}", date="", description="", weightsRange=[1,5], isMultiGraph=isMultiGraph, isDirected=isDirected, isWeighted=isWeighted)
counter += 1
#select our source and destination pair
if g.isMultiGraph:
source = "0"
destination = "1"
else: # we need to select a source/destination pair that doesnt already have an edge
breakOuterForLoop = False
for row in g.adjacencyLists.keys():
for col in g.adjacencyLists.keys():
if row != col:
if not isinstance(g.adjacencyMatrix.at[row,col], type(np.array([]))):
source = row
destination = col
breakOuterForLoop = True
break
if breakOuterForLoop: break
originalNumberOfEdgesBetweenSourceAndDestiation = len(g.adjacencyMatrix.at[source, destination]) if isinstance(g.adjacencyMatrix.at[source,destination], type(np.array([]))) else 0
originalNumberOfEdgesBetweenDestinationAndSource = len(g.adjacencyMatrix.at[destination, source]) if isinstance(g.adjacencyMatrix.at[destination,source], type(np.array([]))) else 0
g2 = copy.deepcopy(g)
g2.addEdges(source, [destination,1])
numberOfEdgesBetweenSourceAndDestiationAfterAddEdges = len(g2.adjacencyMatrix.at[source, destination]) if isinstance(g2.adjacencyMatrix.at[source,destination], type(np.array([]))) else 0
numberOfEdgesBetweenDestinationAndSourceAfterAddEdges = len(g2.adjacencyMatrix.at[destination, source]) if isinstance(g2.adjacencyMatrix.at[destination,source], type(np.array([]))) else 0
if g.isDirected:
if numberOfEdgesBetweenSourceAndDestiationAfterAddEdges != originalNumberOfEdgesBetweenSourceAndDestiation+1 or numberOfEdgesBetweenDestinationAndSourceAfterAddEdges != originalNumberOfEdgesBetweenDestinationAndSource:
print("shiiii")
print("False")
return
else: #g is undirected
if numberOfEdgesBetweenSourceAndDestiationAfterAddEdges != originalNumberOfEdgesBetweenSourceAndDestiation+1 or numberOfEdgesBetweenDestinationAndSourceAfterAddEdges != originalNumberOfEdgesBetweenDestinationAndSource+1:
print()
print(f"Settings: isMultigraph={g.isMultiGraph}, isDirected={g.isDirected}, isWeighted={g.isWeighted}")
print("original:")
g.display()
print("\nnew:")
g2.display()
print("False")
return
print("True")