Skip to content

Commit 42f17ee

Browse files
committed
Add tests for the new functionality regarding last activity
The tests cover the new "last.activity" vertex attribute, which shall implicitly also cover the last-activity data computation. Signed-off-by: Thomas Bock <[email protected]>
1 parent c0d6515 commit 42f17ee

File tree

1 file changed

+369
-0
lines changed

1 file changed

+369
-0
lines changed

tests/test-networks-covariates.R

Lines changed: 369 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
## Copyright 2021 by Christian Hechtl <[email protected]>
1717
## Copyright 2017-2019 by Claus Hunsen <[email protected]>
1818
## Copyright 2018-2019 by Thomas Bock <[email protected]>
19+
## Copyright 2024 by Thomas Bock <[email protected]>
1920
## Copyright 2018-2019 by Klara Schlüter <[email protected]>
2021
## Copyright 2018-2019 by Jakob Kronawitter <[email protected]>
2122
## Copyright 2021 by Johannes Hostert <[email protected]>
@@ -316,6 +317,228 @@ get.expected.first.activity = function() {
316317
return(expected.attributes)
317318
}
318319

320+
#' Helper for the last activitity tests: Gets the last activity per person and data source for possible
321+
#' aggregation levels as a nested list.
322+
#'
323+
#' @return A list (elements represent the levels) of lists (elements represent the networks after splitting) of lists
324+
#' (elements represent the vertices which represent persons) of lists (elements represent the different data
325+
#' sources) of dates as PoSIXct.
326+
get.expected.last.activity = function() {
327+
expected.attributes = list(
328+
range = network.covariates.test.build.expected(
329+
list(
330+
list(
331+
mails = "2016-07-12 15:58:40 UTC",
332+
commits = "2016-07-12 15:58:59 UTC",
333+
issues = NA
334+
)
335+
),
336+
list(
337+
list(
338+
mails = NA,
339+
commits = "2016-07-12 16:00:45 UTC",
340+
issues = NA
341+
)
342+
),
343+
list(
344+
list(
345+
mails = "2016-07-12 16:05:37 UTC",
346+
commits = "2016-07-12 16:05:41 UTC",
347+
issues = NA
348+
),
349+
list(
350+
mails = NA,
351+
commits = "2016-07-12 16:06:10 UTC",
352+
issues = NA
353+
),
354+
list(
355+
mails = NA,
356+
commits = "2016-07-12 16:06:32 UTC",
357+
issues = NA
358+
)
359+
)
360+
),
361+
cumulative = network.covariates.test.build.expected(
362+
list(
363+
list(
364+
mails = "2016-07-12 15:58:40 UTC",
365+
commits = "2016-07-12 15:58:59 UTC",
366+
issues = NA
367+
)
368+
),
369+
list(
370+
list(
371+
mails = "2016-07-12 15:58:50 UTC",
372+
commits = "2016-07-12 16:00:45 UTC",
373+
issues = NA
374+
)
375+
),
376+
list(
377+
list(
378+
mails = "2016-07-12 16:05:37 UTC",
379+
commits = "2016-07-12 16:05:41 UTC",
380+
issues = NA
381+
),
382+
list(
383+
mails = NA,
384+
commits = "2016-07-12 16:06:10 UTC",
385+
issues = NA
386+
),
387+
list(
388+
mails = "2016-07-12 16:04:40 UTC",
389+
commits = "2016-07-12 16:06:32 UTC",
390+
issues = NA
391+
)
392+
)
393+
),
394+
all.ranges = network.covariates.test.build.expected(
395+
list(
396+
list(
397+
mails = "2016-07-12 15:58:40 UTC",
398+
commits = "2016-07-12 15:58:59 UTC",
399+
issues = NA
400+
)
401+
),
402+
list(
403+
list(
404+
mails = "2016-07-12 16:05:37 UTC",
405+
commits = "2016-07-12 16:05:41 UTC",
406+
issues = NA
407+
)
408+
),
409+
list(
410+
list(
411+
mails = "2016-07-12 16:05:37 UTC",
412+
commits = "2016-07-12 16:05:41 UTC",
413+
issues = NA
414+
),
415+
list(
416+
mails = NA,
417+
commits = "2016-07-12 16:06:10 UTC",
418+
issues = NA
419+
),
420+
list(
421+
mails = "2016-07-12 16:04:40 UTC",
422+
commits = "2016-07-12 16:06:32 UTC",
423+
issues = NA
424+
)
425+
)
426+
),
427+
project.cumulative = network.covariates.test.build.expected(
428+
list(
429+
list(
430+
mails = "2016-07-12 15:58:40 UTC",
431+
commits = "2016-07-12 15:58:59 UTC",
432+
issues = NA
433+
)
434+
),
435+
list(
436+
list(
437+
mails = "2016-07-12 15:58:50 UTC",
438+
commits = "2016-07-12 16:00:45 UTC",
439+
issues = NA
440+
)
441+
),
442+
list(
443+
list(
444+
mails = "2016-07-12 16:05:37 UTC",
445+
commits = "2016-07-12 16:05:41 UTC",
446+
issues = NA
447+
),
448+
list(
449+
mails = NA,
450+
commits = "2016-07-12 16:06:10 UTC",
451+
issues = NA
452+
),
453+
list(
454+
mails = "2016-07-12 16:04:40 UTC",
455+
commits = "2016-07-12 16:06:32 UTC",
456+
issues = NA
457+
)
458+
)
459+
),
460+
project.all.ranges = network.covariates.test.build.expected(
461+
list(
462+
list(
463+
mails = "2016-07-12 15:58:40 UTC",
464+
commits = "2016-07-12 15:58:59 UTC",
465+
issues = NA
466+
)
467+
),
468+
list(
469+
list(
470+
mails = "2016-07-12 16:05:37 UTC",
471+
commits = "2016-07-12 16:05:41 UTC",
472+
issues = NA
473+
)
474+
),
475+
list(
476+
list(
477+
mails = "2016-07-12 16:05:37 UTC",
478+
commits = "2016-07-12 16:05:41 UTC",
479+
issues = NA
480+
),
481+
list(
482+
mails = NA,
483+
commits = "2016-07-12 16:06:10 UTC",
484+
issues = NA
485+
),
486+
list(
487+
mails = "2016-07-12 16:04:40 UTC",
488+
commits = "2016-07-12 16:06:32 UTC",
489+
issues = NA
490+
)
491+
)
492+
),
493+
complete = network.covariates.test.build.expected(
494+
list(
495+
list(
496+
mails = "2016-07-12 15:58:40 UTC",
497+
commits = "2016-07-12 15:58:59 UTC",
498+
issues = NA
499+
)
500+
),
501+
list(
502+
list(
503+
mails = "2016-07-12 16:05:37",
504+
commits = "2016-07-12 16:05:41 UTC",
505+
issues = NA
506+
)
507+
),
508+
list(
509+
list(
510+
mails = "2016-07-12 16:05:37",
511+
commits = "2016-07-12 16:05:41 UTC",
512+
issues = NA
513+
),
514+
list(
515+
mails = NA,
516+
commits = "2016-07-12 16:06:10 UTC",
517+
issues = NA
518+
),
519+
list(
520+
mails = "2016-07-12 16:04:40 UTC",
521+
commits = "2016-07-12 16:06:32 UTC",
522+
issues = NA
523+
)
524+
)
525+
)
526+
)
527+
528+
## convert date strings to POSIXct
529+
expected.attributes = lapply(expected.attributes, function(level) {
530+
lapply(level, function(network) {
531+
lapply(network, function(person) {
532+
lapply(person, function(date.per.datasource) {
533+
return(get.date.from.string(date.per.datasource))
534+
})
535+
})
536+
})
537+
})
538+
539+
return(expected.attributes)
540+
}
541+
319542
#' Helper for tests of the function add.vertex.attribute.author.active.ranges: Returns the expected active ranges per range,
320543
#' author and data source as a nested list.
321544
#'
@@ -1044,6 +1267,152 @@ test_that("Test add.vertex.attribute.author.first.activity with one type and com
10441267
})
10451268
})
10461269

