1+ context(" Test LCA Adjustment Function" )
2+
3+ test_that(" lca_adj works with basic data" , {
4+ # Create test data with DK responses
5+ pre_test <- data.frame (
6+ item1 = c(1 , 0 , 0 , 1 , " d" , 1 , 0 , " d" ),
7+ item2 = c(1 , 0 , 1 , " d" , 0 , " d" , 1 , 0 )
8+ )
9+ pst_test <- data.frame (
10+ item1 = c(1 , 1 , 0 , " d" , 1 , 0 , " d" , 1 ),
11+ item2 = c(1 , 0 , 1 , 0 , " d" , 1 , " d" , 0 )
12+ )
13+
14+ # Test basic functionality
15+ result <- lca_adj(pre_test , pst_test )
16+
17+ # Check structure
18+ expect_type(result , " list" )
19+ expect_named(result , c(" pre" , " pst" ))
20+
21+ # Check that something was returned (basic smoke test)
22+ expect_true(! is.null(result $ pre ))
23+ expect_true(! is.null(result $ pst ))
24+ })
25+
26+ test_that(" lca_adj handles NA values" , {
27+ # Create test data with NAs and DK
28+ pre_test <- data.frame (
29+ item1 = c(1 , 0 , NA , 1 , " d" , 0 , 1 , " d" ),
30+ item2 = c(1 , NA , 1 , " d" , 0 , " d" , 1 , 0 )
31+ )
32+ pst_test <- data.frame (
33+ item1 = c(1 , 1 , 0 , " d" , NA , 1 , " d" , 0 ),
34+ item2 = c(NA , 0 , 1 , 0 , " d" , 0 , " d" , 1 )
35+ )
36+
37+ # Should produce a warning about NA conversion
38+ expect_warning(
39+ result <- lca_adj(pre_test , pst_test ),
40+ " NAs will be converted to 0"
41+ )
42+
43+ # Check that function still works
44+ expect_type(result , " list" )
45+ expect_named(result , c(" pre" , " pst" ))
46+ })
47+
48+ test_that(" lca_adj validates basic inputs" , {
49+ # Test with NULL inputs (should error)
50+ expect_error(lca_adj(NULL , NULL ))
51+
52+ # Test basic functionality doesn't crash
53+ pre_test <- data.frame (item1 = c(1 , 0 , " d" , 1 , 0 ))
54+ pst_test <- data.frame (item1 = c(1 , " d" , 1 , 0 , 1 ))
55+
56+ expect_no_error(result <- lca_adj(pre_test , pst_test ))
57+ })
0 commit comments