|
1
|
|
|
"""Module to test the Pathfinder algorithm |
|
2
|
|
|
performance with some constrains.""" |
|
3
|
|
|
|
|
4
|
|
|
from unittest import TestCase |
|
5
|
|
|
from exactdelaypathfinder.core import ExactDelayPathfinder |
|
6
|
|
|
import networkx as nx |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class TestExactDelayResults(TestCase): |
|
10
|
|
|
"""Tests for the Exact Delay result constrain.""" |
|
11
|
|
|
|
|
12
|
|
|
def setUp(self): |
|
13
|
|
|
self.pathfinder = ExactDelayPathfinder() |
|
14
|
|
|
self.G = nx.Graph() |
|
15
|
|
|
|
|
16
|
|
|
def add_edges(self): |
|
17
|
|
|
"""Method to set up edges in the graph structure""" |
|
18
|
|
|
edges = [('User1', 'S2', {'delay': 10}), ('User1', 'S3', {'delay': 37}), |
|
19
|
|
|
('S2', 'S4', {'delay': 24}), ('S3', 'S4', {'delay': 48}), |
|
20
|
|
|
('S3', 'S6', {'delay': 96}), ('S4', 'S5', {'delay': 1}), |
|
21
|
|
|
('S6', 'User2', {'delay': 84}), ('S5', 'User2', {'delay': 29})] |
|
22
|
|
|
self.G.add_edges_from(edges) |
|
23
|
|
|
|
|
24
|
|
|
def test_edpf_can_show_best_path_first(self): |
|
25
|
|
|
"""Test search function to see if the first result is the best one.""" |
|
26
|
|
|
|
|
27
|
|
|
# The following is a small-scale topology we will use to test the |
|
28
|
|
|
# algorithm's functionality and correctness. Modifying the nodes and edges (links) |
|
29
|
|
|
# of the graph (topology) will affect the outcome of the test which may result in a failure. |
|
30
|
|
|
nodes = ['User1', 'S2', 'S3', 'S4', 'S5', 'S6', 'User2'] |
|
31
|
|
|
self.G.add_nodes_from(nodes) |
|
32
|
|
|
self.add_edges() |
|
33
|
|
|
|
|
34
|
|
|
# Create result variables and run the test search |
|
35
|
|
|
result = self.pathfinder.search(self.G, 64, 'User1', 'User2') |
|
36
|
|
|
first_result = result[0] |
|
37
|
|
|
actual = first_result.get('total_delay') # extract first result |
|
38
|
|
|
|
|
39
|
|
|
# The first result should be an exact path with delay of 64 |
|
40
|
|
|
self.assertEqual(64, actual) |
|
41
|
|
|
|
|
42
|
|
|
def test_edpf_can_show_empty_result(self): |
|
43
|
|
|
"""Test search function to see if it can return an empty result.""" |
|
44
|
|
|
self.add_edges() |
|
45
|
|
|
|
|
46
|
|
|
# Create isolated node. This node is not connected to another node. |
|
47
|
|
|
isolated_nodes = ['S7'] |
|
48
|
|
|
self.G.add_nodes_from(isolated_nodes) |
|
49
|
|
|
|
|
50
|
|
|
# Find path to the unreachable node - impossible |
|
51
|
|
|
result = self.pathfinder.search(self.G, 64, 'User1', 'S7') |
|
52
|
|
|
self.assertEqual([], result) |
|
53
|
|
|
|