From f3202a6f96723d11c170346556d036cf087521c8 Mon Sep 17 00:00:00 2001 From: Leo Sendelbach Date: Tue, 9 Jan 2024 16:18:51 +0100 Subject: [PATCH] Add tests for get.author.names.from.networks Signed-off by: Leo Sendelbach --- tests/test-util-networks-misc.R | 160 ++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 tests/test-util-networks-misc.R diff --git a/tests/test-util-networks-misc.R b/tests/test-util-networks-misc.R new file mode 100644 index 00000000..585fb2a4 --- /dev/null +++ b/tests/test-util-networks-misc.R @@ -0,0 +1,160 @@ +## This file is part of coronet, which 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, version 2. +## +## This program 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, write to the Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +## +## Copyright 2019 by Jakob Kronawitter +## Copyright 2019 by Claus Hunsen +## Copyright 2019 by Thomas Bock +## Copyright 2022 by Thomas Bock +## Copyright 2019 by Christian Hechtl +## Copyright 2021 by Christian Hechtl +## All Rights Reserved. + + +context("Tests for the file 'util-networks-misc.R'") + +## +## Context +## + +CF.DATA = file.path(".", "codeface-data") +CF.SELECTION.PROCESS = "testing" +CASESTUDY = "test" +ARTIFACT = "feature" + +## use only when debugging this file independently +if (!dir.exists(CF.DATA)) CF.DATA = file.path(".", "tests", "codeface-data") + +test_that("getting all authors of a list of networks, list length 0", { + + ## Act + result = get.author.names.from.networks(networks = list(), globally = TRUE) + + ## Assert + expected = list(c()) + + expect_equal(expected, result) +}) + +test_that("getting all authors of a list of networks, list length 1", { + + ## Arrange + vertices = data.frame( + name = c("Heinz", "Dieter", "Klaus"), + kind = TYPE.AUTHOR, + type = TYPE.AUTHOR + ) + edges = data.frame( + from = "Heinz", + to = "Dieter" + ) + network = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices) + + ## Act + result = get.author.names.from.networks(networks = list(network)) + + ## Assert + expected = list(c("Dieter", "Heinz", "Klaus")) + + expect_equal(expected, result) + +}) + +test_that("getting all authors of a list of networks, list length 1, not global", { + + ## Arrange + vertices = data.frame( + name = c("Heinz", "Dieter", "Klaus"), + kind = TYPE.AUTHOR, + type = TYPE.AUTHOR + ) + edges = data.frame( + from = "Heinz", + to = "Dieter" + ) + network = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices) + + ## Act + result = get.author.names.from.networks(networks = list(network), globally = FALSE) + + ## Assert + expected = list(c("Dieter", "Heinz", "Klaus")) + + expect_equal(expected, result) + +}) + +test_that("getting all authors of a list of networks, list length 2", { + + ## Arrange + vertices = data.frame( + name = c("Heinz", "Dieter", "Klaus"), + kind = TYPE.AUTHOR, + type = TYPE.AUTHOR + ) + edges = data.frame( + from = "Heinz", + to = "Dieter" + ) + first.network = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices) + + second.vertices = data.frame( + name = c("Detlef", "Dieter"), + kind = TYPE.AUTHOR, + type = TYPE.AUTHOR + ) + second.edges = data.frame( + from = "Detlef", + to = "Dieter" + ) + second.network = igraph::graph.data.frame(second.edges, directed = FALSE, vertices = second.vertices) + ## Act + result = get.author.names.from.networks(networks = list(first.network, second.network)) + + ## Assert + expected = list(c("Detlef", "Dieter", "Heinz", "Klaus")) + + expect_equal(expected, result) +}) + +test_that("getting all authors of a list of networks, list length 2, not global", { + + ## Arrange + vertices = data.frame( + name = c("Heinz", "Dieter", "Klaus"), + kind = TYPE.AUTHOR, + type = TYPE.AUTHOR + ) + edges = data.frame( + from = "Heinz", + to = "Dieter" + ) + first.network = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices) + + second.vertices = data.frame( + name = c("Detlef", "Dieter"), + kind = TYPE.AUTHOR, + type = TYPE.AUTHOR + ) + second.edges = data.frame( + from = "Detlef", + to = "Dieter" + ) + second.network = igraph::graph.data.frame(second.edges, directed = FALSE, vertices = second.vertices) + ## Act + result = get.author.names.from.networks(networks = list(first.network, second.network), globally = FALSE) + + ## Assert + expected = list(c("Dieter", "Heinz", "Klaus"), c("Detlef", "Dieter")) + + expect_equal(expected, result) +}) \ No newline at end of file