diff --git a/test/error.jl b/test/error.jl new file mode 100644 index 0000000..17d69ac --- /dev/null +++ b/test/error.jl @@ -0,0 +1,38 @@ +using Spglib: + SUCCESS, + SPACEGROUP_SEARCH_FAILED, + NIGGLI_FAILED, + DELAUNAY_FAILED, + CELL_STANDARDIZATION_FAILED, + ATOMS_TOO_CLOSE, + get_error_code + +@testset "Test when no error occurs" begin + lattice = [[0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]] * 5.4 + positions = [[0.875, 0.875, 0.875], [0.125, 0.125, 0.125]] + atoms = [1, 1] + cell = Cell(lattice, positions, atoms) + get_dataset(cell, 1e-5) + @test get_error_code() == SUCCESS +end + +@testset "Test error types" begin + lattice = Lattice([[0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]] * 5.4) + positions = [[0.875, 0.875, 0.875], [0.125, 0.125, 0.125]] + atoms = [1, 1] + cell = Cell(lattice, positions, atoms) + @test_throws SpglibError get_dataset(cell, 1e-5) + @test get_error_code() == SPACEGROUP_SEARCH_FAILED + @test_throws SpglibError niggli_reduce(cell, 1e-5) + @test get_error_code() == NIGGLI_FAILED + @test_throws SpglibError delaunay_reduce(cell, 1e-5) + @test get_error_code() == DELAUNAY_FAILED + @test_throws SpglibError standardize_cell(cell, 1e-5) + @test get_error_code() == CELL_STANDARDIZATION_FAILED + @testset "Test when atoms are too close" begin + positions = [[0.875, 0.875, 0.875], [0.875 + eps(), 0.875, 0.875]] + cell = Cell(lattice, positions, atoms) + @test_throws SpglibError get_dataset(cell, 1e-5) + @test get_error_code() == ATOMS_TOO_CLOSE + end +end diff --git a/test/runtests.jl b/test/runtests.jl index cac61c1..a4e6622 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,4 +9,5 @@ using Test include("reciprocal.jl") include("reduce.jl") include("symmetry.jl") + include("error.jl") end diff --git a/test/standardize.jl b/test/standardize.jl index a18bb3e..5659ff6 100644 --- a/test/standardize.jl +++ b/test/standardize.jl @@ -1,4 +1,4 @@ -using Spglib: SpglibError +using Spglib: SPACEGROUP_SEARCH_FAILED, SpglibError, get_error_code # This example is from https://spglib.github.io/spglib/definition.html#transformation-to-a-primitive-cell @testset "Transformation to a primitive cell" begin @@ -147,5 +147,7 @@ end atoms = ["Na", "Na", "Cl"] cell = Cell(lattice, positions, atoms) @test_throws SpglibError find_primitive(cell) + @test get_error_code() == SPACEGROUP_SEARCH_FAILED @test_throws SpglibError standardize_cell(cell, to_primitive=true) + @test get_error_code() == SPACEGROUP_SEARCH_FAILED end