Skip to content

Commit

Permalink
Merge pull request #185 from singularitti:singularitti/issue183
Browse files Browse the repository at this point in the history
Add tests to `get_error_code`
  • Loading branch information
singularitti authored Jan 24, 2024
2 parents d960275 + 4b46299 commit b5d4e3f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
38 changes: 38 additions & 0 deletions test/error.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ using Test
include("reciprocal.jl")
include("reduce.jl")
include("symmetry.jl")
include("error.jl")
end
4 changes: 3 additions & 1 deletion test/standardize.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit b5d4e3f

Please sign in to comment.