Skip to content

Commit e08a712

Browse files
committed
add tests for left and right units
1 parent aaeb4c3 commit e08a712

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

test/test_A4.jl

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using MultiTensorKit
2-
using TensorKitSectors
2+
using TensorKitSectors, TensorKit
33
using Test, TestExtras
44

55
I = A4Object
@@ -75,3 +75,42 @@ end
7575
@test dual(s) == A4Object(j, i, MultiTensorKit._get_dual_cache(I)[2][i, j][s.label])
7676
@test dual(dual(s)) == s
7777
end
78+
79+
@testset "A4 Category ($i, $j) left and right units" for i in 1:12, j in 1:12
80+
Cij_obs = A4Object.(i, j, MultiTensorKit._get_dual_cache(I)[2][i, j])
81+
82+
s = rand(Cij_obs, 1)[1]
83+
sp = Vect[A4Object](s => 1)
84+
W = sp sp
85+
for T in (Float32, ComplexF64)
86+
t = @constinferred rand(T, W)
87+
88+
for a in 1:2
89+
tl = @constinferred insertleftunit(t, Val(a))
90+
@test numind(tl) == numind(t) + 1
91+
@test space(tl) == insertleftunit(space(t), a)
92+
@test scalartype(tl) === T
93+
@test t.data === tl.data
94+
@test @constinferred(removeunit(tl, $(a))) == t
95+
96+
tr = @constinferred insertrightunit(t, Val(a))
97+
@test numind(tr) == numind(t) + 1
98+
@test space(tr) == insertrightunit(space(t), a)
99+
@test scalartype(tr) === T
100+
@test t.data === tr.data
101+
@test @constinferred(removeunit(tr, $(a + 1))) == t
102+
end
103+
104+
@test_throws ErrorException insertleftunit(t) # default should error here
105+
@test insertrightunit(t) isa TensorMap
106+
@test_throws ErrorException insertleftunit(t, numind(t) + 1) # same as default
107+
@test_throws ErrorException insertrightunit(t, numind(t) + 1) # not same as default
108+
109+
t2 = @constinferred insertrightunit(t; copy=true)
110+
@test t.data !== t2.data
111+
for (c, b) in blocks(t)
112+
@test b == block(t2, c)
113+
end
114+
@test @constinferred(removeunit(t2, $(numind(t2)))) == t
115+
end
116+
end

0 commit comments

Comments
 (0)