11test_that(" expand classification works" , {
2- expect_equal(expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), c(2 , 2 , 1 )),
3- list (c(" 1." , " 1." , " 1." ),
4- c(" 1.1." , " 1.1." , " 1.2." ),
5- c(" 1.1.1" , " 1.1.2" , " 1.2.1" )))
6- expect_equal(expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), c(3 , 2 )),
7- list (c(" 1.1" , " 1.1" , " 1.2" ),
8- c(" 1.1.1" , " 1.1.2" , " 1.2.1" )))
9- expect_equal(expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), 3 ),
10- list (c(" 1.1" , " 1.1" , " 1.2" ),
11- c(" 1.1.1NA" , " 1.1.2NA" , " 1.2.1NA" )))
2+ expect_equal(
3+ expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), c(2 , 2 , 1 )),
4+ list (
5+ c(" 1." , " 1." , " 1." ),
6+ c(" 1.1." , " 1.1." , " 1.2." ),
7+ c(" 1.1.1" , " 1.1.2" , " 1.2.1" )
8+ )
9+ )
10+ expect_equal(
11+ expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), c(3 , 2 )),
12+ list (
13+ c(" 1.1" , " 1.1" , " 1.2" ),
14+ c(" 1.1.1" , " 1.1.2" , " 1.2.1" )
15+ )
16+ )
17+ expect_equal(
18+ expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), 3 ),
19+ list (
20+ c(" 1.1" , " 1.1" , " 1.2" ),
21+ c(" 1.1.1NA" , " 1.1.2NA" , " 1.2.1NA" )
22+ )
23+ )
1224 expect_equal(expand_classification(character (0 )), list ())
1325 expect_equal(expand_classification(c(" " , " " )), list (c(" NA" , " NA" )))
1426})
1527
1628test_that(" expand classification fails when expected" , {
1729 expect_error(expand_classification(" 123" , width = c(1 , 0 , 1 )))
1830 expect_error(expand_classification(" 123" , width = c(1 , NA , 1 )))
31+ expect_error(expand_classification(" 123" , pad = 1 : 3 ))
32+ expect_error(expand_classification(" 123" , pad = NULL ))
33+ })
34+
35+ test_that(" expand classification works with unbalanced classification" , {
36+ expect_identical(
37+ expand_classification(c(1234 , 12345 ), c(1 , 3 , 1 ), pad = 0 ),
38+ list (c(" 1" , " 1" ), c(" 1234" , " 1234" ), c(" 12340" , " 12345" ))
39+ )
40+ expect_identical(
41+ expand_classification(c(1234 , 12345 ), c(1 , 3 , 1 ), pad = " 00" ),
42+ list (c(" 1" , " 1" ), c(" 1234" , " 1234" ), c(" 123400" , " 12345" ))
43+ )
1944})
2045
2146test_that(" interaction works" , {
22- c1 = expand_classification(c(11 , 11 , 12 , 12 ))
23- c2 = expand_classification(c(111 , 112 , 121 , 122 ))
24-
47+ c1 <- expand_classification(c(11 , 11 , 12 , 12 ))
48+ c2 <- expand_classification(c(111 , 112 , 121 , 122 ))
49+
2550 expect_identical(
2651 interact_classifications(c1 ),
2752 list (c1 )
2853 )
29-
54+
3055 expect_identical(
3156 interact_classifications(c1 , c2 ),
3257 list (list (
@@ -39,7 +64,7 @@ test_that("interaction works", {
3964 c(" 11:111" , " 11:112" , " 12:121" , " 12:122" )
4065 ))
4166 )
42-
67+
4368 expect_identical(
4469 interact_classifications(list (rep(1 , 4 )), c1 , c2 ),
4570 list (list (
@@ -52,7 +77,7 @@ test_that("interaction works", {
5277 c(" 1:11:111" , " 1:11:112" , " 1:12:121" , " 1:12:122" )
5378 ))
5479 )
55-
80+
5681 expect_error(interact_classifications(c1 , list (c2 )))
5782 expect_error(interact_classifications(list (), c1 ))
5883 expect_error(interact_classifications(c1 , list (1 )))
@@ -62,7 +87,7 @@ test_that("interacting a single classification does nothing", {
6287 expect_identical(interact_classifications(), list ())
6388 expect_identical(interact_classifications(list (), list ()), list ())
6489 expect_identical(interact_classifications(list (1 )), list (list (1 )))
65-
66- x = expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), c(2 , 2 , 1 ))
90+
91+ x <- expand_classification(c(" 1.1.1" , " 1.1.2" , " 1.2.1" ), c(2 , 2 , 1 ))
6792 expect_identical(interact_classifications(x )[[1 ]], x )
68- })
93+ })
0 commit comments