@@ -8,7 +8,8 @@ addprocs(2)
8
8
Pkg. activate (" ." )
9
9
using ParallelUtilities
10
10
import ParallelUtilities: BinaryTreeNode, RemoteChannelContainer, BranchChannel,
11
- Sorted, Unsorted, Ordering, pval, value, reducedvalue, collectvalues, reduceTreeNode
11
+ Sorted, Unsorted, Ordering, pval, value, reducedvalue, collectvalues, reduceTreeNode,
12
+ BinaryTree, constructBinaryTree, parentnoderank
12
13
end
13
14
14
15
@testset " ProductSplit" begin
@@ -440,39 +441,63 @@ end
440
441
441
442
@test_throws ParallelUtilities. BinaryTreeError BinaryTreeNode (p,p,(2 ,3 ,4 ))
442
443
end
443
-
444
- @testset " constructBinaryTree" begin
445
- for imax = 1 : 10
446
- procs = collect (1 : imax)
447
- tree = ParallelUtilities. constructBinaryTree (procs)
448
- @test length (tree) == length (procs)
449
- @test tree[1 ]. parent == 1
450
- for (rank,node) in enumerate (tree)
451
- @test node. p == procs[rank]
452
- @test node. parent == procs[ParallelUtilities. parentnoderank (rank)]
453
- end
454
- end
455
-
456
- procs = [1 ]
457
- tree = ParallelUtilities. constructBinaryTree (procs)
458
- @test tree[1 ]. children == ()
459
-
460
- procs = collect (1 : 2 )
461
- tree = ParallelUtilities. constructBinaryTree (procs)
462
- @test tree[1 ]. children == (2 ,)
463
- @test tree[2 ]. children == ()
464
-
465
- procs = collect (1 : 8 )
466
- tree = ParallelUtilities. constructBinaryTree (procs)
467
- @test tree[1 ]. children == (2 ,3 )
468
- @test tree[2 ]. children == (4 ,5 )
469
- @test tree[3 ]. children == (6 ,7 )
470
- @test tree[4 ]. children == (8 ,)
471
- @test tree[5 ]. children == ()
472
- @test tree[6 ]. children == ()
473
- @test tree[7 ]. children == ()
474
- @test tree[8 ]. children == ()
475
- end
444
+ end
445
+
446
+ @testset " BinaryTree" begin
447
+
448
+ @testset " constructBinaryTree" begin
449
+ for imax = 1 : 10
450
+ procs = collect (1 : imax)
451
+ tree = constructBinaryTree (procs)
452
+ @test length (tree) == length (procs)
453
+ @test tree[1 ]. parent == 1
454
+ for (rank,node) in enumerate (tree)
455
+ @test node. p == procs[rank]
456
+ @test node. parent == procs[parentnoderank (rank)]
457
+ end
458
+ end
459
+
460
+ procs = [1 ]
461
+ tree = constructBinaryTree (procs)
462
+ @test tree[1 ]. children == ()
463
+
464
+ procs = collect (1 : 2 )
465
+ tree = constructBinaryTree (procs)
466
+ @test tree[1 ]. children == (2 ,)
467
+ @test tree[2 ]. children == ()
468
+
469
+ procs = collect (1 : 8 )
470
+ tree = constructBinaryTree (procs)
471
+ @test tree[1 ]. children == (2 ,3 )
472
+ @test tree[2 ]. children == (4 ,5 )
473
+ @test tree[3 ]. children == (6 ,7 )
474
+ @test tree[4 ]. children == (8 ,)
475
+ @test tree[5 ]. children == ()
476
+ @test tree[6 ]. children == ()
477
+ @test tree[7 ]. children == ()
478
+ @test tree[8 ]. children == ()
479
+ end
480
+
481
+ @testset " Constructor" begin
482
+ function test_constructor (procs)
483
+ bt = BinaryTree (procs)
484
+ btvector = constructBinaryTree (procs)
485
+
486
+ @test length (bt) == length (btvector)
487
+ @test ! isempty (bt)
488
+
489
+ for (i,btnode) in enumerate (btvector)
490
+ @test bt[i] == btnode
491
+ end
492
+ end
493
+
494
+ @test_throws DomainError BinaryTree (1 : 0 )
495
+ @test_throws DomainError BinaryTree (Int[])
496
+
497
+ test_constructor (1 : 10 )
498
+ test_constructor (collect (1 : 10 ))
499
+ test_constructor (workers ())
500
+ end
476
501
end
477
502
478
503
@testset " RemoteChannelContainer" begin
678
703
branches = ParallelUtilities. createbranchchannels (T,tree)
679
704
@test length (branches) == length (tree)
680
705
for (rank,branch) in enumerate (branches)
681
- parentrank = ParallelUtilities . parentnoderank (rank)
706
+ parentrank = parentnoderank (rank)
682
707
p = branch. p
683
708
p_parent = branches[parentrank]. p
684
709
@test branch. selfchannels. out. where == p
697
722
end
698
723
end
699
724
700
- tree = ParallelUtilities . constructBinaryTree (workers ())
725
+ tree = constructBinaryTree (workers ())
701
726
for T in [Int,Any,Bool,Vector{Float64},Array{ComplexF64,2 }]
702
727
testbranches (T,tree)
703
728
end
0 commit comments