# tests for the path distance functions require(tsna) require(testthat) require(networkDynamicData) linegraph<-network.initialize(10) add.edges(linegraph,tail=1:9,head=2:10) data(concurrencyComparisonNets) # ----- tests for tPath ---- test_that('tPath basic tests',{ line<-network.initialize(4) add.edges.active(line,tail=1:3,head=2:4,onset=0:2,terminus=1:3) # check return format expect_equal(names(tPath(line,v=1)),c('tdist','previous','gsteps','start','end','direction','type')) expect_is(tPath(line,v=1),class = 'tPath') # check args expect_error(tPath(line,v=1,type='foo')) expect_error(tPath(line,v=1,direction='foo')) # check unimplemented expect_error(tPath(line,v=1,type='latest.depart'),regexp='method is not yet implemented') # check basic line with default earliest arriving fwd expect_equal(tPath(line,v=1)$tdist,c(0, 0, 1, 2)) expect_equal(tPath(line,v=2)$tdist,c(Inf,0,1,2)) # test starting and ending flags expect_equal(tPath(line,v=1,start=0.5)$tdist, c(0,0,0.5,1.5)) expect_equal(tPath(line,v=1,start=2)$tdist, c(0,Inf,Inf,Inf)) expect_equal(tPath(line,v=1,end=2)$tdist, c(0,0,1,Inf)) line<-network.initialize(4) add.edges.active(line,tail=1:3,head=2:4,onset=c(2,1,3),terminus=c(3,2,4)) expect_equal(tPath(line,v=1)$tdist,c(0,1,Inf,Inf)) # test active default test<-as.networkDynamic(network.initialize(4)) add.edges(test,1:3,2:4) expect_equal(tPath(test,v=1,start=0)$tdist,c(0,0,0,0)) expect_equal(tPath(test,v=1,active.default=FALSE,start=0)$tdist,c(0,Inf,Inf,Inf)) test<-network.initialize(4) add.edges(test,1:3,3:4) activate.edges(test,e=1,at=2) # test start message test<-as.networkDynamic(network.initialize(4)) expect_message(tPath(test,v=1),regexp="'start' time parameter for paths was not specified") # test wrong object expect_error(tPath(network.initialize(3)),regexp='first argument must be a networkDynamic object') # test no v specified expect_error(tPath(as.networkDynamic(network.initialize(2)),regexp='argument with valid vertex ids was not given')) # test on network size 0 expect_equal(tPath(as.networkDynamic(network.initialize(0)),start=0,v=numeric(0))$tdist,numeric(0)) }) # ----- tests for forward earliest paths ---- test_that("path in large base network matches",{ fwdDFS<-tPath(base,v=24) expect_equal(sum(fwdDFS$tdist0) pathset<-which(tPath(base,v=24,graph.step.time=1)$tdist