R version 4.4.0 RC (2024-04-16 r86468 ucrt) -- "Puppy Cup" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## This file is part of SimInf, a framework for stochastic > ## disease spread simulations. > ## > ## Copyright (C) 2015 -- 2023 Stefan Widgren > ## > ## SimInf is free software: you can redistribute it and/or modify > ## it under the terms of the GNU General Public License as published by > ## the Free Software Foundation, either version 3 of the License, or > ## (at your option) any later version. > ## > ## SimInf is distributed in the hope that it will be useful, > ## but WITHOUT ANY WARRANTY; without even the implied warranty of > ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > ## GNU General Public License for more details. > ## > ## You should have received a copy of the GNU General Public License > ## along with this program. If not, see . > > library(SimInf) > library(tools) > source("util/check.R") > > ## Define a tolerance > tol <- 1e-8 > > edges <- data.frame( + from = c(2, 3, 4, 1, 4, 5, 1, 3, 1, 3), + to = c(1, 1, 1, 2, 3, 3, 4, 4, 5, 5), + rate = c(0.2, 0.01, 0.79, 1, 0.2, 0.05, 0.2, 0.8, 0.2, 0.8), + count = c(5, 5, 5, 50, 10, 10, 5, 5, 5, 5)) > > m_exp <- matrix(c(1, 0.2, 5, 2, 0.01, 5, 3, 0.79, 5, -1, 0, 1, 50, -1, + NaN, NaN, NaN, NaN, NaN, NaN, 3, 0.2, 10, 4, 0.05, + 10, -1, NaN, NaN, NaN, 0, 0.2, 5, 2, 0.8, 5, -1, + NaN, NaN, NaN, 0, 0.2, 5, 2, 0.8, 5, -1, NaN, NaN, + NaN, -1, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, + NaN), + nrow = 10L, + ncol = 6L) > > m_obs <- edge_properties_to_matrix(edges, 6) > > > stopifnot(identical(length(m_obs), length(m_exp))) > stopifnot(all(abs(m_obs[is.finite(m_obs)] - m_exp[is.finite(m_exp)]) < tol)) > > edges$from[1] <- NaN > res <- assertError(edge_properties_to_matrix(edges, 6)) > check_error(res, "Values in 'edges' must be numeric and finite.") > > edges$from[1] <- 2.2 > res <- assertError(edge_properties_to_matrix(edges, 6)) > check_error(res, "'edges' contain invalid 'from -> to' indices.") > > edges$from[1] <- 0 > res <- assertError(edge_properties_to_matrix(edges, 6)) > check_error(res, "'edges' contain invalid 'from -> to' indices.") > > edges$from[1] <- 2 > edges <- rbind(edges[1, ], edges) > res <- assertError(edge_properties_to_matrix(edges, 6)) > check_error(res, "'edges' contain duplicated properties.") > > proc.time() user system elapsed 0.82 0.12 0.93