Skip to content

Commit 3183829

Browse files
authored
Graph implementation (#47)
* Added all the test files into one test_cases folder * Created a folder named Graph_implementation and added 3 files in it, 1)Graph.py which contains all the methods, 2) SearchAlgorithms.py which contains some searching algos. and 3)main.py * Added 'test_cases' folder under which added test cases files for graph implementation are added
1 parent 5a87ff1 commit 3183829

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

test_cases/graph.py Test Cases.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Import the necessary modules and classes from graph.py
2+
from easyPythonpi.Graph_implementation.Graph import Graph
3+
4+
# Create an instance of the Graph class
5+
graph = Graph()
6+
7+
# Test adding edges
8+
def test_add_edge():
9+
graph.add_edge('A', 'B')
10+
graph.add_edge('A', 'C')
11+
graph.add_edge('B', 'C')
12+
assert 'A' in graph.graph
13+
assert 'B' in graph.graph
14+
assert 'C' in graph.graph
15+
assert 'B' in graph.graph['A']
16+
assert 'C' in graph.graph['A']
17+
assert 'C' in graph.graph['B']
18+
19+
# Run the test
20+
test_add_edge()

test_cases/main.py Test Cases.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Import the necessary modules and classes from main.py
2+
from easyPythonpi.Graph_implementation.main import Graph, bfs, dfs
3+
4+
# Create an instance of the Graph class
5+
graph = Graph()
6+
7+
# Add edges to the graph
8+
graph.add_edge('A', 'B')
9+
graph.add_edge('A', 'C')
10+
graph.add_edge('B', 'C')
11+
graph.add_edge('C', 'D')
12+
13+
# Test Breadth-First Search (BFS) from main.py
14+
def test_bfs():
15+
result = bfs(graph.graph, 'A')
16+
assert result == ['A', 'B', 'C', 'D']
17+
18+
# Test Depth-First Search (DFS) from main.py
19+
def test_dfs():
20+
result = dfs(graph.graph, 'A')
21+
assert result == ['A', 'B', 'C', 'D']
22+
23+
# Run the tests
24+
test_bfs()
25+
test_dfs()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Import the necessary modules and functions from searchalgorithms.py
2+
from easyPythonpi.Graph_implementation.SearchAlgorithms import bfs, dfs
3+
4+
# Create a sample graph for testing
5+
graph = {
6+
'A': ['B', 'C'],
7+
'B': ['C', 'D'],
8+
'C': ['D'],
9+
'D': ['C'],
10+
'E': ['F'],
11+
'F': ['C'],
12+
}
13+
14+
# Test Breadth-First Search (BFS)
15+
def test_bfs():
16+
result = bfs(graph, 'A')
17+
assert result == ['A', 'B', 'C', 'D']
18+
19+
# Test Depth-First Search (DFS)
20+
def test_dfs():
21+
result = dfs(graph, 'A')
22+
assert result == ['A', 'B', 'C', 'D']
23+
24+
# Run the tests
25+
test_bfs()
26+
test_dfs()

0 commit comments

Comments
 (0)