File tree Expand file tree Collapse file tree 6 files changed +163
-0
lines changed Expand file tree Collapse file tree 6 files changed +163
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ` levels ` argument is validated
2
+
3
+ Code
4
+ new_default_formula_blueprint(levels = 1)
5
+ Condition
6
+ Error in `new_default_formula_blueprint()`:
7
+ ! `levels` must be a list, not the number 1.
8
+
9
+ ---
10
+
11
+ Code
12
+ new_default_formula_blueprint(levels = list(1))
13
+ Condition
14
+ Error in `new_default_formula_blueprint()`:
15
+ ! `levels` must be fully named.
16
+
17
+ ---
18
+
19
+ Code
20
+ new_default_formula_blueprint(levels = list(a = 1))
21
+ Condition
22
+ Error in `new_default_formula_blueprint()`:
23
+ ! `levels` must only contain character vectors.
24
+
Original file line number Diff line number Diff line change
1
+ # check on input to ` new_blueprint() `
2
+
3
+ Code
4
+ new_blueprint(same_new_arg = 1, same_new_arg = 2)
5
+ Condition
6
+ Error in `new_blueprint()`:
7
+ ! All elements of `...` must have unique names.
8
+
9
+ # checks for updating a blueprint
10
+
11
+ Code
12
+ update_blueprint(blueprint, intercept = TRUE, intercept = FALSE)
13
+ Condition
14
+ Error in `update_blueprint()`:
15
+ ! `...` must have unique names.
16
+
17
+ ---
18
+
19
+ Code
20
+ update_blueprint(blueprint, intercpt = TRUE)
21
+ Condition
22
+ Error in `update_blueprint()`:
23
+ ! All elements of `...` must already exist.
24
+ i The following fields are new: "intercpt".
25
+
26
+ # checks the ptype
27
+
28
+ Code
29
+ new_blueprint(ptypes = list(x = 1))
30
+ Condition
31
+ Error in `new_blueprint()`:
32
+ ! `ptypes` must have an element named "predictors".
33
+
34
+ ---
35
+
36
+ Code
37
+ new_blueprint(ptypes = list(predictors = "not a tibble", outcomes = "not a tibble"))
38
+ Condition
39
+ Error in `new_blueprint()`:
40
+ ! `ptypes$predictors` must be a tibble, not the string "not a tibble".
41
+
42
+ ---
43
+
44
+ Code
45
+ new_blueprint(ptypes = list(predictors = tibble_too_long, outcomes = tibble_too_long))
46
+ Condition
47
+ Error in `new_blueprint()`:
48
+ ! `ptypes$predictors` must be size 0, not size 1.
49
+
Original file line number Diff line number Diff line change
1
+ # ` contr_one_hot() ` input checks
2
+
3
+ Code
4
+ contr_one_hot(n = 1, sparse = TRUE)
5
+ Condition
6
+ Warning:
7
+ `sparse = TRUE` not implemented for `contr_one_hot()`.
8
+ Output
9
+ 1
10
+ 1 1
11
+
12
+ ---
13
+
14
+ Code
15
+ contr_one_hot(n = 1, contrasts = FALSE)
16
+ Condition
17
+ Warning:
18
+ `contrasts = FALSE` not implemented for `contr_one_hot()`.
19
+ Output
20
+ 1
21
+ 1 1
22
+
23
+ ---
24
+
25
+ Code
26
+ contr_one_hot(n = 1:2)
27
+ Condition
28
+ Error in `contr_one_hot()`:
29
+ ! `n` must have length 1 when an integer is provided.
30
+
31
+ ---
32
+
33
+ Code
34
+ contr_one_hot(n = list(1:2))
35
+ Condition
36
+ Error in `contr_one_hot()`:
37
+ ! `n` must be a character vector or an integer of size 1.
38
+
Original file line number Diff line number Diff line change
1
+ test_that(" `levels` argument is validated" , {
2
+ expect_snapshot(error = TRUE , {
3
+ new_default_formula_blueprint(levels = 1 )
4
+ })
5
+ expect_snapshot(error = TRUE , {
6
+ new_default_formula_blueprint(levels = list (1 ))
7
+ })
8
+ expect_snapshot(error = TRUE , {
9
+ new_default_formula_blueprint(levels = list (" a" = 1 ))
10
+ })
11
+ })
Original file line number Diff line number Diff line change
1
+ test_that(" check on input to `new_blueprint()`" , {
2
+ expect_snapshot(error = TRUE , {
3
+ new_blueprint(same_new_arg = 1 , same_new_arg = 2 )
4
+ })
5
+ })
6
+
7
+ test_that(" checks for updating a blueprint" , {
8
+ blueprint <- default_xy_blueprint()
9
+
10
+ expect_snapshot(error = TRUE , {
11
+ update_blueprint(blueprint , intercept = TRUE , intercept = FALSE )
12
+ })
13
+ expect_snapshot(error = TRUE , {
14
+ update_blueprint(blueprint , intercpt = TRUE )
15
+ })
16
+ })
17
+
18
+ test_that(" checks the ptype" , {
19
+ expect_snapshot(error = TRUE , {
20
+ new_blueprint(ptypes = list (x = 1 ))
21
+ })
22
+ expect_snapshot(error = TRUE , {
23
+ new_blueprint(ptypes = list (" predictors" = " not a tibble" , outcomes = " not a tibble" ))
24
+ })
25
+
26
+ tibble_too_long <- tibble :: tibble(x = 1 )
27
+ expect_snapshot(error = TRUE , {
28
+ new_blueprint(ptypes = list (" predictors" = tibble_too_long , outcomes = tibble_too_long ))
29
+ })
30
+ })
Original file line number Diff line number Diff line change @@ -13,3 +13,14 @@ test_that("`model_matrix()` strips all attributes from the `model.matrix()` resu
13
13
# attached "assign" and "contrasts" attributes here
14
14
expect_identical(matrix $ Speciessetosa , expect )
15
15
})
16
+
17
+ test_that(" `contr_one_hot()` input checks" , {
18
+ expect_snapshot(contr_one_hot(n = 1 , sparse = TRUE ))
19
+ expect_snapshot(contr_one_hot(n = 1 , contrasts = FALSE ))
20
+ expect_snapshot(error = TRUE , {
21
+ contr_one_hot(n = 1 : 2 )
22
+ })
23
+ expect_snapshot(error = TRUE , {
24
+ contr_one_hot(n = list (1 : 2 ))
25
+ })
26
+ })
You can’t perform that action at this time.
0 commit comments