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

Add tests to get_error_code #185

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
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
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
Loading