From c7a5d44899a032e9474b34df20379437c75b92cb Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlsson <cont-frb@ulund.org> Date: Sat, 5 Sep 2015 13:58:21 +0200 Subject: [PATCH] Added several tests --- test/tests.jl | 77 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/test/tests.jl b/test/tests.jl index c7b64cb..b769bdc 100644 --- a/test/tests.jl +++ b/test/tests.jl @@ -1,15 +1,78 @@ module SystemIdentificationTests -export run_tests() +export run_tests using SystemIdentification + +macro test(text,x) + + return :(begin + global success = 0 + global fail = 0 + print("Testing ",$text, ": ") + try + $x + if fail == 0 + print_with_color(:green, "Success: $success\n") + else + print_with_color(:green, "Success: $success, ") + print_with_color(:red, "Failed: $fail\n") + end + catch ex + print_with_color(:red, "Failed: ") + print(ex, "\n") + end + end) +end + +macro tassert(x) + return :(begin + try + @assert $x + success += 1 + catch ex + if isa(ex,AssertionError) + print_with_color(:red, "Error: ") + print(ex.msg, " ") + fail += 1 + else + rethrow(ex) + end + end + end) +end + function run_tests() - @assert isa(1,Polynom) - @assert isa(1.0,Polynom) - @assert isa([1.0; 1.0],Polynom) - @assert isa(1.0,PolynomMatrix) - @assert isa(1,PolynomMatrix) + @test "Polynomials " begin + @tassert isa(1,Polynom) + @tassert isa(1.0,Polynom) + @tassert isa([1.0; 1.0],Polynom) + @tassert isa(1.0,PolynomMatrix) + @tassert isa(1,PolynomMatrix) + end + + @test "AR " begin + model, result = ar(collect(1:5.0),1,bias=true) + fit = result.fit + @tassert isa(model,AR) + @tassert isa(result,FitResult) + @tassert isa(fit,FitStatistics) + @tassert model.a ≈ [1;1] + @tassert fit.FIT ≈ 100.0 + @tassert isapprox(fit.RMS, 0.0, atol=1e-10) + @tassert result.method == :LS + end - #ar(collect(1:5.0),1,bias=true) + @test "ARX " begin + model, result = arx(collect(1:5.0),collect(1:5.0),1,1,bias=true) + fit = result.fit + @tassert isa(model,ARX) + @tassert isa(result,FitResult) + @tassert isa(fit,FitStatistics) + @tassert model.a ≈ [1;1] + @tassert fit.FIT ≈ 100.0 + @tassert isapprox(fit.RMS, 0.0, atol=1e-10) + @tassert result.method == :LS + end end end -- GitLab