1270+
#' Test the add.vertex.attribute.author.last.activity method with computation over all types.
1271+
test_that("Test add.vertex.attribute.author.last.activity with multiple types and computation over all types", {
1272+
1273+
## Test setup
1274+
1275+
networks.and.data = get.network.covariates.test.networks()
1276+
1277+
## lock issues in order to prevent them from being read because that alters the first activity dates
1278+
networks.and.data$project.data$set.project.conf.entry("issues.locked", TRUE)
1279+
1280+
expected.attributes = list(
1281+
range = network.covariates.test.build.expected(
1282+
list(list(all.activities = "2016-07-12 15:58:59 UTC")),
1283+
list(list(all.activities = "2016-07-12 16:00:45 UTC")),
1284+
list(list(all.activities = "2016-07-12 16:05:41 UTC"),
1285+
list(all.activities = "2016-07-12 16:06:10 UTC"),
1286+
list(all.activities = "2016-07-12 16:06:32 UTC")
1287+
)
1288+
),
1289+
cumulative = network.covariates.test.build.expected(
1290+
list(list(all.activities = "2016-07-12 15:58:59 UTC")),
1291+
list(list(all.activities = "2016-07-12 16:00:45 UTC")),
1292+
list(list(all.activities = "2016-07-12 16:05:41 UTC"),
1293+
list(all.activities = "2016-07-12 16:06:10 UTC"),
1294+
list(all.activities = "2016-07-12 16:06:32 UTC")
1295+
)
1296+
),
1297+
all.ranges = network.covariates.test.build.expected(
1298+
list(list(all.activities = "2016-07-12 15:58:59 UTC")),
1299+
list(list(all.activities = "2016-07-12 16:05:41 UTC")),
1300+
list(list(all.activities = "2016-07-12 16:05:41 UTC"),
1301+
list(all.activities = "2016-07-12 16:06:10 UTC"),
1302+
list(all.activities = "2016-07-12 16:06:32 UTC")
1303+
)
1304+
),
1305+
project.cumulative = network.covariates.test.build.expected(
1306+
list(list(all.activities = "2016-07-12 15:58:59 UTC")),
1307+
list(list(all.activities = "2016-07-12 16:00:45 UTC")),
1308+
list(list(all.activities = "2016-07-12 16:05:41 UTC"),
1309+
list(all.activities = "2016-07-12 16:06:10 UTC"),
1310+
list(all.activities = "2016-07-12 16:06:32 UTC")
1311+
)
1312+
),
1313+
project.all.ranges = network.covariates.test.build.expected(
1314+
list(list(all.activities = "2016-07-12 15:58:59 UTC")),
1315+
list(list(all.activities = "2016-07-12 16:05:41 UTC")),
1316+
list(list(all.activities = "2016-07-12 16:05:41 UTC"),
1317+
list(all.activities = "2016-07-12 16:06:10 UTC"),
1318+
list(all.activities = "2016-07-12 16:06:32 UTC")
1319+
)
1320+
),
1321+
complete = network.covariates.test.build.expected(
1322+
list(list(all.activities = "2016-07-12 15:58:59 UTC")),
1323+
list(list(all.activities = "2016-07-12 16:05:41 UTC")),
1324+
list(list(all.activities = "2016-07-12 16:05:41 UTC"),
1325+
list(all.activities = "2016-07-12 16:06:10 UTC"),
1326+
list(all.activities = "2016-07-12 16:06:32 UTC")
1327+
)
1328+
)
1329+
)
1330+
1331+
## convert date strings to POSIXct
1332+
expected.attributes = lapply(expected.attributes, function(level) {
1333+
lapply(level, function(network) {
1334+
lapply(network, function(person) {
1335+
lapply(person, function(date.per.datasource) {
1336+
return(get.date.from.string(date.per.datasource))
1337+
})
1338+
})
1339+
})
1340+
})
1341+
1342+
## Test
1343+
1344+
lapply(AGGREGATION.LEVELS, function(level) {
1345+
1346+
networks.with.attributes = add.vertex.attribute.author.last.activity(
1347+
list.of.networks = networks.and.data[["networks"]], project.data = networks.and.data[["project.data"]],
1348+
activity.types = c("mails", "commits", "issues"), name = "last.activity", aggregation.level = level,
1349+
default.value = NA, combine.activity.types = TRUE
1350+
)
1351+
actual.attributes = lapply(networks.with.attributes, igraph::vertex_attr, name = "last.activity")
1352+
1353+
expect_equal(expected.attributes[[level]], actual.attributes)
1354+
})
1355+
})
1356+
1357+
#' Test the add.vertex.attribute.author.last.activity method with multiple activity types and computation per type.
1358+
test_that("Test add.vertex.attribute.author.last.activity with multiple types and computation per type", {
1359+
1360+
## Test setup
1361+
1362+
networks.and.data = get.network.covariates.test.networks()
1363+
1364+
expected.attributes = get.expected.last.activity()
1365+
1366+
## lock issues in order to prevent them from being read because that alters the first activity dates
1367+
networks.and.data$project.data$set.project.conf.entry("issues.locked", TRUE)
1368+
1369+
## Test
1370+
1371+
lapply(AGGREGATION.LEVELS, function(level) {
1372+
1373+
networks.with.attributes = add.vertex.attribute.author.last.activity(
1374+
list.of.networks = networks.and.data[["networks"]], project.data = networks.and.data[["project.data"]],
1375+
activity.types = c("mails", "commits", "issues"), name = "last.activity", aggregation.level = level,
1376+
default.value = NA, combine.activity.types = FALSE
1377+
)
1378+
actual.attributes = lapply(networks.with.attributes, igraph::vertex_attr, name = "last.activity")
1379+
1380+
expect_equal(expected.attributes[[level]], actual.attributes)
1381+
})
1382+
})
1383+
1384+
#' Test the add.vertex.attribute.author.last.activity method with one activity type and computation per type.
1385+
test_that("Test add.vertex.attribute.author.last.activity with one type and computation per type", {
1386+
1387+
## Test setup
1388+
1389+
networks.and.data = get.network.covariates.test.networks()
1390+
1391+
expected.attributes = get.expected.last.activity()
1392+
expected.attributes = lapply(expected.attributes, function(level) {
1393+
lapply(level, function(network) {
1394+
lapply(network, function(person) {
1395+
return(person["mails"])
1396+
})
1397+
})
1398+
})
1399+
1400+
1401+
## Test
1402+
1403+
lapply(AGGREGATION.LEVELS, function(level) {
1404+
1405+
networks.with.attributes = add.vertex.attribute.author.last.activity(
1406+
list.of.networks = networks.and.data[["networks"]], project.data = networks.and.data[["project.data"]],
1407+
activity.types = c("mails"), name = "last.activity", aggregation.level = level,
1408+
default.value = NA, combine.activity.types = FALSE
1409+
)
1410+
actual.attributes = lapply(networks.with.attributes, igraph::vertex_attr, name = "last.activity")
1411+
1412+
expect_equal(expected.attributes[[level]], actual.attributes)
1413+
})
1414+
})
1415+
10471416
#' Test the add.vertex.attribute.author.active.ranges method with computation over all types
10481417
test_that("Test add.vertex.attribute.author.active.ranges with computation over all types", {
10491418

0 commit comments

Comments
 (0)