From d4546c335336d205daef21e48aa9e04544cf8b73 Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Sat, 12 Oct 2024 12:34:32 +1300 Subject: [PATCH 1/3] improve coverage --- src/traits.jl | 14 ++------------ test/accessor_functions.jl | 4 ++++ test/fit_update.jl | 14 ++++++++++++++ test/runtests.jl | 2 ++ test/traits.jl | 1 + 5 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 test/accessor_functions.jl create mode 100644 test/fit_update.jl diff --git a/src/traits.jl b/src/traits.jl index 81ecf778..8c41a2a9 100644 --- a/src/traits.jl +++ b/src/traits.jl @@ -6,13 +6,6 @@ const DOC_UNKNOWN = "not overloaded the trait. " const DOC_ON_TYPE = "The value of the trait must depend only on the type of `algorithm`. " -DOC_ONLY_ONE(func) = - "Ordinarily, at most one of the following should be overloaded for given "* - "algorithm "* - "`LearnAPI.$(func)_scitype`, `LearnAPI.$(func)_type`, "* - "`LearnAPI.$(func)_observation_scitype`, "* - "`LearnAPI.$(func)_observation_type`." - const DOC_EXPLAIN_EACHOBS = """ @@ -82,7 +75,7 @@ value is non-empty. # New implementations -All new implementations must overload this trait. Here's a checklist for elements in the +All new implementations must implement this trait. Here's a checklist for elements in the return value: | expression | implementation compulsory? | include in returned tuple? | @@ -106,7 +99,6 @@ Also include any implemented accessor functions, both those owned by LearnaAPI.j algorithm-specific ones. The LearnAPI.jl accessor functions are: $ACCESSOR_FUNCTIONS_LIST. """ -functions(::Any) = () functions() = ( :(LearnAPI.fit), :(LearnAPI.algorithm), @@ -195,8 +187,6 @@ tags() = [ "meta-algorithms" ] -const DOC_TAGS_LIST = join(map(d -> "`\"$d\"`", tags()), ", ") - """ LearnAPI.tags(algorithm) @@ -402,7 +392,7 @@ See also [`LearnAPI.target_observation_scitype`](@ref). # New implementations -Optional. The fallback return value is `Union{}`. $(DOC_ONLY_ONE(:fit)) +Optional. The fallback return value is `Union{}`. """ fit_observation_scitype(::Any) = Union{} diff --git a/test/accessor_functions.jl b/test/accessor_functions.jl new file mode 100644 index 00000000..f22e73bb --- /dev/null +++ b/test/accessor_functions.jl @@ -0,0 +1,4 @@ +using Test +using LearnAPI + +@test strip("junk") == "junk" diff --git a/test/fit_update.jl b/test/fit_update.jl new file mode 100644 index 00000000..aa783432 --- /dev/null +++ b/test/fit_update.jl @@ -0,0 +1,14 @@ +using Test +using LearnAPI + +struct Gander end + +LearnAPI.update(::Gander, data) = sum(data) +LearnAPI.update_features(::Gander, data) = prod(data) + +@testset "update, update_features slurping" begin + @test update(Gander(), 2, 3, 4) == 9 + @test update_features(Gander(), 2, 3, 4) == 24 +end + +true diff --git a/test/runtests.jl b/test/runtests.jl index 2c66588d..a32dbecf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,6 +4,8 @@ test_files = [ "tools.jl", "traits.jl", "clone.jl", + "fit_update.jl", + "accessor_functions.jl", "integration/regression.jl", "integration/static_algorithms.jl", "integration/ensembling.jl", diff --git a/test/traits.jl b/test/traits.jl index a0c8a3d9..39484fa4 100644 --- a/test/traits.jl +++ b/test/traits.jl @@ -41,6 +41,7 @@ small = SmallAlgorithm() @test LearnAPI.data_interface(small) == LearnAPI.RandomAccess() @test !(6 isa LearnAPI.fit_observation_scitype(small)) @test 6 isa LearnAPI.target_observation_scitype(small) +@test !LearnAPI.is_static(small) # DERIVED TRAITS From 893b138104a4b912c4700fdacbff9eb445c78fe0 Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Sat, 12 Oct 2024 12:34:32 +1300 Subject: [PATCH 2/3] improve coverage --- src/traits.jl | 14 ++------------ test/accessor_functions.jl | 4 ++++ test/fit_update.jl | 14 ++++++++++++++ test/runtests.jl | 5 +++++ test/traits.jl | 1 + 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 test/accessor_functions.jl create mode 100644 test/fit_update.jl diff --git a/src/traits.jl b/src/traits.jl index 614daf53..9b566120 100644 --- a/src/traits.jl +++ b/src/traits.jl @@ -6,13 +6,6 @@ const DOC_UNKNOWN = "not overloaded the trait. " const DOC_ON_TYPE = "The value of the trait must depend only on the type of `algorithm`. " -DOC_ONLY_ONE(func) = - "Ordinarily, at most one of the following should be overloaded for given "* - "algorithm "* - "`LearnAPI.$(func)_scitype`, `LearnAPI.$(func)_type`, "* - "`LearnAPI.$(func)_observation_scitype`, "* - "`LearnAPI.$(func)_observation_type`." - const DOC_EXPLAIN_EACHOBS = """ @@ -82,7 +75,7 @@ value is non-empty. # New implementations -All new implementations must overload this trait. Here's a checklist for elements in the +All new implementations must implement this trait. Here's a checklist for elements in the return value: | expression | implementation compulsory? | include in returned tuple? | @@ -107,7 +100,6 @@ algorithm-specific ones. The LearnAPI.jl accessor functions are: $ACCESSOR_FUNCT (`LearnAPI.strip` is always included). """ -functions(::Any) = () functions() = ( :(LearnAPI.fit), :(LearnAPI.algorithm), @@ -196,8 +188,6 @@ tags() = [ "meta-algorithms" ] -const DOC_TAGS_LIST = join(map(d -> "`\"$d\"`", tags()), ", ") - """ LearnAPI.tags(algorithm) @@ -403,7 +393,7 @@ See also [`LearnAPI.target_observation_scitype`](@ref). # New implementations -Optional. The fallback return value is `Union{}`. $(DOC_ONLY_ONE(:fit)) +Optional. The fallback return value is `Union{}`. """ fit_observation_scitype(::Any) = Union{} diff --git a/test/accessor_functions.jl b/test/accessor_functions.jl new file mode 100644 index 00000000..f22e73bb --- /dev/null +++ b/test/accessor_functions.jl @@ -0,0 +1,4 @@ +using Test +using LearnAPI + +@test strip("junk") == "junk" diff --git a/test/fit_update.jl b/test/fit_update.jl new file mode 100644 index 00000000..aa783432 --- /dev/null +++ b/test/fit_update.jl @@ -0,0 +1,14 @@ +using Test +using LearnAPI + +struct Gander end + +LearnAPI.update(::Gander, data) = sum(data) +LearnAPI.update_features(::Gander, data) = prod(data) + +@testset "update, update_features slurping" begin + @test update(Gander(), 2, 3, 4) == 9 + @test update_features(Gander(), 2, 3, 4) == 24 +end + +true diff --git a/test/runtests.jl b/test/runtests.jl index 9af76002..c71b5e38 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,11 +4,16 @@ test_files = [ "tools.jl", "traits.jl", "clone.jl", + "fit_update.jl", + "accessor_functions.jl", "predict_transform.jl", "patterns/regression.jl", "patterns/static_algorithms.jl", "patterns/ensembling.jl", "patterns/incremental_algorithms.jl", + "patterns/regression.jl", + "patterns/static_algorithms.jl", + "integration/ensembling.jl", ] files = isempty(ARGS) ? test_files : ARGS diff --git a/test/traits.jl b/test/traits.jl index ab4cad1a..e6eaae45 100644 --- a/test/traits.jl +++ b/test/traits.jl @@ -44,6 +44,7 @@ small = SmallAlgorithm() @test LearnAPI.data_interface(small) == LearnAPI.RandomAccess() @test !(6 isa LearnAPI.fit_observation_scitype(small)) @test 6 isa LearnAPI.target_observation_scitype(small) +@test !LearnAPI.is_static(small) # DERIVED TRAITS From 92e5e3b1529c3a7f8b5ad0cfd339885fc7ea46e8 Mon Sep 17 00:00:00 2001 From: "Anthony D. Blaom" Date: Sat, 12 Oct 2024 12:41:01 +1300 Subject: [PATCH 3/3] fix duplication --- test/runtests.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 4d2aa289..9ef643f8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,8 +11,6 @@ test_files = [ "patterns/static_algorithms.jl", "patterns/ensembling.jl", "patterns/incremental_algorithms.jl", - "patterns/regression.jl", - "patterns/static_algorithms.jl", ] files = isempty(ARGS) ? test_files : ARGS