Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 3, 2024
1 parent 3117387 commit 777e2a9
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 14 deletions.
141 changes: 130 additions & 11 deletions tests/testthat/_snaps/data_codebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
---

Code
print(data_codebook(efc), table_width = "auto")
print(data_codebook(efc), table_width = "auto", remove_duplicates = FALSE)
Output
efc (100 rows and 5 variables, 5 shown)
Expand All @@ -174,16 +174,55 @@
1 | c12hour | average number of hours of care per week | numeric
---+----------+------------------------------------------+------------
2 | e16sex | elder's gender | numeric
---+----------+------------------------------------------+------------
| | |
---+----------+------------------------------------------+------------
3 | e42dep | elder's dependency | categorical
| | |
| | |
| | |
---+----------+------------------------------------------+------------
4 | c172code | carer's level of education | numeric
| | |
| | |
---+----------+------------------------------------------+------------
5 | neg_c_7 | Negative impact with 7 items | numeric
----------------------------------------------------------------------
ID | Missings | Values | Value Labels | N
---+------------+----------+---------------------------------+-----------
1 | 2 (2.0%) | [5, 168] | | 98
---+------------+----------+---------------------------------+-----------
2 | 0 (0.0%) | 1 | male | 46 (46.0%)
| | 2 | female | 54 (54.0%)
---+------------+----------+---------------------------------+-----------
3 | 3 (3.0%) | 1 | independent | 2 ( 2.1%)
| | 2 | slightly dependent | 4 ( 4.1%)
| | 3 | moderately dependent | 28 (28.9%)
| | 4 | severely dependent | 63 (64.9%)
---+------------+----------+---------------------------------+-----------
4 | 10 (10.0%) | 1 | low level of education | 8 ( 8.9%)
| | 2 | intermediate level of education | 66 (73.3%)
| | 3 | high level of education | 16 (17.8%)
---+------------+----------+---------------------------------+-----------
5 | 3 (3.0%) | [7, 28] | | 97
-------------------------------------------------------------------------

---

Code
print(data_codebook(efc), table_width = "auto", remove_duplicates = TRUE)
Output
efc (100 rows and 5 variables, 5 shown)
ID | Name | Label | Type
---+----------+------------------------------------------+------------
1 | c12hour | average number of hours of care per week | numeric
---+----------+------------------------------------------+------------
4 | c172code | carer's level of education | numeric
2 | e16sex | elder's gender | numeric
---+----------+------------------------------------------+------------
3 | e42dep | elder's dependency | categorical
---+----------+------------------------------------------+------------
4 | c172code | carer's level of education | numeric
---+----------+------------------------------------------+------------
5 | neg_c_7 | Negative impact with 7 items | numeric
----------------------------------------------------------------------
Expand Down Expand Up @@ -237,7 +276,7 @@
---

Code
print(out, table_width = "auto")
print(out, table_width = "auto", remove_duplicates = FALSE)
Output
efc (100 rows and 5 variables, 5 shown)
Expand All @@ -247,16 +286,57 @@
| | care per week | |
---+----------+------------------------------+-------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%)
---+----------+------------------------------+-------------+-----------
| | | |
---+----------+------------------------------+-------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%)
| | | |
| | | |
| | | |
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
| | | |
| | | |
---+----------+------------------------------+-------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%)
-----------------------------------------------------------------------
ID | Values | Value Labels | N
---+----------+---------------------------------+-----------
1 | [5, 168] | | 98
| | |
---+----------+---------------------------------+-----------
2 | 1 | male | 46 (46.0%)
| 2 | female | 54 (54.0%)
---+----------+---------------------------------+-----------
3 | 1 | independent | 2 ( 2.1%)
| 2 | slightly dependent | 4 ( 4.1%)
| 3 | moderately dependent | 28 (28.9%)
| 4 | severely dependent | 63 (64.9%)
---+----------+---------------------------------+-----------
4 | 1 | low level of education | 8 ( 8.9%)
| 2 | intermediate level of education | 66 (73.3%)
| 3 | high level of education | 16 (17.8%)
---+----------+---------------------------------+-----------
5 | [7, 28] | | 97
------------------------------------------------------------

---

