Skip to content

Commit

Permalink
add generic interface tests from MLJTestIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Sep 19, 2022
1 parent d44debb commit 0125d75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ julia = "1.6"
[extras]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
MLJTestIntegration = "697918b4-fdc1-4f9e-8ff9-929724cee270"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Distributions", "MLJBase", "StableRNGs", "Test"]
test = ["Distributions", "MLJBase", "MLJTestIntegration", "StableRNGs", "Test"]
47 changes: 43 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using MLJTestIntegration
using MLJBase
using Test
import XGBoost
Expand Down Expand Up @@ -68,9 +69,9 @@ ycount = @view(ycount_[:]) # intention is to simulate issue #17

fitresultC, cacheC, reportC = MLJBase.fit(count_regressor, 0, Xtable, ycount);
fitresultC_, cacheC_, reportC_ = MLJBase.fit(count_regressor, 0, Xtable, ycount_);
# the `cacheC` and `reportC` should be same for both models but the
# the `cacheC` and `reportC` should be same for both models but the
# `fitresultC`s might be different since they may have different pointers to same
# information.
# information.
@test cacheC == cacheC_
@test reportC == reportC_
cpred = predict(count_regressor, fitresultC, Xtable);
Expand Down Expand Up @@ -112,9 +113,9 @@ fitresult, cache, report = MLJBase.fit(plain_classifier, 0,
fitresult_, cache_, report_ = MLJBase.fit(
plain_classifier, 0, selectrows(X, train), @view(y[train]);
) # mimick issue #17
# the `cache` and `report` should be same for both models but the
# the `cache` and `report` should be same for both models but the
# `fitresult` might be different since they may have different pointers to same
# information.
# information.
@test cache == cache_
@test report == report_

Expand Down Expand Up @@ -181,3 +182,41 @@ mach2 = machine(io)

# compare:
@test predict_mode(mach2, X) == yhat

@testset "generic interface tests" begin
@testset "XGBoostRegressor" begin
failures, summary = MLJTestIntegration.test(
[XGBoostRegressor,],
MLJTestIntegration.make_regression()...;
mod=@__MODULE__,
verbosity=0, # bump to debug
throw=false, # set to true to debug
)
@test isempty(failures)
end
@testset "XGBoostCount" begin
failures, summary = MLJTestIntegration.test(
[XGBoostCount],
MLJTestIntegration.make_count()...;
mod=@__MODULE__,
verbosity=0, # bump to debug
throw=false, # set to true to debug
)
@test isempty(failures)
end
@testset "XGBoostClassifier" begin
for data in [
MLJTestIntegration.make_binary(),
MLJTestIntegration.make_multiclass(),
]
failures, summary = MLJTestIntegration.test(
[XGBoostClassifier],
data...;
mod=@__MODULE__,
verbosity=0, # bump to debug
throw=false, # set to true to debug
)
@test isempty(failures)
end
end
end

0 comments on commit 0125d75

Please sign in to comment.