Skip to content

Commit

Permalink
replace hand made tests with @test_throws
Browse files Browse the repository at this point in the history
  • Loading branch information
iintSjds committed Apr 6, 2023
1 parent facb75c commit 6d69025
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 46 deletions.
38 changes: 14 additions & 24 deletions test/AbstractMeshes.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
@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
Expand Down Expand Up @@ -38,24 +28,24 @@
# 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_throws ErrorException 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_throws ErrorException notamesh[1]
@test_throws ErrorException notamesh[1, 2, 3]
@test_throws ErrorException notamesh[FracCoords, 1]
@test_throws ErrorException notamesh[FracCoords, 1, 2, 3]

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_throws ErrorException locate(notamesh, 1)
@test_throws ErrorException volume(notamesh, 1)
@test_throws ErrorException 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_throws ErrorException lattice_vector(notamesh)
@test_throws ErrorException inv_lattice_vector(notamesh)
@test_throws ErrorException cell_volume(notamesh)

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

test_func_not_implemented(x -> interval(x, 1), notamesh)
@test_throws ErrorException interval(notamesh, 1)

end
12 changes: 1 addition & 11 deletions test/BaseMesh.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
@testset "Base Mesh" begin
rng = MersenneTwister(1234)

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

@testset "UMesh" begin
DIM = 2
N1, N2 = 3, 5
Expand Down Expand Up @@ -49,7 +39,7 @@

# basics
struct NotAPM{T,DIM} <: BaseMesh.AbstractProdMesh{T,DIM} end
test_func_not_implemented(x -> BaseMesh._getgrid(x, 1), NotAPM{Int,3}())
@test_throws ErrorException BaseMesh._getgrid(NotAPM{Int,3}(), 1)

@testset "DirectProdMesh" begin
N, M = 3, 2
Expand Down
12 changes: 1 addition & 11 deletions test/MeshMap.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
@testset "MeshMaps" begin

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

locate, volume = MeshMaps.locate, MeshMaps.volume

@testset "MeshMap" begin

struct NotAMesh{T,DIM} <: AbstractMesh{T,DIM} end
notamesh = NotAMesh{Float64,3}()
test_func_not_implemented(MeshMap, notamesh)
@test_throws ErrorException MeshMap(notamesh)

# test MeshMap constructor
map = [1, 2, 2, 1, 2, 6, 6, 2, 2, 6, 6, 2, 1, 2, 2, 1]
Expand Down

0 comments on commit 6d69025

Please # to comment.