Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve test coverage for CartanMatrix.jl #4295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 91 additions & 59 deletions experimental/LieAlgebras/test/CartanMatrix-test.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
@testset "LieAlgebras.CartanMatrix" begin
@testset "cartan_matrix(fam::Symbol, rk::Int)" begin
@testset "cartan_matrix" begin
for i in -1:10
if i < 1
@test_throws ArgumentError cartan_matrix(:A, i)
end
if i < 2
@test_throws ArgumentError cartan_matrix(:B, i)
end
if i < 2
@test_throws ArgumentError cartan_matrix(:C, i)
end
if i < 4
@test_throws ArgumentError cartan_matrix(:D, i)
end
if i < 6 || i > 8
@test_throws ArgumentError cartan_matrix(:E, i)
end
if i != 4
@test_throws ArgumentError cartan_matrix(:F, i)
end
if i != 2
@test_throws ArgumentError cartan_matrix(:G, i)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you transform this block of tests into tests for is_cartan_type and then test the cartan matrix constructor via

for i in -1:10, fam in (:A, :B, :C, :D, :E, :F, :G)
  if is_cartan_type(fam, i)
    cartan_matrix(fam, i)
  else
    @test_throws ArgumentError cartan_matrix(fam, i)
  end
end

?


@test cartan_matrix(:A, 1) == matrix(ZZ, 1, 1, [2])
@test cartan_matrix(:A, 2) == ZZ[2 -1; -1 2]

@test cartan_matrix(:B, 2) == ZZ[2 -1; -2 2]
@test cartan_matrix(:B, 3) == ZZ[2 -1 0; -1 2 -1; 0 -2 2]

@test cartan_matrix(:C, 2) == ZZ[2 -2; -1 2]
@test cartan_matrix(:C, 3) == ZZ[2 -1 0; -1 2 -2; 0 -1 2]

@test cartan_matrix(:D, 4) == ZZ[2 -1 0 0; -1 2 -1 -1; 0 -1 2 0; 0 -1 0 2]

@test_throws ArgumentError root_system(:X, 1)
@test_throws ArgumentError root_system(:A, 0)
@test_throws ArgumentError root_system(:B, 1)
@test_throws ArgumentError root_system(:C, 1)
@test_throws ArgumentError root_system(:D, 2)
@test_throws ArgumentError root_system(:E, 5)
@test_throws ArgumentError root_system(:E, 9)
@test_throws ArgumentError root_system(:F, 3)
@test_throws ArgumentError root_system(:F, 5)
@test_throws ArgumentError root_system(:G, 1)
@test_throws ArgumentError root_system(:G, 3)
end

@testset "cartan_matrix(type::Tuple{Symbol,Int}...)" begin
Expand All @@ -32,25 +41,41 @@
@test_throws ArgumentError cartan_matrix()
end

@testset "is_cartan_matrix(mat::ZZMatrix; generalized::Bool=true)" begin
# test finite type
@test is_cartan_matrix(cartan_matrix(:A, 1)) == true
@test is_cartan_matrix(cartan_matrix(:A, 1); generalized=false) == true

@test is_cartan_matrix(cartan_matrix(:A, 2)) == true
@test is_cartan_matrix(cartan_matrix(:A, 2); generalized=false) == true
@testset "is_cartan_matrix" begin
# test non cartan
@test is_cartan_matrix(ZZ[2 -1; -1 1]) == false
@testset for i in 1:3
is_cartan_matrix(ZZ[2 -i; 0 2]) == false
end

@test is_cartan_matrix(cartan_matrix(:B, 2)) == true
@test is_cartan_matrix(cartan_matrix(:B, 2); generalized=false) == true
# test finite type
function test_is_cartan_matrix_finite_type(cm::ZZMatrix)
rk = nrows(cm)
for _ in 1:50
i, j = rand(1:rk, 2)
if i != j
swap_rows!(cm, i, j)
swap_cols!(cm, i, j)
end
end

