Skip to content

Commit

Permalink
Merge pull request #74 from numericalEFT/dev-tests
Browse files Browse the repository at this point in the history
Dev tests
  • Loading branch information
iintSjds authored Mar 24, 2023
2 parents 2693116 + 81d8389 commit 5832c2a
Show file tree
Hide file tree
Showing 11 changed files with 554 additions and 422 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ deps/src/
docs/build/
docs/site/
/run/
/coverage/

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/BZMeshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ function MeshMaps.MeshMap(mesh::UniformBZMesh{T,DIM},
return MeshMaps.MeshMap(new_map)
end

# temporarily hide wip codes
include("PolarMeshes.jl")

end
2 changes: 1 addition & 1 deletion src/BrillouinZoneMeshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export AbstractUniformMesh

include("CompositeMeshes.jl")
using .CompositeMeshes
export CompositeMeshes
# export CompositeMeshes

# include("TreeMeshes.jl")
# using .TreeMeshes
Expand Down
61 changes: 61 additions & 0 deletions test/AbstractMeshes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@testset "AbstractMeshes" begin
using BrillouinZoneMeshes.AbstractMeshes

function test_func_not_implemented(func, obj)
# if a func required is not implemented for obj
# an error occur
try
func(obj)
catch e
@test e isa ErrorException
end
end

# create a random concrete mesh
DIM = 2
N1, N2 = 3, 5
lattice = Matrix([1/N1/2 0; 0 1.0/N2/2]') .* 2π
cell = BZMeshes.Cell(lattice=lattice)
mesh = BaseMesh.UMesh(br=cell, origin=ones(DIM) ./ 2, size=(N1, N2), shift=zeros(DIM))

# type
@test eltype(mesh) == BrillouinZoneMeshes.SVector{Float64,DIM}

# size
@test length(mesh) == N1 * N2
@test size(mesh) == (N1, N2)
@test size(mesh, 1) == N1
@test ndims(mesh) == DIM

# indexing
@test mesh[end] == mesh[length(mesh)]
@test mesh[begin] == mesh[1]

# tools
@test AbstractMeshes._inds2ind(size(mesh), (2, 2)) == 5
@test AbstractMeshes._ind2inds(size(mesh), 5) == [2, 2]

# test error thrown from funcs not implemented
struct NotAMesh{T,DIM} <: AbstractMesh{T,DIM} end
notamesh = NotAMesh{Float64,3}()
test_func_not_implemented(println, notamesh)

test_func_not_implemented(x -> getindex(x, 1), notamesh)
test_func_not_implemented(x -> getindex(x, 1, 2, 3), notamesh)
test_func_not_implemented(x -> getindex(x, FracCoords, 1), notamesh)
test_func_not_implemented(x -> getindex(x, FracCoords, 1, 2, 3), notamesh)

test_func_not_implemented(x -> locate(x, 1), notamesh)
test_func_not_implemented(x -> volume(x, 1), notamesh)
test_func_not_implemented(volume, notamesh)

test_func_not_implemented(lattice_vector, notamesh)
test_func_not_implemented(inv_lattice_vector, notamesh)
test_func_not_implemented(cell_volume, notamesh)

test_func_not_implemented(x -> integrate([1,], x), notamesh)
test_func_not_implemented(x -> interp([1,], x, 1), notamesh)

test_func_not_implemented(x -> interval(x, 1), notamesh)

end
Loading

0 comments on commit 5832c2a

Please # to comment.