1- # ###############################################################################
2- # Tests for collapse_timeframes()
3- # ###############################################################################
4-
51context(" collapse_timeframes: collapsing longitudinal edgelists" )
62
73# Base edgelist used across most tests:
@@ -15,9 +11,7 @@ el <- data.frame(
1511 weight = c(1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 )
1612)
1713
18- # ###############################################################################
19- # Block 1: Output structure
20- # ###############################################################################
14+ # Block 1: Output structure -----------------------------------------------
2115
2216test_that(" collapse_timeframes returns a data.frame" , {
2317 result <- collapse_timeframes(el , ego = " sender" , alter = " receiver" ,
@@ -47,9 +41,7 @@ test_that("output has fewer or equal rows than input after collapsing", {
4741 expect_lte(nrow(result ), nrow(el ))
4842})
4943
50- # ###############################################################################
51- # Block 2: Binning logic (window_size)
52- # ###############################################################################
44+ # Block 2: Binning logic (window_size) ------------------------------------
5345
5446test_that(" window_size=1 does not merge periods" , {
5547 result <- collapse_timeframes(el , ego = " sender" , alter = " receiver" ,
@@ -86,9 +78,7 @@ test_that("aggregated weight is sum of constituent weights", {
8678 expect_equal(result $ weight , 1.0 )
8779})
8880
89- # ###############################################################################
90- # Block 3: relative_time TRUE / FALSE
91- # ###############################################################################
81+ # Block 3: relative_time TRUE / FALSE -------------------------------------
9282
9383# Edgelist with a gap: time points 1, 2, 5, 6 (no 3 or 4)
9484el_gap <- data.frame (
@@ -112,9 +102,7 @@ test_that("relative_time=FALSE preserves original bin values (may have gaps)", {
112102 expect_false(identical(sort(unique(result $ time )), 1 : 4 ))
113103})
114104
115- # ###############################################################################
116- # Block 4: Time column parsing (integer, POSIXct, character string)
117- # ###############################################################################
105+ # Block 4: Time column parsing (integer, POSIXct, character string) -------
118106
119107test_that(" integer time column is handled" , {
120108 el_int <- el
@@ -148,9 +136,7 @@ test_that("character time with time_format is parsed correctly", {
148136 expect_equal(length(unique(result $ time )), 2L )
149137})
150138
151- # ###############################################################################
152- # Block 5: weightvar = NULL (count mode) vs explicit weight column
153- # ###############################################################################
139+ # Block 5: weightvar = NULL (count mode) vs explicit weight column --------
154140
155141test_that(" weightvar=NULL counts interactions as weight" , {
156142 el_now <- data.frame (
@@ -186,9 +172,7 @@ test_that("explicit weight column is summed correctly", {
186172 expect_equal(result $ w , 10 )
187173})
188174
189- # ###############################################################################
190- # Block 6: Edge cases and error handling
191- # ###############################################################################
175+ # Block 6: Edge cases and error handling ----------------------------------
192176
193177test_that(" NAs in time column produce a warning" , {
194178 el_na <- el
0 commit comments