@test is_cartan_matrix(cartan_matrix(:C, 2)) == true
@test is_cartan_matrix(cartan_matrix(:C, 2); generalized=false) == true
@test is_cartan_matrix(cm) == true
@test is_cartan_matrix(cm; generalized=false) == true
end

@test is_cartan_matrix(cartan_matrix(:D, 4)) == true
@test is_cartan_matrix(cartan_matrix(:D, 4); generalized=false) == true
test_is_cartan_matrix_finite_type(cartan_matrix(:A, 1))
test_is_cartan_matrix_finite_type(cartan_matrix(:A, 3))
test_is_cartan_matrix_finite_type(cartan_matrix(:B, 4))
test_is_cartan_matrix_finite_type(cartan_matrix(:C, 2))
test_is_cartan_matrix_finite_type(cartan_matrix(:D, 5))
test_is_cartan_matrix_finite_type(cartan_matrix(:E, 6))
test_is_cartan_matrix_finite_type(cartan_matrix(:E, 7))
test_is_cartan_matrix_finite_type(cartan_matrix(:E, 8))
test_is_cartan_matrix_finite_type(cartan_matrix(:F, 4))
test_is_cartan_matrix_finite_type(cartan_matrix(:G, 2))

@test is_cartan_matrix(cartan_matrix(:G, 2)) == true
@test is_cartan_matrix(cartan_matrix(:G, 2); generalized=false) == true
test_is_cartan_matrix_finite_type(cartan_matrix((:A, 3), (:C, 3), (:E, 6), (:G, 2)))
test_is_cartan_matrix_finite_type(cartan_matrix((:F, 4), (:B, 2), (:E, 7), (:G, 2)))

# test affine type
@test is_cartan_matrix(ZZ[2 -2; -2 2]) == true
Expand All @@ -63,34 +88,24 @@
@test is_cartan_matrix(ZZ[2 -1 -1; -1 2 -1; -1 -1 2]; generalized=false) == false
end

@testset "cartan_symmetrizer(gcm::ZZMatrix; check::Bool)" begin
@testset "cartan_symmetrizer" begin
# cartan_symmetrizer function is indirectly covered by the cartan_bilinear_form tests
# here we simply guarantee that the choice of the symmetrizer is as expected

# finite type
@test cartan_symmetrizer(cartan_matrix(:A, 1)) == [1]
@test cartan_symmetrizer(cartan_matrix(:A, 2)) == [1, 1]

@test cartan_symmetrizer(cartan_matrix(:B, 2)) == [2, 1]
@test cartan_symmetrizer(cartan_matrix(:B, 4)) == [2, 2, 2, 1]

@test cartan_symmetrizer(cartan_matrix(:C, 2)) == [1, 2]
@test cartan_symmetrizer(cartan_matrix(:C, 4)) == [1, 1, 1, 2]

@test cartan_symmetrizer(cartan_matrix(:D, 4)) == [1, 1, 1, 1]

@test cartan_symmetrizer(cartan_matrix(:E, 6)) == [1, 1, 1, 1, 1, 1]
@test cartan_symmetrizer(cartan_matrix(:E, 7)) == [1, 1, 1, 1, 1, 1, 1]
@test cartan_symmetrizer(cartan_matrix(:E, 8)) == [1, 1, 1, 1, 1, 1, 1, 1]

@test cartan_symmetrizer(cartan_matrix(:F, 4)) == [2, 2, 1, 1]
@test cartan_symmetrizer(cartan_matrix(:G, 2)) == [1, 3]

@test cartan_symmetrizer(cartan_matrix((:A, 3), (:B, 3))) == [[1, 1, 1]; [2, 2, 1]]
@test cartan_symmetrizer(cartan_matrix((:F, 4), (:D, 4))) ==
[[2, 2, 1, 1]; [1, 1, 1, 1]]
@test cartan_symmetrizer(cartan_matrix((:C, 4), (:G, 2))) == [[1, 1, 1, 2]; [1, 3]]