Code
print(out, table_width = "auto", remove_duplicates = TRUE)
Output
efc (100 rows and 5 variables, 5 shown)
ID | Name | Label | Type | Missings
---+----------+------------------------------+-------------+-----------
1 | c12hour | average number of hours of | numeric | 2 (2.0%)
| | care per week | |
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
2 | e16sex | elder's gender | numeric | 0 (0.0%)
---+----------+------------------------------+-------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%)
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
---+----------+------------------------------+-------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%)
-----------------------------------------------------------------------
Expand All @@ -265,7 +345,6 @@
---+----------+---------------------------------+-----------
1 | [5, 168] | | 98
---+----------+---------------------------------+-----------
---+----------+---------------------------------+-----------
2 | 1 | male | 46 (46.0%)
| 2 | female | 54 (54.0%)
---+----------+---------------------------------+-----------
Expand Down Expand Up @@ -311,7 +390,7 @@
---

Code
print(out, table_width = "auto")
print(out, table_width = "auto", remove_duplicates = FALSE)
Output
efc (100 rows and 5 variables, 5 shown)
Expand All @@ -321,16 +400,57 @@
| | care per week | |
---+----------+------------------------------+-------------+-----------
2 | e16sex | elder's gender | numeric | 0 (0.0%)
---+----------+------------------------------+-------------+-----------
| | | |
---+----------+------------------------------+-------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%)
| | | |
| | | |
| | | |
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
| | | |
| | | |
---+----------+------------------------------+-------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%)
-----------------------------------------------------------------------
ID | Values | Value Labels | N
---+----------+------------------+-----------
1 | [5, 168] | | 98
| | |
---+----------+------------------+-----------
2 | 1 | male | 46 (46.0%)
| 2 | female | 54 (54.0%)
---+----------+------------------+-----------
3 | 1 | independent | 2 ( 2.1%)
| 2 | slightly... | 4 ( 4.1%)
| 3 | moderately... | 28 (28.9%)
| 4 | severely... | 63 (64.9%)
---+----------+------------------+-----------
4 | 1 | low level of... | 8 ( 8.9%)
| 2 | intermediate... | 66 (73.3%)
| 3 | high level of... | 16 (17.8%)
---+----------+------------------+-----------
5 | [7, 28] | | 97
---------------------------------------------

---

Code
print(out, table_width = "auto", remove_duplicates = TRUE)
Output
efc (100 rows and 5 variables, 5 shown)
ID | Name | Label | Type | Missings
---+----------+------------------------------+-------------+-----------
1 | c12hour | average number of hours of | numeric | 2 (2.0%)
| | care per week | |
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
2 | e16sex | elder's gender | numeric | 0 (0.0%)
---+----------+------------------------------+-------------+-----------
3 | e42dep | elder's dependency | categorical | 3 (3.0%)
---+----------+------------------------------+-------------+-----------
4 | c172code | carer's level of education | numeric | 10 (10.0%)
---+----------+------------------------------+-------------+-----------
5 | neg_c_7 | Negative impact with 7 items | numeric | 3 (3.0%)
-----------------------------------------------------------------------
Expand All @@ -339,7 +459,6 @@
---+----------+------------------+-----------
1 | [5, 168] | | 98
---+----------+------------------+-----------
---+----------+------------------+-----------
2 | 1 | male | 46 (46.0%)
| 2 | female | 54 (54.0%)
---+----------+------------------+-----------
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-data_codebook.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,24 @@ test_that("data_codebook iris, select, ID", {

test_that("data_codebook efc", {
expect_snapshot(print(data_codebook(efc), table_width = Inf))
expect_snapshot(print(data_codebook(efc), table_width = "auto"))
expect_snapshot(print(data_codebook(efc), table_width = "auto", remove_duplicates = FALSE))
expect_snapshot(print(data_codebook(efc), table_width = "auto", remove_duplicates = TRUE))
})


test_that("data_codebook efc, variable_label_width", {
out <- data_codebook(efc, variable_label_width = 30)
expect_snapshot(print(out, table_width = Inf))
expect_snapshot(print(out, table_width = "auto"))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = FALSE))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = TRUE))
})


test_that("data_codebook efc, value_label_width", {
out <- data_codebook(efc, variable_label_width = 30, value_label_width = 15)
expect_snapshot(print(out, table_width = Inf))
expect_snapshot(print(out, table_width = "auto"))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = FALSE))
expect_snapshot(print(out, table_width = "auto", remove_duplicates = TRUE))
})


Expand Down

0 comments on commit 777e2a9

Please sign in to comment.