diff --git a/tests/contact-chain.R b/tests/contact-chain.R index 4426257..d98f54a 100644 --- a/tests/contact-chain.R +++ b/tests/contact-chain.R @@ -34,10 +34,10 @@ movements <- structure(list(source = 1:7, destination = c(4L, 5L, 5L, "t"), class = "data.frame", row.names = c(NA, -7L)) ct <- Trace(movements, root = 8L, - inBegin = as.Date('2010-08-22'), - inEnd = as.Date('2010-10-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-22"), + inEnd = as.Date("2010-10-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) ct stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 7L)) stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 0L)) @@ -54,10 +54,10 @@ NA_integer_)), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -4L), class = "data.frame") ct <- Trace(movements, root = 4L, - inBegin = as.Date('2010-07-22'), - inEnd = as.Date('2010-08-21'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-07-22"), + inEnd = as.Date("2010-08-21"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) ct stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 3L)) stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 0L)) @@ -73,10 +73,10 @@ c(NA_character_, NA_character_ ), n = c(NA_integer_, NA_integer_)), = c(NA, -2L), class = "data.frame") ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-09-01'), - outEnd = as.Date('2010-10-01')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-09-01"), + outEnd = as.Date("2010-10-01")) ct stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 1L)) stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 0L)) @@ -95,10 +95,10 @@ NA_integer_)), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -7L ), class = "data.frame") ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-11-09')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-11-09")) ct stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 0L)) stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 7L)) @@ -114,10 +114,10 @@ c(NA_character_, NA_character_ ), n = c(NA_integer_, NA_integer_)), = c(NA, -2L), class = "data.frame") ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-07-02'), - inEnd = as.Date('2010-08-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-07-02"), + inEnd = as.Date("2010-08-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) ct stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 0L)) stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 1L)) @@ -134,10 +134,10 @@ class = "factor")), .Names = c("source", "destination", "t"), class = "data.frame", row.names = c(NA, -7L)) ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-10-10'), - inEnd = as.Date('2010-10-20'), - outBegin = as.Date('2010-10-10'), - outEnd = as.Date('2010-10-20')) + inBegin = as.Date("2010-10-10"), + inEnd = as.Date("2010-10-20"), + outBegin = as.Date("2010-10-10"), + outEnd = as.Date("2010-10-20")) ct stopifnot(identical(IngoingContactChain(ct)$ingoingContactChain, 0L)) stopifnot(identical(OutgoingContactChain(ct)$outgoingContactChain, 2L)) diff --git a/tests/degree.R b/tests/degree.R index d26b2f1..45b0789 100644 --- a/tests/degree.R +++ b/tests/degree.R @@ -37,10 +37,10 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), ct <- Trace(movements, root = 4L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) stopifnot(identical(InDegree(ct)$inDegree, 1L)) stopifnot(identical(OutDegree(ct)$outDegree, 0L)) @@ -56,7 +56,7 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -4L), class = "data.frame") -ns <- NetworkSummary(movements, root = 4, tEnd = '2010-09-01', days = 30) +ns <- NetworkSummary(movements, root = 4, tEnd = "2010-09-01", days = 30) stopifnot(identical(ns$inDegree, 1L)) ## @@ -70,7 +70,7 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -4L), class = "data.frame") -ns <- NetworkSummary(movements, root = 4, tEnd = '2010-08-31', days = 30) +ns <- NetworkSummary(movements, root = 4, tEnd = "2010-08-31", days = 30) stopifnot(identical(ns$outDegree, 0L)) ## @@ -86,10 +86,10 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), ct <- Trace(movements, root = 4L, - inBegin = as.Date('2010-08-27'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-27"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) stopifnot(identical(InDegree(ct)$inDegree, 0L)) stopifnot(identical(OutDegree(ct)$outDegree, 0L)) @@ -105,7 +105,7 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -4L), class = "data.frame") -ns <- NetworkSummary(movements, root = 4, tEnd = '2010-09-01', days = 5) +ns <- NetworkSummary(movements, root = 4, tEnd = "2010-09-01", days = 5) stopifnot(identical(ns$inDegree, 0L)) ## @@ -119,7 +119,7 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -4L), class = "data.frame") -ns <- NetworkSummary(movements, root = 4, tEnd = '2010-08-31', days = 30) +ns <- NetworkSummary(movements, root = 4, tEnd = "2010-08-31", days = 30) stopifnot(identical(ns$outDegree, 0L)) ## @@ -135,10 +135,10 @@ movements <- structure(list(source = c("1", "1", "1"), ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) stopifnot(identical(InDegree(ct)$inDegree, 0L)) stopifnot(identical(OutDegree(ct)$outDegree, 3L)) @@ -154,7 +154,7 @@ movements <- structure(list(source = c("1", "1", "1"), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -3L), class = "data.frame") -ns <- NetworkSummary(movements, root = 1, tEnd = '2010-09-01', days = 30) +ns <- NetworkSummary(movements, root = 1, tEnd = "2010-09-01", days = 30) stopifnot(identical(ns$inDegree,0L)) ## @@ -168,7 +168,7 @@ movements <- structure(list(source = c("1", "1", "1"), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -3L), class = "data.frame") -ns <- NetworkSummary(movements, root = 1, tEnd = '2010-08-31', days = 30) +ns <- NetworkSummary(movements, root = 1, tEnd = "2010-08-31", days = 30) stopifnot(identical(ns$outDegree, 3L)) ## @@ -184,10 +184,10 @@ movements <- structure(list(source = c("1", "1", "1"), ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-16')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-16")) stopifnot(identical(InDegree(ct)$inDegree, 0L)) stopifnot(identical(OutDegree(ct)$outDegree, 2L)) @@ -203,7 +203,7 @@ movements <- structure(list(source = c("1", "1", "1"), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -3L), class = "data.frame") -ns <- NetworkSummary(movements, root = 1, tEnd = '2010-09-01', days = 30) +ns <- NetworkSummary(movements, root = 1, tEnd = "2010-09-01", days = 30) stopifnot(identical(ns$inDegree, 0L)) ## @@ -217,5 +217,5 @@ movements <- structure(list(source = c("1", "1", "1"), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -3L), class = "data.frame") -ns <- NetworkSummary(movements, root = 1, tEnd = '2010-08-16', days = 15) +ns <- NetworkSummary(movements, root = 1, tEnd = "2010-08-16", days = 15) stopifnot(identical(ns$outDegree, 2L)) diff --git a/tests/misc.R b/tests/misc.R index 7511f38..7ee2f33 100644 --- a/tests/misc.R +++ b/tests/misc.R @@ -29,34 +29,34 @@ library(EpiContactTrace) ## movements <- data.frame(source = c(2L, 2L), destination = c(1L, 2L), - t = as.Date(c('2010-10-03', '2010-10-02'))) + t = as.Date(c("2010-10-03", "2010-10-02"))) ct <- Trace(movements, root = 1L, - inBegin = as.Date('2010-09-30'), - inEnd = as.Date('2010-10-05'), - outBegin = as.Date('2010-10-05'), - outEnd = as.Date('2010-10-10')) + inBegin = as.Date("2010-09-30"), + inEnd = as.Date("2010-10-05"), + outBegin = as.Date("2010-10-05"), + outEnd = as.Date("2010-10-10")) -stopifnot(identical(ct@ingoingContacts@source, '2')) -stopifnot(identical(ct@ingoingContacts@destination, '1')) +stopifnot(identical(ct@ingoingContacts@source, "2")) +stopifnot(identical(ct@ingoingContacts@destination, "1")) ## ## Loops: Case 2 ## movements <- data.frame(source = c(2L, 2L), destination = c(1L, 2L), - t = as.Date(c('2010-10-03', '2010-10-02'))) + t = as.Date(c("2010-10-03", "2010-10-02"))) ct <- Trace(movements, root = 2L, - inBegin = as.Date('2010-09-30'), - inEnd = as.Date('2010-10-05'), - outBegin = as.Date('2010-09-30'), - outEnd = as.Date('2010-10-10')) + inBegin = as.Date("2010-09-30"), + inEnd = as.Date("2010-10-05"), + outBegin = as.Date("2010-09-30"), + outEnd = as.Date("2010-10-10")) -stopifnot(identical(ct@outgoingContacts@source, '2')) -stopifnot(identical(ct@outgoingContacts@destination, '1')) +stopifnot(identical(ct@outgoingContacts@source, "2")) +stopifnot(identical(ct@outgoingContacts@destination, "1")) ## ## Direction: Case 1 @@ -70,13 +70,13 @@ movements <- structure(list(source = 1:7, ct <- Trace(movements, root = 4L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) -stopifnot(identical(ct@ingoingContacts@direction, 'in')) -stopifnot(identical(ct@outgoingContacts@direction, 'out')) +stopifnot(identical(ct@ingoingContacts@direction, "in")) +stopifnot(identical(ct@outgoingContacts@direction, "out")) ## ## Direction: Case 2 @@ -92,13 +92,13 @@ movements <- structure(list(source = c(1L, 2L, 3L, 3L), ct <- Trace(movements, root = 4L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) -stopifnot(identical(ct@ingoingContacts@direction, 'in')) -stopifnot(identical(ct@outgoingContacts@direction, 'out')) +stopifnot(identical(ct@ingoingContacts@direction, "in")) +stopifnot(identical(ct@outgoingContacts@direction, "out")) ## ## Root not in movements: Case 1 @@ -114,10 +114,10 @@ movements <- structure(list(source = c("1", "1", "1"), ct <- Trace(movements, root = 15L, - inBegin = as.Date('2010-08-02'), - inEnd = as.Date('2010-09-01'), - outBegin = as.Date('2010-08-01'), - outEnd = as.Date('2010-08-31')) + inBegin = as.Date("2010-08-02"), + inEnd = as.Date("2010-09-01"), + outBegin = as.Date("2010-08-01"), + outEnd = as.Date("2010-08-31")) stopifnot(identical(InDegree(ct)$inDegree, 0L)) stopifnot(identical(OutDegree(ct)$outDegree, 0L)) @@ -134,7 +134,7 @@ movements <- structure(list(source = c("1", "1", "1"), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -3L), class = "data.frame") -ns <- NetworkSummary(movements, root = 15, tEnd = '2010-09-01', days = 30) +ns <- NetworkSummary(movements, root = 15, tEnd = "2010-09-01", days = 30) stopifnot(identical(ns$inDegree, 0L)) ## @@ -149,7 +149,7 @@ movements <- structure(list(source = c("1", "1", "1"), .Names = c("source", "destination", "t", "individual", "n"), row.names = c(NA, -3L), class = "data.frame") -ns <- NetworkSummary(movements, root = 15, tEnd = '2010-08-31', days = 30) +ns <- NetworkSummary(movements, root = 15, tEnd = "2010-08-31", days = 30) stopifnot(identical(ns$outDegree, 0L)) ## @@ -296,25 +296,25 @@ movements <- structure(list(source = c("2019", "2019", "2019", "2019", "2019", 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L), class = "data.frame") -ct.1 <- Trace(movements, 2645, '2005-10-31', 90) -ct.1.df <- as(ct.1, 'data.frame') +ct.1 <- Trace(movements, 2645, "2005-10-31", 90) +ct.1.df <- as(ct.1, "data.frame") -ct.2 <- Trace(ct.1.df, 2645, '2005-10-31', 90) -ct.2.df <- as(ct.2, 'data.frame') +ct.2 <- Trace(ct.1.df, 2645, "2005-10-31", 90) +ct.2.df <- as(ct.2, "data.frame") -ct.1.df <- ct.1.df[, c('source', - 'destination', - 't', - 'id', - 'n', - 'category')] +ct.1.df <- ct.1.df[, c("source", + "destination", + "t", + "id", + "n", + "category")] -ct.2.df <- ct.2.df[, c('source', - 'destination', - 't', - 'id', - 'n', - 'category')] +ct.2.df <- ct.2.df[, c("source", + "destination", + "t", + "id", + "n", + "category")] ct.1.df <- ct.1.df[order(ct.1.df$source, ct.1.df$destination, diff --git a/tests/network-summary.R b/tests/network-summary.R index 868993a..9d9274e 100644 --- a/tests/network-summary.R +++ b/tests/network-summary.R @@ -30,15 +30,15 @@ data(transfers) ## load(file=system.file("extdata", "ns.rda", package="EpiContactTrace")) root <- sort(unique(c(transfers$source, transfers$destination))) -result <- NetworkSummary(transfers, root=root, tEnd='2005-10-31', days=90) +result <- NetworkSummary(transfers, root=root, tEnd="2005-10-31", days=90) stopifnot(identical(result, ns)) ## ## Case 2 ## -ns <- NetworkSummary(transfers, root=584, tEnd='2005-10-31', days=91) +ns <- NetworkSummary(transfers, root=584, tEnd="2005-10-31", days=91) ns.trace <- NetworkSummary(Trace(transfers, root=584, - tEnd='2005-10-31', + tEnd="2005-10-31", days=91)) stopifnot(identical(ns, ns.trace)) diff --git a/tests/shortest-paths.R b/tests/shortest-paths.R index 12eda30..9ff23b3 100644 --- a/tests/shortest-paths.R +++ b/tests/shortest-paths.R @@ -28,17 +28,17 @@ data(transfers) ## ## Case 1 ## -sp.1 <- ShortestPaths(transfers, root=2645, tEnd='2005-10-31', days=90) -sp.2 <- ShortestPaths(Trace(movements=transfers, root=2645, tEnd='2005-10-31', days=90)) -in.1 <- sp.1[sp.1$direction == 'in', c('source', 'distance')] -in.2 <- sp.2[sp.2$direction == 'in', c('source', 'distance')] +sp.1 <- ShortestPaths(transfers, root=2645, tEnd="2005-10-31", days=90) +sp.2 <- ShortestPaths(Trace(movements=transfers, root=2645, tEnd="2005-10-31", days=90)) +in.1 <- sp.1[sp.1$direction == "in", c("source", "distance")] +in.2 <- sp.2[sp.2$direction == "in", c("source", "distance")] in.1 <- in.1[order(in.1$source, in.1$distance),] in.2 <- in.2[order(in.2$source, in.2$distance),] rownames(in.1) <- NULL rownames(in.2) <- NULL stopifnot(identical(in.1, in.2)) -out.1 <- sp.1[sp.1$direction == 'out', c('destination', 'distance')] -out.2 <- sp.2[sp.2$direction == 'out', c('destination', 'distance')] +out.1 <- sp.1[sp.1$direction == "out", c("destination", "distance")] +out.2 <- sp.2[sp.2$direction == "out", c("destination", "distance")] out.1 <- out.1[order(out.1$destination, out.1$distance),] out.2 <- out.2[order(out.2$destination, out.2$distance),] rownames(out.1) <- NULL @@ -54,8 +54,8 @@ sp.in.exp <- structure(list(root = c("100", "100", "100", "100", "100"), .Names = c("root", "source", "distance"), row.names = c(NA, -5L), class = "data.frame") -sp.in <- ShortestPaths(Trace(movements=transfers, root=100, tEnd='2005-10-31', days=90)) -sp.in <- sp.in[sp.in$direction == 'in', c('root', 'source', 'distance')] +sp.in <- ShortestPaths(Trace(movements=transfers, root=100, tEnd="2005-10-31", days=90)) +sp.in <- sp.in[sp.in$direction == "in", c("root", "source", "distance")] sp.in <- sp.in[order(as.numeric(sp.in$source)),] rownames(sp.in) <- NULL stopifnot(identical(sp.in, sp.in.exp)) @@ -68,8 +68,8 @@ sp.out.exp <- structure(list( distance = c(1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L)), .Names = c("root", "destination", "distance"), row.names = c(NA, -14L), class = "data.frame") -sp.out <- ShortestPaths(Trace(movements=transfers, root=100, tEnd='2005-10-31', days=90)) -sp.out <- sp.out[sp.out$direction == 'out', c('root', 'destination', 'distance')] +sp.out <- ShortestPaths(Trace(movements=transfers, root=100, tEnd="2005-10-31", days=90)) +sp.out <- sp.out[sp.out$direction == "out", c("root", "destination", "distance")] sp.out <- sp.out[order(as.numeric(sp.out$destination)),] rownames(sp.out) <- NULL stopifnot(identical(sp.out, sp.out.exp))