@@ -456,6 +456,7 @@ def test_02_dag(self):
456
456
adjacency_list .append ([f"SA{ n } " , f"SB{ n } " ])
457
457
adjacency_list .append ([f"SA{ n } " , f"SC{ n } " ])
458
458
459
+
459
460
# Create and assign nodes to variables
460
461
log .debug ("Start creating nodes" )
461
462
for node in node_name_list2 :
@@ -470,39 +471,27 @@ def test_02_dag(self):
470
471
# Compute descendants of a root node
471
472
canal_root = NetworkNode .objects .get (name = "0" )
472
473
start_time = time .time ()
473
- log .debug ("Descendants: %s" % str ( len (canal_root .descendants ())) )
474
+ log .debug (f "Descendants: { len (canal_root .descendants ())} " )
474
475
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 } " )
476
477
477
478
# Compute descendants of a leaf node
478
479
canal_leaf = NetworkNode .objects .get (name = "200" )
479
480
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 )) } " )
481
482
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 )
499
488
500
489
# 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 )
503
492
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 ()} " )
506
495
507
496
def test_03_deep_dag (self ):
508
497
"""
@@ -544,37 +533,26 @@ def run_test():
544
533
# Compute descendants of a root node
545
534
root_node = NetworkNode .objects .get (pk = 0 )
546
535
start_time = time .time ()
547
- log .debug ("Descendants: %s" % str ( len (root_node .ancestors ())) )
536
+ log .debug (f "Descendants: { len (root_node .ancestors ())} " )
548
537
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 } " )
550
539
551
540
# Compute ancestors of a leaf node
552
541
leaf_node = NetworkNode .objects .get (pk = 2 * n - 1 )
553
542
start_time = time .time ()
554
- log .debug ("Ancestors: %s" % str ( len (leaf_node .ancestors ())) )
543
+ log .debug (f "Ancestors: { len (leaf_node .ancestors ())} " )
555
544
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 } " )
557
546
558
547
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 ))
572
549
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 )
574
552
self .assertEqual (first .distance (last , max_depth = n ), n - 1 )
575
553
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 ()} " )
578
556
579
557
# Connect the first-created node to the last-created node
580
558
NetworkNode .objects .get (pk = 0 ).add_child (
0 commit comments