@@ -36,6 +36,30 @@ test_that("normalize.data handles group normalization", {
3636 expect_equal(dim(result_group ), dim(test_data ))
3737})
3838
39+ test_that(" normalize.data preserves column order after group normalization" , {
40+ # Create test data with columns in a specific order
41+ # This tests the bug where columns were reordered by group
42+ test_data <- matrix (c(1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ), nrow = 3 , ncol = 4 )
43+ rownames(test_data ) <- paste0(" gene_" , 1 : 3 )
44+ colnames(test_data ) <- paste0(" sample_" , 1 : 4 )
45+
46+ # Create group vector where groups appear in non-alphabetical order
47+ # Original order: sample_1 (B), sample_2 (A), sample_3 (B), sample_4 (A)
48+ # If unique() sorts alphabetically, it would process A then B, reordering columns
49+ test_grp_vec <- c(" B" , " A" , " B" , " A" )
50+ names(test_grp_vec ) <- colnames(test_data )
51+
52+ # Store original column order
53+ original_col_order <- colnames(test_data )
54+
55+ # Test group normalization
56+ result_group <- normalize.data(test_data , method = " Median" , grp.vec = test_grp_vec )
57+
58+ # Verify column order is preserved
59+ expect_equal(colnames(result_group ), original_col_order )
60+ expect_equal(dim(result_group ), dim(test_data ))
61+ })
62+
3963test_that(" normalize.data handles single group" , {
4064 # Create test data with proper dimnames
4165 test_data <- matrix (c(1 , 2 , 3 , 4 , 5 , 6 ), nrow = 2 , ncol = 3 )
0 commit comments