Skip to content

Commit

Permalink
Add tests for convert.adjacency.matrix.list.to.array
Browse files Browse the repository at this point in the history
Signed-off by: Leo Sendelbach <s8lesend@stud.uni-saarland.de>
  • Loading branch information
Leo-Send committed Jan 9, 2024
1 parent 7335c3d commit 6b600df
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/test-util-networks-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,95 @@ test_that("getting cumulative sums of adjacency matrices generated from networks
## Assert
compare.sparse.matrices(matrix.out.one, result[[1]])
compare.sparse.matrices(matrix.out.two, result[[2]])
})

test_that("getting cumulative sums of adjacency matrices generated from networks,
two networks, then convert to array", {

## Arrange
vertices = data.frame(
name = c("Heinz", "Dieter", "Klaus"),
kind = TYPE.AUTHOR,
type = TYPE.AUTHOR
)
edges = data.frame(
from = c("Heinz", "Dieter", "Dieter"),
to = c("Dieter", "Klaus", "Heinz")
)
network.in.one = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices)
authors.in.one = sort(c("Heinz", "Dieter", "Klaus"))

edges = data.frame(
from = c("Klaus"),
to = c("Dieter")
)
network.in.two = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices)

expected.array = array(data = 0, dim = c(3, 3, 2))
rownames(expected.array) = authors.in.one
colnames(expected.array) = authors.in.one

expected.array[1, 2, 1] = 1
expected.array[1, 3, 1] = 1
expected.array[2, 1, 1] = 1
expected.array[3, 1, 1] = 1

expected.array[1, 2, 2] = 1
expected.array[1, 3, 2] = 1
expected.array[2, 1, 2] = 1
expected.array[3, 1, 2] = 1

## Act
result.adjacency = get.expanded.adjacency.cumulated(networks = list(network.in.one, network.in.two))
result.array = convert.adjacency.matrix.list.to.array(result.adjacency)

## Assert
expect_equal(expected.array, result.array)
})

test_that("getting cumulative sums of adjacency matrices generated from networks,
two networks, weighted, then convert to array", {

## Arrange
vertices = data.frame(
name = c("Heinz", "Dieter", "Klaus"),
kind = TYPE.AUTHOR,
type = TYPE.AUTHOR
)
edges = data.frame(
from = c("Heinz", "Dieter", "Dieter"),
to = c("Dieter", "Klaus", "Heinz"),
weight = c(1, 2, 1)
)
network.in.one = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices)
authors.in.one = sort(c("Heinz", "Dieter", "Klaus"))

edges = data.frame(
from = c("Klaus"),
to = c("Dieter"),
weight = c(1)
)
network.in.two = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices)
authors.in.two = sort(c("Heinz", "Dieter", "Klaus"))

expected.array = array(data = 0, dim = c(3, 3, 2))
rownames(expected.array) = authors.in.one
colnames(expected.array) = authors.in.one

expected.array[1, 2, 1] = 2
expected.array[1, 3, 1] = 2
expected.array[2, 1, 1] = 2
expected.array[3, 1, 1] = 2

expected.array[1, 2, 2] = 2
expected.array[1, 3, 2] = 3
expected.array[2, 1, 2] = 2
expected.array[3, 1, 2] = 3

## Act
result.adjacency = get.expanded.adjacency.cumulated(networks = list(network.in.one, network.in.two), weighted = TRUE)
result.array = convert.adjacency.matrix.list.to.array(result.adjacency)

## Assert
expect_equal(expected.array, result.array)
})

0 comments on commit 6b600df

Please sign in to comment.