Skip to content

Commit

Permalink
Cleaned up tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
JackAtOmenApps committed Nov 22, 2020
1 parent 4d8ab09 commit bc4e488
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ def test_02_dag(self):
adjacency_list.append([f"SA{n}", f"SB{n}"])
adjacency_list.append([f"SA{n}", f"SC{n}"])


# Create and assign nodes to variables
log.debug("Start creating nodes")
for node in node_name_list2:
Expand All @@ -470,39 +471,27 @@ def test_02_dag(self):
# Compute descendants of a root node
canal_root = NetworkNode.objects.get(name="0")
start_time = time.time()
log.debug("Descendants: %s" % str(len(canal_root.descendants())))
log.debug(f"Descendants: {len(canal_root.descendants())}")
execution_time = time.time() - start_time
log.debug("Execution time in seconds: %s" % str(execution_time))
log.debug(f"Execution time in seconds: {execution_time}")

# Compute descendants of a leaf node
canal_leaf = NetworkNode.objects.get(name="200")
start_time = time.time()
log.debug("Ancestors: %s" % str(len(canal_leaf.ancestors())))
log.debug(f"Ancestors: {len(canal_leaf.ancestors(max_depth=200))}")
execution_time = time.time() - start_time
log.debug("Execution time in seconds: %s" % str(execution_time))

# Count number of paths from start to end of graph
# NOTE: Does not work with current method of returning only a single path
# start_time = time.time()
# log.debug(
# "Paths through graph: : %s"
# % str(
# len(
# canal_root.path_ids_list(
# canal_leaf, max_depth=n + 1, max_paths=500000000
# )
# )
# )
# )
# execution_time = time.time() - start_time
# log.debug("Execution time in seconds: %s" % str(execution_time))
log.debug(f"Execution time in seconds: {execution_time}")

# Check if path exists from canal_root to canal_leaf
log.debug(f"Path Exists: {canal_root.path_exists(canal_leaf, max_depth=200)}")
self.assertTrue(canal_root.path_exists(canal_leaf, max_depth=200), True)

# Find distance from root to leaf
log.debug("Distance: %s" % str(canal_root.distance(canal_leaf, max_depth=100)))
self.assertEqual(canal_root.distance(canal_leaf, max_depth=100), 60)
log.debug(f"Distance: {canal_root.distance(canal_leaf, max_depth=200)}")
self.assertEqual(canal_root.distance(canal_leaf, max_depth=200), 60)

log.debug("Node count: %s" % str(NetworkNode.objects.count()))
log.debug("Edge count: %s" % str(NetworkEdge.objects.count()))
log.debug(f"Node count: {NetworkNode.objects.count()}")
log.debug(f"Edge count: {NetworkEdge.objects.count()}")

def test_03_deep_dag(self):
"""
Expand Down Expand Up @@ -544,37 +533,26 @@ def run_test():
# Compute descendants of a root node
root_node = NetworkNode.objects.get(pk=0)
start_time = time.time()
log.debug("Descendants: %s" % str(len(root_node.ancestors())))
log.debug(f"Descendants: {len(root_node.ancestors())}")
execution_time = time.time() - start_time
log.debug("Execution time in seconds: %s" % str(execution_time))
log.debug(f"Execution time in seconds: {execution_time}")

# Compute ancestors of a leaf node
leaf_node = NetworkNode.objects.get(pk=2 * n - 1)
start_time = time.time()
log.debug("Ancestors: %s" % str(len(leaf_node.ancestors())))
log.debug(f"Ancestors: {len(leaf_node.ancestors())}")
execution_time = time.time() - start_time
log.debug("Execution time in seconds: %s" % str(execution_time))
log.debug(f"Execution time in seconds: {execution_time}")

first = NetworkNode.objects.get(name="0")
last = NetworkNode.objects.get(pk=2 * n - 1)

# # Count number of paths from start to end of graph
# # NOTE: Does not work with current method of returning only a single path
# start_time = time.time()
# log.debug(
# "Paths through graph: %s"
# % str(
# len(first.path_ids_list(last, max_depth=n + 1, max_paths=500000000))
# )
# )
# execution_time = time.time() - start_time
# log.debug("Execution time in seconds: %s" % str(execution_time))
last = NetworkNode.objects.get(name=str(2 * n - 1))

log.debug("Distance")
log.debug(f"Path exists: {first.path_exists(last, max_depth=n)}")
self.assertTrue(first.path_exists(last, max_depth=n), True)
self.assertEqual(first.distance(last, max_depth=n), n - 1)

log.debug("Node count: %s" % str(NetworkNode.objects.count()))
log.debug("Edge count: %s" % str(NetworkEdge.objects.count()))
log.debug(f"Node count: {NetworkNode.objects.count()}")
log.debug(f"Edge count: {NetworkEdge.objects.count()}")

# Connect the first-created node to the last-created node
NetworkNode.objects.get(pk=0).add_child(
Expand Down

0 comments on commit bc4e488

Please sign in to comment.