@test cartan_symmetrizer(ZZ[2 -2 0; -1 2 -1; 0 -1 2]) == [1, 2, 2]
@test cartan_symmetrizer(ZZ[2 0 -1 0; 0 2 0 -2; -2 0 2 0; 0 -1 0 2]) == [2, 1, 1, 2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are still indirectly tested via the bilinear form test below, right?


# affine type
@test cartan_symmetrizer(ZZ[2 -2; -2 2]) == [1, 1] # A1~1
@test cartan_symmetrizer(ZZ[2 -2 0; -1 2 -1; 0 -2 2]) == [1, 2, 1] # D3~2
Expand All @@ -100,20 +115,37 @@
@test cartan_symmetrizer(ZZ[2 -2; -3 2]) == [3, 2]
end

@testset "cartan_bilinear_form(gcm::ZZMatrix; check::Bool)" begin
# finite type
@test cartan_bilinear_form(cartan_matrix(:A, 2)) == ZZ[2 -1; -1 2]
@test cartan_bilinear_form(cartan_matrix(:B, 4)) ==
ZZ[4 -2 0 0; -2 4 -2 0; 0 -2 4 -2; 0 0 -2 2]
@test cartan_bilinear_form(cartan_matrix(:C, 4)) ==
ZZ[2 -1 0 0; -1 2 -1 0; 0 -1 2 -2; 0 0 -2 4]
@test cartan_bilinear_form(cartan_matrix(:F, 4)) ==
ZZ[4 -2 0 0; -2 4 -2 0; 0 -2 2 -1; 0 0 -1 2]
@test cartan_bilinear_form(cartan_matrix(:G, 2)) == ZZ[2 -3; -3 6]

@test cartan_bilinear_form(cartan_matrix((:B, 2), (:A, 1))) == ZZ[4 -2 0; -2 2 0; 0 0 2]
@test cartan_bilinear_form(ZZ[2 0 -1 0; 0 2 0 -2; -2 0 2 0; 0 -1 0 2]) ==
ZZ[4 0 -2 0; 0 2 0 -2; -2 0 2 0; 0 -2 0 4]
@testset "cartan_bilinear_form" begin
function test_cartan_bilinear_form(cm::ZZMatrix)
rk = nrows(cm)
for _ in 1:50
i, j = rand(1:rk, 2)
if i != j
swap_rows!(cm, i, j)
swap_cols!(cm, i, j)
end
end

bil = cartan_bilinear_form(cm)
@test is_symmetric(bil) == true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test is_symmetric(bil) == true
@test is_symmetric(bil)

@test all(cm[i, j] == div(2 * bil[i, j], bil[i, i]) for i in 1:rk, j in 1:rk)
end

# irreducible matrices
test_cartan_bilinear_form(cartan_matrix(:A, 1))
test_cartan_bilinear_form(cartan_matrix(:A, 3))
test_cartan_bilinear_form(cartan_matrix(:B, 4))
test_cartan_bilinear_form(cartan_matrix(:C, 2))
test_cartan_bilinear_form(cartan_matrix(:D, 5))
test_cartan_bilinear_form(cartan_matrix(:E, 6))
test_cartan_bilinear_form(cartan_matrix(:E, 7))
test_cartan_bilinear_form(cartan_matrix(:E, 8))
test_cartan_bilinear_form(cartan_matrix(:F, 4))
test_cartan_bilinear_form(cartan_matrix(:G, 2))

# reducible matrices
test_cartan_bilinear_form(cartan_matrix((:A, 3), (:C, 3), (:E, 6), (:G, 2)))
test_cartan_bilinear_form(cartan_matrix((:F, 4), (:B, 2), (:E, 7), (:G, 2)))

# affine type
@test cartan_bilinear_form(ZZ[2 -2; -2 2]) == ZZ[2 -2; -2 2]
Expand Down
Loading