Skip to content

Commit 6edf1b1

Browse files
committed
add tests to guard against breaking changes
1 parent d9e6477 commit 6edf1b1

3 files changed

Lines changed: 124 additions & 0 deletions

File tree

tests/testthat.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is part of the standard setup for testthat.
2+
# It is recommended that you do not modify it.
3+
#
4+
# Where should you do additional test configuration?
5+
# Learn more about the roles of various files in:
6+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
7+
# * https://testthat.r-lib.org/articles/special-files.html
8+
9+
library(testthat)
10+
library(fastrmodels)
11+
12+
test_check("fastrmodels")

tests/testthat/_snaps/models.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# models are structured as expected
2+
3+
Code
4+
print(parsed_ep_model)
5+
Output
6+
##### xgb.Booster
7+
# of features: 18
8+
# of rounds: 525
9+
xgb.attributes:
10+
niter
11+
12+
---
13+
14+
Code
15+
print(parsed_cp_model)
16+
Output
17+
##### xgb.Booster
18+
# of features: 18
19+
# of rounds: 560
20+
xgb.attributes:
21+
niter
22+
23+
---
24+
25+
Code
26+
print(parsed_wp_model)
27+
Output
28+
##### xgb.Booster
29+
# of features: 11
30+
# of rounds: 65
31+
xgb.attributes:
32+
niter
33+
34+
---
35+
36+
Code
37+
print(parsed_wp_model_spread)
38+
Output
39+
##### xgb.Booster
40+
# of features: 12
41+
# of rounds: 534
42+
xgb.attributes:
43+
niter
44+
45+
---
46+
47+
Code
48+
print(parsed_xpass_model)
49+
Output
50+
##### xgb.Booster
51+
# of features: 17
52+
# of rounds: 1121
53+
xgb.attributes:
54+
niter
55+
56+
---
57+
58+
Code
59+
print(parsed_xyac_model)
60+
Output
61+
##### xgb.Booster
62+
# of features: 19
63+
# of rounds: 500
64+
xgb.attributes:
65+
niter
66+

tests/testthat/test-models.R

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
test_that("models are structured as expected", {
2+
# test raw model types
3+
expect_type(ep_model, "raw")
4+
expect_type(cp_model, "raw")
5+
expect_type(wp_model, "raw")
6+
expect_type(wp_model_spread, "raw")
7+
expect_type(xpass_model, "raw")
8+
expect_type(xyac_model, "raw")
9+
expect_type(fg_model, "list")
10+
11+
# test length of raw model vectors
12+
expect_length(ep_model, 9737490L)
13+
expect_length(cp_model, 925080L)
14+
expect_length(wp_model, 106989L)
15+
expect_length(wp_model_spread, 1219925L)
16+
expect_length(xpass_model, 8378743L)
17+
expect_length(xyac_model, 48418214L)
18+
expect_length(fg_model, 54L)
19+
20+
# load raw models in xgboost
21+
parsed_ep_model <- xgboost::xgb.load.raw(ep_model)
22+
parsed_cp_model <- xgboost::xgb.load.raw(cp_model)
23+
parsed_wp_model <- xgboost::xgb.load.raw(wp_model)
24+
parsed_wp_model_spread <- xgboost::xgb.load.raw(wp_model_spread)
25+
parsed_xpass_model <- xgboost::xgb.load.raw(xpass_model)
26+
parsed_xyac_model <- xgboost::xgb.load.raw(xyac_model)
27+
28+
# verify class of all parsed models
29+
expect_s3_class(parsed_ep_model, "xgb.Booster")
30+
expect_s3_class(parsed_cp_model, "xgb.Booster")
31+
expect_s3_class(parsed_wp_model, "xgb.Booster")
32+
expect_s3_class(parsed_wp_model_spread, "xgb.Booster")
33+
expect_s3_class(parsed_xpass_model, "xgb.Booster")
34+
expect_s3_class(parsed_xyac_model, "xgb.Booster")
35+
expect_s3_class(fg_model, c("bam", "gam", "glm", "lm"), exact = TRUE)
36+
37+
# snapshot print method of xgboost models
38+
# just as an additional layer of security guarding against breaking
39+
# xgboost changes
40+
expect_snapshot(print(parsed_ep_model), cran = TRUE)
41+
expect_snapshot(print(parsed_cp_model), cran = TRUE)
42+
expect_snapshot(print(parsed_wp_model), cran = TRUE)
43+
expect_snapshot(print(parsed_wp_model_spread), cran = TRUE)
44+
expect_snapshot(print(parsed_xpass_model), cran = TRUE)
45+
expect_snapshot(print(parsed_xyac_model), cran = TRUE)
46+
})

0 commit comments

Comments
 (0)