Commit b9141834 authored by William F Godoy's avatar William F Godoy
Browse files

Adding test

parent bf05d689
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
name = "Exio" name = "Exio"
uuid = "0525473d-17b7-4fd3-beb1-bf17216ddbac" uuid = "0525473d-17b7-4fd3-beb1-bf17216ddbac"
version = "0.0.1" version = "0.0.1"
[deps]
Test
Filesystem
[compat] [compat]
julia = "1" julia = "1"
...@@ -12,3 +17,5 @@ Test = "eaa6fafa-8011-46e2-b288-c2f1e2a8ee56" ...@@ -12,3 +17,5 @@ Test = "eaa6fafa-8011-46e2-b288-c2f1e2a8ee56"
test = ["Test"] test = ["Test"]
# jexio # jexio
Run tests:
`> julia --project=. test/runtests.jl`
module Exio module Exio
export ExioH, exio_init export ExioH, exio_init, input_parser
include("extractor/extractor.jl") include("extractor/extractor.jl")
...@@ -11,13 +11,13 @@ mutable struct ExioH ...@@ -11,13 +11,13 @@ mutable struct ExioH
end end
function exio_init(app::String, outputPrefix::String) function exio_init(app::String, outputPrefix::String)::ExioH
exioH = ExioH() exioH = ExioH()
if app == "AmrexCastro" if app == "AmrexCastro"
println("Hello AmrexCastro") println("Hello AmrexCastro")
exioH.extractor = AmrexCastro() exioH.extractor = AmrexCastro()
init(exioH.extractor, outputPrefix) init!(exioH.extractor, outputPrefix)
end end
return exioH return exioH
......
...@@ -9,7 +9,13 @@ mutable struct Amrex <: AbstractAmrex ...@@ -9,7 +9,13 @@ mutable struct Amrex <: AbstractAmrex
Amrex() = new() Amrex() = new()
end end
function init(extractor::Amrex, outputPrefix::String) """
initialize members of the extractor::Amrex type
Using bang convention as init modifies the extractor::Amrex
https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
"""
function init!(extractor::Amrex, outputPrefix::String)
extractor.app = "Amrex" extractor.app = "Amrex"
extractor.outputPrefix = outputPrefix extractor.outputPrefix = outputPrefix
extractor.degreesOfFreedom = [ extractor.degreesOfFreedom = [
...@@ -21,12 +27,39 @@ function init(extractor::Amrex, outputPrefix::String) ...@@ -21,12 +27,39 @@ function init(extractor::Amrex, outputPrefix::String)
] ]
end end
"""
Parses an input file with entries key = value, returns all entries in a Dict
# Arguments
- `extractor::AbstractAmrex` : input type extending AbstractAmrex
- `inputFile::String` : input file to be parsed, absolute path is preferred
"""
function input_parser(extractor::AbstractAmrex, inputFile::String)::Dict{String,String}
function input_parser(inputFile::String)
parameters = Dict{String,String}() parameters = Dict{String,String}()
# get file contents in a single iterable type, \n newline is removed
fileContents = readlines(inputFile) fileContents = readlines(inputFile)
print(fileContents) # go through each line
for line in fileContents
if isempty(line)
continue
end
# remove comments marked with #
result = findfirst("#", line)
if isnothing(result) == false
line = SubString(line, 1, result[1]-1)
if isempty(line)
continue
end
end
parameter = split(line,"=")
parameters[strip(parameter[1])] = strip(parameter[2])
end
return parameters
end end
\ No newline at end of file
...@@ -7,7 +7,13 @@ mutable struct AmrexCastro <: AbstractAmrex ...@@ -7,7 +7,13 @@ mutable struct AmrexCastro <: AbstractAmrex
AmrexCastro() = new() AmrexCastro() = new()
end end
function init(extractor::AmrexCastro, outputPrefix::String) """
init!
initialize members of the extractor::AmrexCastro type
Using bang convention as init modifies the extractor::Amrex
https://docs.julialang.org/en/v1/manual/style-guide/index.html#bang-convention-1
"""
function init!(extractor::AmrexCastro, outputPrefix::String)
extractor.app = "AmrexCastro" extractor.app = "AmrexCastro"
extractor.degreesOfFreedom = [ extractor.degreesOfFreedom = [
"max_step", "max_step",
......
using Test using Test, Base.Filesystem
import Exio import Exio
@testset "test_amrexCastro" begin @testset "test_amrexCastro" begin
include("test_amrexCastro.jl") include("test_amrexCastro.jl")
end; end;
@testset "test_Exio.input_parser_docstring" begin
@test println(@doc Exio.input_parser) === nothing
end;
...@@ -3,3 +3,30 @@ ...@@ -3,3 +3,30 @@
exio = Exio.exio_init("AmrexCastro", ".") exio = Exio.exio_init("AmrexCastro", ".")
@test typeof(exio) == Exio.ExioH @test typeof(exio) == Exio.ExioH
println("Current directory: ", Filesystem.pwd() )
inputFile = string(Filesystem.pwd(),"/test/data/amrexCastro/test_data_AmrexCastro_inputs.2d.cyl_in_cartcoords")
println( "Input file: ", inputFile )
parameters = Exio.input_parser(exio.extractor, inputFile)
# keys counter
n = 0
for parameter in parameters
key = parameter[1]
value = parameter[2]
if isequal(key, "amr.regrid_int") global n += 1; @test isequal(value, "2")
elseif isequal(key, "amr.plot_file") global n += 1; @test isequal(value,"sedov_2d_cyl_in_cart_plt")
elseif isequal(key, "amr.max_level") global n += 1; @test isequal(value, "2")
elseif isequal(key, "amr.plot_int") global n += 1; @test isequal(value, "20")
elseif isequal(key, "amr.n_cell") global n += 1; @test isequal(value, "16 16")
end
println(parameter[1], "...", parameter[2])
end
# @test n == 5
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment