Files
JuliaFEM.jl/test/runtests.jl
T

142 lines
3.6 KiB
Julia
Raw Normal View History

2015-05-25 22:39:30 +03:00
using JuliaFEM
using Base.Test
2015-06-20 22:14:04 +03:00
using Logging
2015-06-20 23:30:33 +03:00
@Logging.configure(level=DEBUG)
2015-06-20 15:32:57 +03:00
function test_create_model()
m = new_model()
fn = fieldnames(m)
2015-06-20 16:43:45 +03:00
@test :model in fn
@test :nodes in fn
@test :elements in fn
@test :element_nodes in fn
@test :element_gauss_points in fn
2015-06-20 15:32:57 +03:00
end
2015-06-20 16:43:45 +03:00
test_create_model()
2015-05-20 20:34:37 +03:00
2015-06-20 15:57:23 +03:00
function test_add_field()
m = new_model()
field = new_field(m.elements, "color")
2015-06-20 16:43:45 +03:00
@test "color" in keys(m.elements)
2015-06-20 15:57:23 +03:00
end
2015-06-20 16:43:45 +03:00
test_add_field()
2015-06-20 15:57:23 +03:00
2015-06-20 15:57:23 +03:00
function test_get_field()
m = new_model()
field = new_field(m.elements, "color")
field[1] = "red" # set element 1 field value to "red"
field2 = get_field(m.elements, "color") # get color field
2015-06-20 16:43:45 +03:00
@test field2[1] == "red"
2015-06-20 15:57:23 +03:00
end
2015-06-20 16:43:45 +03:00
test_get_field()
2015-06-20 15:57:23 +03:00
2015-06-20 15:57:23 +03:00
function test_get_field_if_it_doesnt_exist()
m = new_model()
# FIXME: how to test exception?
# @assert "throw error when" field = get_field(m.elements, "temperature")
field = get_field(m.elements, "temperature"; create_if_doesnt_exist=true)
field[1] = 173
field2 = get_field(m.elements, "temperature")
2015-06-20 16:43:45 +03:00
@test field2[1] == 173
2015-06-20 15:57:23 +03:00
end
2015-06-20 16:43:45 +03:00
test_get_field_if_it_doesnt_exist()
2015-06-20 15:57:23 +03:00
2015-06-20 21:38:10 +03:00
function test_get_field_throw_exception()
m = new_model()
@test_throws ASCIIString get_field(m.elements, "temperature")
end
test_get_field_throw_exception()
2015-06-20 15:57:23 +03:00
function test_add_and_get_nodes()
m = new_model()
nodes = Dict(1 => [0.0, 0.0, 0.0],
2 => [1.0, 0.0, 0.0],
3 => [0.0, 1.0, 0.0],
4 => [0.0, 0.0, 1.0])
add_nodes(m, nodes)
subset = get_nodes(m, [2, 3])
2015-06-20 16:43:45 +03:00
@test length(subset) == 2
@test subset[2] == [1.0, 0.0, 0.0]
@test subset[3] == [0.0, 1.0, 0.0]
end
2015-06-20 16:43:45 +03:00
test_add_and_get_nodes()
2015-06-20 20:26:18 +03:00
2015-06-20 19:56:36 +03:00
function test_print()
lines_with_print = Dict()
2015-06-20 20:30:33 +03:00
#src = readdir("/src")
2015-06-20 21:38:10 +03:00
#src_dir = "/home/travis/build/ovainola/JuliaFEM/src"
src_dir = "../src"
2015-06-20 20:36:26 +03:00
src = readdir(src_dir)
2015-06-20 19:56:36 +03:00
for file_name in src
2015-06-20 20:41:19 +03:00
fil = open(joinpath(src_dir,file_name),"r")
2015-06-20 19:56:36 +03:00
for line in readlines(fil)
if ismatch(r"print",line)
lines_with_print[file_name] = "print"
end
end
close(fil)
end
2015-06-20 20:44:49 +03:00
#@test lines_with_print == Dict()
2015-06-20 23:30:33 +03:00
@debug("number of lines with print = ", length(lines_with_print))
@debug(lines_with_print)
2015-06-20 20:44:49 +03:00
@test length(lines_with_print) == 0
2015-06-20 19:56:36 +03:00
end
test_print()
2015-06-20 20:26:18 +03:00
function test_add_element()
m = new_model()
nodes = Dict(1 => [0.0, 0.0, 0.0],
2 => [1.0, 0.0, 0.0],
3 => [0.0, 1.0, 0.0],
4 => [0.0, 0.0, 1.0])
add_nodes(m, nodes)
el1 = Dict("element_type" => 0x6, "node_ids" => [1, 2, 3, 4])
el2 = Dict("element_type" => 0x6, "node_ids" => [4, 3, 2, 1])
elements = Dict(1 => el1, 2 => el2)
add_elements(m, elements)
2015-06-20 23:30:33 +03:00
@debug(m)
@test m.elements["element_type"][1] == 0x6
@test m.elements["connectivity"][1] == [1, 2, 3, 4]
end
test_add_element()
function test_get_element()
m = new_model()
nodes = Dict(1 => [0.0, 0.0, 0.0],
2 => [1.0, 0.0, 0.0],
3 => [0.0, 1.0, 0.0],
4 => [0.0, 0.0, 1.0])
add_nodes(m, nodes)
el1 = Dict("element_type" => 0x6, "node_ids" => [1, 2, 3, 4])
el2 = Dict("element_type" => 0x6, "node_ids" => [4, 3, 2, 1])
elements = Dict(1 => el1, 2 => el2)
#println(elements)
add_elements(m, elements)
#println(m)
# get elements by element id
els = get_elements(m, [1])
#println(els)
@test length(els) == 1
@test 1 in keys(els)
@test els[1]["element_type"] == 0x6
@test els[1]["node_ids"] == [1, 2, 3, 4]
end
test_get_element()
2015-06-20 21:51:50 +03:00
include("test_xdmf.jl")
2015-06-21 00:02:15 +03:00
include("solver_tests/test_elasticity_solver.jl")
2015-06-20 21:47:54 +03:00
2015-06-20 15:32:57 +03:00
# write your own tests here
# @test 1 == JuliaFEM.test()
# @test_approx_eq 1.0 1.0