Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Glasscat tests (#152)
Browse files Browse the repository at this point in the history
* remove old docstring function

* remove ambiguities and unbound_args tests

these should be covered in test/testsets/JuliaLang.jl

* using OpticSim.GlassCat

* export CARGILLE

* prettier isapprox tests

* prettier unitful usage

* Air.jl, GlassTypes.jl, search.jl testsets

* use exported variables directly

e.g. CARGILLE instead of GlassCat.CARGILLE

* glassnames() tests

* using Unitful.DefaultSymbols

* add wrappedallocs macro, fixing allocation test issues
  • Loading branch information
alfredclwong authored May 5, 2021
1 parent e0204ee commit bdefffe
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 217 deletions.
1 change: 1 addition & 0 deletions src/GlassCat/GlassCat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if !isfile(AGFGLASSCAT_PATH)
end
include("data/jl/AGFGlassCat.jl") # this needs to be literal for intellisense to work
include("data/jl/CARGILLE.jl")
export CARGILLE

# include functionality for managing runtime (dynamic) glass cats: MIL_GLASSES and MODEL_GLASSES
include("runtime.jl")
Expand Down
167 changes: 0 additions & 167 deletions src/GlassCat/GlassTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,170 +338,3 @@ function info(io::IO, glass::Glass)
end

info(g::AbstractGlass) = info(stdout, g)

function docstring(io::IO, glass::Glass)
D = glass.dispform

println(io, "**ID**$(glass.ID)\n")

if (D == -2)
println(io, "**Dispersion formula**Cauchy (-2)\n")
elseif (D == -1)
println(io, "**Dispersion formula**Fitted for model/MIL glass\n")
else
println(io, "**Dispersion formula**$(DISPFORM_NAMES[D]) ($D)\n")
end
println(io, "**Dispersion formula coefficients**\n")
println(io, "|Coefficient|Value|")
println(io, "|:----------|-----|")
if (D == -2) # Cauchy
println(io, "|A |$(glass.C1)|")
println(io, "|B |$(glass.C2)|")
println(io, "|C |$(glass.C3)|")
println(io, "|D |$(glass.C4)|")
println(io, "|E |$(glass.C5)|")
println(io, "|F |$(glass.C6)|")
elseif (D == -1)
println(io, "|C₀|$(glass.C1)|")
println(io, "|C₁|$(glass.C2)|")
println(io, "|C₂|$(glass.C3)|")
println(io, "|C₃|$(glass.C4)|")
elseif (D == 1) # Schott
println(io, "|a₀|$(glass.C1)|")
println(io, "|a₁|$(glass.C2)|")
println(io, "|a₂|$(glass.C3)|")
println(io, "|a₃|$(glass.C4)|")
println(io, "|a₄|$(glass.C5)|")
println(io, "|a₅|$(glass.C6)|")
elseif (D == 2) # Sellmeier1
println(io, "|K₁|$(glass.C1)|")
println(io, "|L₁|$(glass.C2)|")
println(io, "|K₂|$(glass.C3)|")
println(io, "|L₂|$(glass.C4)|")
println(io, "|K₃|$(glass.C5)|")
println(io, "|L₃|$(glass.C6)|")
elseif (D == 3) # Herzberger
println(io, "|A |$(glass.C1)|")
println(io, "|B |$(glass.C2)|")
println(io, "|C |$(glass.C3)|")
println(io, "|D |$(glass.C4)|")
println(io, "|E |$(glass.C5)|")
println(io, "|F |$(glass.C6)|")
elseif (D == 4) # Sellmeier2
println(io, "|A |$(glass.C1)|")
println(io, "|B₁|$(glass.C2)|")
println(io, "|λ₁|$(glass.C3)|")
println(io, "|B₂|$(glass.C4)|")
println(io, "|λ₂|$(glass.C5)|")
elseif (D == 5) # Conrady
println(io, "|n₀|$(glass.C1)|")
println(io, "|A |$(glass.C2)|")
println(io, "|B |$(glass.C3)|")
elseif (D == 6) # Sellmeier3
println(io, "|K₁|$(glass.C1)|")
println(io, "|L₁|$(glass.C2)|")
println(io, "|K₂|$(glass.C3)|")
println(io, "|L₂|$(glass.C4)|")
println(io, "|K₃|$(glass.C5)|")
println(io, "|L₃|$(glass.C6)|")
println(io, "|K₄|$(glass.C7)|")
println(io, "|L₄|$(glass.C8)|")
elseif (D == 7) || (D == 8) # HandbookOfOptics1/2
println(io, "|A |$(glass.C1)|")
println(io, "|B |$(glass.C2)|")
println(io, "|C |$(glass.C3)|")
println(io, "|D |$(glass.C4)|")
elseif (D == 9) # Sellmeier4
println(io, "|A |$(glass.C1)|")
println(io, "|B |$(glass.C2)|")
println(io, "|C |$(glass.C3)|")
println(io, "|D |$(glass.C4)|")
println(io, "|E |$(glass.C5)|")
elseif (D == 10) || (D == 12) # Extended1/2
println(io, "|a₀|$(glass.C1)|")
println(io, "|a₁|$(glass.C2)|")
println(io, "|a₂|$(glass.C3)|")
println(io, "|a₃|$(glass.C4)|")
println(io, "|a₄|$(glass.C5)|")
println(io, "|a₅|$(glass.C6)|")
println(io, "|a₆|$(glass.C7)|")
println(io, "|a₇|$(glass.C8)|")
elseif (D == 11) # Sellmeier5
println(io, "|K₁|$(glass.C1)|")
println(io, "|L₁|$(glass.C2)|")
println(io, "|K₂|$(glass.C3)|")
println(io, "|L₂|$(glass.C4)|")
println(io, "|K₃|$(glass.C5)|")
println(io, "|L₃|$(glass.C6)|")
println(io, "|K₄|$(glass.C7)|")
println(io, "|L₄|$(glass.C8)|")
println(io, "|K₅|$(glass.C9)|")
println(io, "|L₅|$(glass.C10)|")
elseif (D == 13) # Extended3
println(io, "|a₀|$(glass.C1)|")
println(io, "|a₁|$(glass.C2)|")
println(io, "|a₂|$(glass.C3)|")
println(io, "|a₃|$(glass.C4)|")
println(io, "|a₄|$(glass.C5)|")
println(io, "|a₅|$(glass.C6)|")
println(io, "|a₆|$(glass.C7)|")
println(io, "|a₇|$(glass.C8)|")
println(io, "|a₈|$(glass.C9)|")
else
println(io, " INVALID DISPERSION FORMULA!!\n")
end
println(io)

println(io, "**Valid wavelengths**$(glass.λmin)μm to $(glass.λmax)μm\n")
println(io, "**Reference temperature**$(glass.temp)°C\n")

if !isnan(glass.D₀) && (glass.D₀ != 0 || glass.D₁ != 0 || glass.D₂ != 0 || glass.E₀ != 0 || glass.E₁ != 0)
println(io, "**Thermal ΔRI coefficients**\n")
println(io, "|Coefficient |Value |")
println(io, "|:---------------------------|-----------|")
println(io, "|D₀ |$(glass.D₀)|")
println(io, "|D₁ |$(glass.D₁)|")
println(io, "|D₂ |$(glass.D₂)|")
println(io, "|E₀ |$(glass.E₀)|")
println(io, "|E₁ |$(glass.E₁)|")
println(io, "|λₜₖ |$(glass.λₜₖ)|")
println(io)
end

println(io, "**TCE (÷1e-6)**$(glass.TCE)\n")
println(io, "**Ignore thermal expansion**$(glass.ignore_thermal_exp == 1)\n")

println(io, "**Density (p)**$(glass.p)g/m³\n")
println(io, "**ΔPgF**$(glass.ΔPgF)\n")

println(io, "**RI at sodium D-Line (587nm)**$(glass.Nd)\n")
println(io, "**Abbe Number**$(glass.Vd)\n")

println(io, "**Cost relative to N_BK7**$(glass.relcost == -1 ? "?" : glass.relcost)\n")

if glass.CR != -1 || glass.FR != -1 || glass.SR != -1 || glass.AR != -1 || glass.PR != -1
println(io, "**Environmental resistance**\n")
println(io, "|Environment |Resistance |")
println(io, "|:-------------|----------------------------------|")
println(io, "|Climate (CR) |$(glass.CR == -1 ? "?" : glass.CR)|")
println(io, "|Stain (FR) |$(glass.FR == -1 ? "?" : glass.FR)|")
println(io, "|Acid (SR) |$(glass.SR == -1 ? "?" : glass.SR)|")
println(io, "|Alkaline (AR) |$(glass.AR == -1 ? "?" : glass.AR)|")
println(io, "|Phosphate (PR)|$(glass.PR == -1 ? "?" : glass.PR)|")
println(io)
end

println(io, "**Status**$(STATUS[glass.status + 1]) ($(glass.status))\n")
println(io, "**Melt frequency**$(glass.meltfreq == -1 ? "?" : glass.meltfreq)\n")
println(io, "**Exclude substitution**$(glass.exclude_sub == 1)\n")

if glass.transmission !== nothing
println(io, "**Transmission data**\n")
println(io, "|Wavelength|Transmission|Thickness|")
println(io, "|----------|------------|---------|")
for i in 1:(glass.transmissionN)
λ, t, τ = glass.transmission[i]
println(io, "|$(λ)μm|$t|$(τ)mm|")
end
end
end
32 changes: 32 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ macro test_all_no_arg_functions(m)
end
end

"""
@wrappedallocs(expr)
https://github.com/JuliaAlgebra/TypedPolynomials.jl/blob/master/test/runtests.jl
Given an expression, this macro wraps that expression inside a new function
which will evaluate that expression and measure the amount of memory allocated
by the expression. Wrapping the expression in a new function allows for more
accurate memory allocation detection when using global variables (e.g. when
at the REPL).
For example, `@wrappedallocs(x + y)` produces:
```julia
function g(x1, x2)
@allocated x1 + x2
end
g(x, y)
```
You can use this macro in a unit test to verify that a function does not
allocate:
```
@test @wrappedallocs(x + y) == 0
```
"""
macro wrappedallocs(expr)
argnames = [gensym() for a in expr.args]
quote
function g($(argnames...))
@allocated $(Expr(expr.head, argnames...))
end
$(Expr(:call, :g, [esc(a) for a in expr.args]...))
end
end

include("Benchmarks/Benchmarks.jl")

alltestsets = [
Expand Down
Loading

0 comments on commit bdefffe

Please sign in to comment.