From b4c0742309c21dbfe8f04d5639e9dbf0f555470f Mon Sep 17 00:00:00 2001 From: "mhsatman@gmail.com" Date: Sun, 26 May 2024 19:09:57 +0300 Subject: [PATCH] summary throws error when an unknown method name is provided --- CHANGELOG.md | 2 ++ src/summary.jl | 3 +-- test/testsummary.jl | 59 +++++++++++++++++++++++++++++---------------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a00b24..f6e3c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Initial attempt to reduce memory allocations in `lts()`, `lms()`, `hadi92()`, `hadi94()`, `hs93()`, `robcov()` - Replace `@assert` macro with `throw(ErrorException())` in whole code - `depestregression` returns `Dict` instead of a `vector` of betas like other regression methods. +- `summary()` throws `ErrorException` rather than simply prompting with `@error` macro. + # v0.11.3 diff --git a/src/summary.jl b/src/summary.jl index 710ecd9..6edba0e 100644 --- a/src/summary.jl +++ b/src/summary.jl @@ -118,8 +118,7 @@ function detectOutliers(X::AbstractMatrix{Float64}, y::AbstractVector{Float64}; result = Int[] end else - @error "Method not found " method - result = Int[] + throw(ErrorException("Method not found: $method")) end outlier_matrix[:, method] = makeColorColumn(result, n) end diff --git a/test/testsummary.jl b/test/testsummary.jl index 9399a8b..45d3d40 100644 --- a/test/testsummary.jl +++ b/test/testsummary.jl @@ -1,6 +1,8 @@ @testset "Summary" begin - smiley = " 😔 " - methods = [ + + @testset "Withour errors" begin + smiley = " 😔 " + methods = [ "hs93", "ks89", "smr98", @@ -10,25 +12,40 @@ "asm20", "bch", "bacon", - "imon2005", + "imon2005" + ] + sett = LinRegOutliers.createRegressionSetting(@formula(calls ~ year), phones) + result = LinRegOutliers.detectOutliers(sett, methods=methods) + + for i in 15:21 + @test result[:, "hs93"][i] == smiley + end + + for i in 18:20 + @test result[:, "ks89"][i] == smiley + end + + for i in 15:24 + @test result[:, "smr98"][i] == smiley + end + + for i in 15:21 + @test result[:, "lts"][i] == smiley + end + + end + + + + @testset "Withour errors" begin + + methods = [ "unknown" ] - sett = LinRegOutliers.createRegressionSetting(@formula(calls ~ year), phones) - result = LinRegOutliers.detectOutliers(sett, methods = methods) - - for i in 15:21 - @test result[:, "hs93"][i] == smiley - end - - for i in 18:20 - @test result[:, "ks89"][i] == smiley - end - - for i in 15:24 - @test result[:, "smr98"][i] == smiley - end - - for i in 15:21 - @test result[:, "lts"][i] == smiley - end + + sett = LinRegOutliers.createRegressionSetting(@formula(calls ~ year), phones) + + Test.@test_throws ErrorException LinRegOutliers.detectOutliers(sett, methods=methods) + + end end \ No newline at end of file