Skip to content

Commit 050ba9f

Browse files
authored
Merge pull request #131 from ropensci/fix/fix-tests-assert
Fix/fix tests assert
2 parents d856759 + fc61e9b commit 050ba9f

File tree

1 file changed

+53
-31
lines changed

1 file changed

+53
-31
lines changed

‎tests/testthat/test-assert.R‎

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,59 @@
11
# Test assert family
22
context('test assert_*')
33

4-
expect_error(assert_not_null(NULL))
5-
expect_error(assert_is_data_table(data.frame()))
6-
expect_error(assert_is_data_table(data.table()))
7-
84
test <- data.table(X = LETTERS, Y = LETTERS, ANGLE = runif(length(LETTERS), 0, 180))
95
units(test$ANGLE) <- 'degrees'
106

11-
expect_error(assert_are_colnames(test, 'Z'))
12-
expect_error(assert_are_colnames(test, c('X', 'Z')))
13-
14-
expect_error(assert_col_inherits(test, 'X', 'numeric'))
15-
expect_error(assert_col_inherits(test, c('X', 'Y'), 'numeric'))
16-
17-
expect_error(assert_col_typeof(test, 'X', 'units'))
18-
expect_null(assert_col_typeof(test, 'X', 'character'))
19-
20-
expect_error(assert_inherits(42, 'character'))
21-
expect_error(assert_inherits(TRUE, 'numeric'))
22-
23-
expect_error(assert_col_radians(test, 'ANGLE', ', did you use direction_step?'))
24-
expect_error(assert_length(1:2, 3L))
25-
26-
expect_error(assert_relation(1, '>', 3))
27-
28-
expect_error((function(x) assert_not_missing(x))())
29-
30-
31-
expect_error(assert_threshold(0), '> 0')
32-
expect_error(assert_threshold(-1), '> 0')
33-
expect_silent(assert_threshold(1))
34-
expect_error(assert_threshold(assert_threshold(units::as_units(-1, 'm'))), '> 0')
35-
expect_error(assert_threshold(units::as_units(1, 'degree'), 4326), 'do not match')
36-
expect_silent(assert_threshold(units::as_units(1, 'm'), 4326))
37-
expect_silent(assert_threshold(units::as_units(1, 'm'), 32649))
7+
test_that('assert_not_null', {
8+
expect_error(assert_not_null(NULL))
9+
})
10+
11+
test_that('assert_is_data_table', {
12+
expect_error(assert_is_data_table(data.frame()))
13+
expect_error(assert_is_data_table(data.table()))
14+
})
15+
16+
test_that('assert_are_colnames', {
17+
expect_error(assert_are_colnames(test, 'Z'))
18+
expect_error(assert_are_colnames(test, c('X', 'Z')))
19+
})
20+
21+
test_that('assert_col_inherits', {
22+
expect_error(assert_col_inherits(test, 'X', 'numeric'))
23+
expect_error(assert_col_inherits(test, c('X', 'Y'), 'numeric'))
24+
})
25+
26+
test_that('assert_col_typeof', {
27+
expect_error(assert_col_typeof(test, 'X', 'units'))
28+
expect_null(assert_col_typeof(test, 'X', 'character'))
29+
})
30+
31+
test_that('assert_inherits', {
32+
expect_error(assert_inherits(42, 'character'))
33+
expect_error(assert_inherits(TRUE, 'numeric'))
34+
})
35+
36+
37+
test_that('assert_col_radians', {
38+
expect_error(assert_col_radians(test, 'ANGLE', ', did you use direction_step?'))
39+
})
40+
test_that('assert_length', {
41+
expect_error(assert_length(1:2, 3L))
42+
})
43+
test_that('assert_relation', {
44+
expect_error(assert_relation(1, '>', 3))
45+
})
46+
47+
test_that('assert_not_missing', {
48+
expect_error((function(x) assert_not_missing(x))())
49+
})
50+
51+
test_that('assert_threshold', {
52+
expect_error(assert_threshold(0), '> 0')
53+
expect_error(assert_threshold(-1), '> 0')
54+
expect_silent(assert_threshold(1))
55+
expect_error(assert_threshold(units::as_units(-1, 'm')), '> units')
56+
expect_error(assert_threshold(units::as_units(1, 'degree'), 4326), 'do not match')
57+
expect_silent(assert_threshold(units::as_units(1, 'm'), 4326))
58+
expect_silent(assert_threshold(units::as_units(1, 'm'), 32649))
59+
})

0 commit comments

Comments
 (0)