Skip to content

Commit bc4e488

Browse files
Cleaned up tests a bit
1 parent 4d8ab09 commit bc4e488

File tree

1 file changed

+22
-44
lines changed

1 file changed

+22
-44
lines changed

tests/test.py

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ def test_02_dag(self):
456456
adjacency_list.append([f"SA{n}", f"SB{n}"])
457457
adjacency_list.append([f"SA{n}", f"SC{n}"])
458458

459+
459460
# Create and assign nodes to variables
460461
log.debug("Start creating nodes")
461462
for node in node_name_list2:
@@ -470,39 +471,27 @@ def test_02_dag(self):
470471
# Compute descendants of a root node
471472
canal_root = NetworkNode.objects.get(name="0")
472473
start_time = time.time()
473-
log.debug("Descendants: %s" % str(len(canal_root.descendants())))
474+
log.debug(f"Descendants: {len(canal_root.descendants())}")
474475
execution_time = time.time() - start_time
475-
log.debug("Execution time in seconds: %s" % str(execution_time))
476+
log.debug(f"Execution time in seconds: {execution_time}")
476477

477478
# Compute descendants of a leaf node
478479
canal_leaf = NetworkNode.objects.get(name="200")
479480
start_time = time.time()
480-
log.debug("Ancestors: %s" % str(len(canal_leaf.ancestors())))
481+
log.debug(f"Ancestors: {len(canal_leaf.ancestors(max_depth=200))}")
481482
execution_time = time.time() - start_time
482-
log.debug("Execution time in seconds: %s" % str(execution_time))
483-
484-
# Count number of paths from start to end of graph
485-
# NOTE: Does not work with current method of returning only a single path
486-
# start_time = time.time()
487-
# log.debug(
488-
# "Paths through graph: : %s"
489-
# % str(
490-
# len(
491-
# canal_root.path_ids_list(
492-
# canal_leaf, max_depth=n + 1, max_paths=500000000
493-
# )
494-
# )
495-
# )
496-
# )
497-
# execution_time = time.time() - start_time
498-
# log.debug("Execution time in seconds: %s" % str(execution_time))
483+
log.debug(f"Execution time in seconds: {execution_time}")
484+
485+
# Check if path exists from canal_root to canal_leaf
486+
log.debug(f"Path Exists: {canal_root.path_exists(canal_leaf, max_depth=200)}")
487+
self.assertTrue(canal_root.path_exists(canal_leaf, max_depth=200), True)
499488

500489
# Find distance from root to leaf
501-
log.debug("Distance: %s" % str(canal_root.distance(canal_leaf, max_depth=100)))
502-
self.assertEqual(canal_root.distance(canal_leaf, max_depth=100), 60)
490+
log.debug(f"Distance: {canal_root.distance(canal_leaf, max_depth=200)}")
491+
self.assertEqual(canal_root.distance(canal_leaf, max_depth=200), 60)
503492

504-
log.debug("Node count: %s" % str(NetworkNode.objects.count()))
505-
log.debug("Edge count: %s" % str(NetworkEdge.objects.count()))
493+
log.debug(f"Node count: {NetworkNode.objects.count()}")
494+
log.debug(f"Edge count: {NetworkEdge.objects.count()}")
506495

507496
def test_03_deep_dag(self):
508497
"""
@@ -544,37 +533,26 @@ def run_test():
544533
# Compute descendants of a root node
545534
root_node = NetworkNode.objects.get(pk=0)
546535
start_time = time.time()
547-
log.debug("Descendants: %s" % str(len(root_node.ancestors())))
536+
log.debug(f"Descendants: {len(root_node.ancestors())}")
548537
execution_time = time.time() - start_time
549-
log.debug("Execution time in seconds: %s" % str(execution_time))
538+
log.debug(f"Execution time in seconds: {execution_time}")
550539

551540
# Compute ancestors of a leaf node
552541
leaf_node = NetworkNode.objects.get(pk=2 * n - 1)
553542
start_time = time.time()
554-
log.debug("Ancestors: %s" % str(len(leaf_node.ancestors())))
543+
log.debug(f"Ancestors: {len(leaf_node.ancestors())}")
555544
execution_time = time.time() - start_time
556-
log.debug("Execution time in seconds: %s" % str(execution_time))
545+
log.debug(f"Execution time in seconds: {execution_time}")
557546

558547
first = NetworkNode.objects.get(name="0")
559-
last = NetworkNode.objects.get(pk=2 * n - 1)
560-
561-
# # Count number of paths from start to end of graph
562-
# # NOTE: Does not work with current method of returning only a single path
563-
# start_time = time.time()
564-
# log.debug(
565-
# "Paths through graph: %s"
566-
# % str(
567-
# len(first.path_ids_list(last, max_depth=n + 1, max_paths=500000000))
568-
# )
569-
# )
570-
# execution_time = time.time() - start_time
571-
# log.debug("Execution time in seconds: %s" % str(execution_time))
548+
last = NetworkNode.objects.get(name=str(2 * n - 1))
572549

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

576-
log.debug("Node count: %s" % str(NetworkNode.objects.count()))
577-
log.debug("Edge count: %s" % str(NetworkEdge.objects.count()))
554+
log.debug(f"Node count: {NetworkNode.objects.count()}")
555+
log.debug(f"Edge count: {NetworkEdge.objects.count()}")
578556

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

0 commit comments

Comments
 (0)