@@ -2,8 +2,11 @@ using Test: @test, @test_broken, @testset
22
33using BlockArrays: blockfirsts, blocklasts, blocklength, blocklengths, blocks
44using Combinatorics: permutations
5+ using EllipsisNotation: var".."
6+ using TestExtras: @constinferred
57
6- using TensorAlgebra: BlockedTuple, blockedperm, blockedperm_indexin
8+ using TensorAlgebra:
9+ BlockedTrivialPermutation, BlockedTuple, blockedperm, blockedperm_indexin, trivialperm
710
811@testset " BlockedPermutation" begin
912 p = blockedperm ((3 , 4 , 5 ), (2 , 1 ))
@@ -28,7 +31,13 @@ using TensorAlgebra: BlockedTuple, blockedperm, blockedperm_indexin
2831 @test blockfirsts (p) == (1 , 3 , 3 )
2932 @test blocklasts (p) == (2 , 2 , 3 )
3033 @test invperm (p) == blockedperm ((3 , 2 ), (), (1 ,))
31- @test BlockedTuple (p) == BlockedTuple {(2, 0, 1)} ((3 , 2 , 1 ))
34+
35+ bt = BlockedTuple {(2, 0, 1)} ((3 , 2 , 1 ))
36+ @test (@constinferred BlockedTuple (p)) == bt
37+ @test (@constinferred map (identity, p)) == bt
38+ @test (@constinferred p .+ p) == BlockedTuple {(2, 0, 1)} ((6 , 4 , 2 ))
39+ @test (@constinferred blockedperm (p)) == p
40+ @test (@constinferred blockedperm (bt)) == p
3241
3342 # Split collection into `BlockedPermutation`.
3443 p = blockedperm_indexin ((" a" , " b" , " c" , " d" ), (" c" , " a" ), (" b" , " d" ))
@@ -63,3 +72,22 @@ using TensorAlgebra: BlockedTuple, blockedperm, blockedperm_indexin
6372 p = blockedperm ((3 , 2 ), .. , 1 )
6473 @test p == blockedperm ((3 , 2 ), 1 )
6574end
75+
76+ @testset " BlockedTrivialPermutation" begin
77+ p = blockedperm ((3 , 2 ), (), (1 ,))
78+ tp = trivialperm (p)
79+
80+ @test tp isa BlockedTrivialPermutation
81+ @test Tuple (tp) == (1 , 2 , 3 )
82+ @test blocklength (tp) == 3
83+ @test blocklengths (tp) == (2 , 0 , 1 )
84+
85+ bt = BlockedTuple {(2, 0, 1)} ((1 , 2 , 3 ))
86+ @test (@constinferred BlockedTuple (tp)) == bt
87+ @test (@constinferred blocks (tp)) == blocks (bt)
88+ @test (@constinferred map (identity, tp)) == bt
89+ @test (@constinferred tp .+ tp) == BlockedTuple {(2, 0, 1)} ((2 , 4 , 6 ))
90+ @test (@constinferred blockedperm (tp)) == tp
91+ @test (@constinferred trivialperm (tp)) == tp
92+ @test (@constinferred trivialperm (bt)) == tp
93+ end
0 commit comments