Skip to content

Commit

Permalink
add some tests to cell operations
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiq committed May 14, 2024
1 parent ddf1558 commit 6c9532b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/CellOperations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ julia> wrap_to_first(x,unit_cell_matrix)
return unit_cell_matrix * p
end

@testitem "wrap_to_first" begin
x = [15.0, 13.0]
unit_cell_matrix = [10.0 0.0; 0.0 10.0]
@test CellListMap.wrap_to_first(x, unit_cell_matrix) [5.0, 3.0]
end

#=
wrap_relative_to(x, xref, unit_cell_matrix::SMatrix{N,N,T}) where {N,T}
Expand Down Expand Up @@ -102,6 +108,23 @@ for an Orthorhombic cell of which only the side lengths are provided.
return xw + xref
end

@testitem "wrap_relative_to" begin
using StaticArrays
using Unitful
x = [15.0, 13.0]
y = [4.0, 2.0]
unit_cell_matrix = SMatrix{2,2}(10.0, 0.0, 0.0, 10.0)
@test CellListMap.wrap_relative_to(x, y, unit_cell_matrix) [5.0, 3.0]
unit_cell_matrix = [10.0, 10.0]
@test CellListMap.wrap_relative_to(x, y, unit_cell_matrix) [5.0, 3.0]
x = [15.0, 13.0]u"nm"
y = [4.0, 2.0]u"nm"
unit_cell_matrix = SMatrix{2,2}(10.0, 0.0, 0.0, 10.0)u"nm"
@test CellListMap.wrap_relative_to(x, y, unit_cell_matrix) [5.0, 3.0]u"nm"
unit_cell_matrix = [10.0, 10.0]u"nm"
@test CellListMap.wrap_relative_to(x, y, unit_cell_matrix) [5.0, 3.0]u"nm"
end

#
# Wrap a single coordinate
#
Expand Down Expand Up @@ -158,6 +181,17 @@ function translation_image(x::AbstractVector{<:AbstractVector}, unit_cell_matrix
return x_new
end

@testitem "translation image" begin
using StaticArrays
x = SVector{2}[ [1.0, 1.0], [2.0, 2.0], [3.0, 3.0] ]
unitcell = [10.0 0.0 ; 0.0 10.0]
@test CellListMap.translation_image(x, unitcell, [0, 0]) [ [1.0, 1.0], [2.0, 2.0], [3.0, 3.0] ]
@test CellListMap.translation_image(x, unitcell, [1, 1]) [ [11.0, 11.0], [12.0, 12.0], [13.0, 13.0] ]
@test CellListMap.translation_image(x, unitcell, [1, 2]) [ [11.0, 21.0], [12.0, 22.0], [13.0, 23.0] ]
@test CellListMap.translation_image(x, unitcell, [2, 1]) [ [21.0, 11.0], [22.0, 12.0], [23.0, 13.0] ]
@test CellListMap.translation_image(x, unitcell, [-1, -1]) [ [-9.0, -9.0], [-8.0, -8.0], [-7.0, -7.0] ]
end

#=
replicate_system!(
x::AbstractVector{SVector{N,T}},
Expand Down

0 comments on commit 6c9532b

Please sign in to comment.