mirror of
https://github.com/Cian-H/nanoconc.git
synced 2025-12-22 14:12:00 +00:00
Added type stability tests for bhmie
This commit is contained in:
@@ -13,7 +13,6 @@ codebases=("bhmie-f.zip" "bhmie-c.zip")
|
||||
# if bhmie_dir containers bhmie-c/bhmie.so, bhmie-f/bhmie.so, and bhmie-f/bhmie_f77.so then we can skip the build
|
||||
bhmie_dir=$1
|
||||
if [ -f $bhmie_dir/bhmie-c/bhmie.so ] && [ -f $bhmie_dir/bhmie-f/bhmie.so ] && [ -f $bhmie_dir/bhmie-f/bhmie_f77.so ]; then
|
||||
echo "FFI shared objects already exist. Skipping build."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
@@ -125,15 +125,26 @@ function FFIWraps.bhmie_c(
|
||||
return result
|
||||
end
|
||||
|
||||
@testset "miemfp" begin
|
||||
@testset "miemfp.bhmie" begin
|
||||
@testset "bhmie" begin
|
||||
@testset "Properties vs ffi" begin
|
||||
event1, event2 = py"asyncio.Event"(), py"asyncio.Event"()
|
||||
event1.set(), event2.set()
|
||||
result, output = py"compare_bhmie_functions"(miemfp.bhmie, FFIWraps.bhmie_fortran, event1, event2)
|
||||
@test result
|
||||
TestUtils.@namedtest "Fortran" result
|
||||
result, output = py"compare_bhmie_functions"(miemfp.bhmie, FFIWraps.bhmie_fortran77, event1, event2)
|
||||
@test result
|
||||
TestUtils.@namedtest "FORTRAN77" result
|
||||
result, output = py"compare_bhmie_functions"(miemfp.bhmie, FFIWraps.bhmie_c, event1, event2)
|
||||
@test result
|
||||
TestUtils.@namedtest "C" result
|
||||
end
|
||||
@testset "Type stability" begin
|
||||
expected_return_type = Tuple{Float64,Float64,Float64,Array{ComplexF64,1},Array{ComplexF64,1}}
|
||||
x = 1.0
|
||||
cxref = 1.0 + 1.0im
|
||||
nang = 2
|
||||
s1 = [1.0 + 1.0im for _ in 1:nang]
|
||||
s2 = [1.0 + 1.0im for _ in 1:nang]
|
||||
out = @inferred(miemfp.bhmie(x, cxref, nang, s1, s2))
|
||||
@test typeof(out) === expected_return_type # Check that inferred type is correct
|
||||
@test out == miemfp.bhmie(x, cxref, nang, s1, s2) # Check that inferred result matches actual result
|
||||
end
|
||||
end
|
||||
@@ -31,7 +31,7 @@ def compare_bhmie_functions(
|
||||
@settings(deadline=None)
|
||||
@given(
|
||||
# Must be bigger than an atom but still nanoscale
|
||||
x=st.floats(min_value=0.1, max_value=100),
|
||||
x=st.floats(min_value=0.1, max_value=500), # max_value > 500 cannot reliably run on C FFI (may need to remove C check in the future)
|
||||
# Refractive indeces must be within a physically reasonable range
|
||||
cxref=st.tuples(
|
||||
st.floats(min_value=0.1, max_value=4.0),
|
||||
|
||||
@@ -7,7 +7,7 @@ include("../src/nanoconc.jl")
|
||||
TestUtils.init_pyenv()
|
||||
|
||||
# include("nanoconc_tests.jl")
|
||||
TestUtils.singleton_include("miemfp_tests.jl", :miemfp, @__MODULE__)
|
||||
@testset "miemfp" include("miemfp_tests.jl")
|
||||
# include("quantumcalc_tests.jl")
|
||||
TestUtils.singleton_include("benchmarks.jl", :Benchmarks, @__MODULE__)
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ function init_pyenv()
|
||||
end
|
||||
end
|
||||
|
||||
macro namedtest(name, test)
|
||||
esc(:(@testset $name begin @test $test end))
|
||||
end
|
||||
export namedtest
|
||||
|
||||
function fieldvalues(obj)
|
||||
[getfield(obj, f) for f in fieldnames(typeof(obj))]
|
||||
|
||||
Reference in New Issue
Block a user