Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asizemore committed Nov 2, 2023
1 parent e206d09 commit 74b9ac7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
15 changes: 8 additions & 7 deletions R/class-Link.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ check_link_list <- function(object) {

errors <- character()

# If one link has a color, all must have colors
if (any(unlist(lapply(object, function(x) {!is.null(color(x))})))) {
if (all(unlist(lapply(object, function(x) {!is.null(color(x))})))) {
# If one link has a color, all must have colors
if (!all(unlist(lapply(object, function(x) {!is.null(color(x))})))) {
errors <- c(errors, "If one link has a color, all links must have a color")
}

# Link colors must be all the same class
if (length(unique(unlist(lapply(object, function(x) {class(color(x))})))) > 1) {
errors <- c(errors, "Link colors must be all the same class")
}
}

# Link colors must be all the same class
if (unique(unlist(lapply(ll, function(x) {class(color(x))})) > 1)) {
errors <- c(errors, "Link colors must be all the same class")
}

# If one link has a weight, all must have weights
if (any(unlist(lapply(object, function(x) {!is.null(weight(x))})))) {
if (all(unlist(lapply(object, function(x) {!is.null(weight(x))})))) {
if (!all(unlist(lapply(object, function(x) {!is.null(weight(x))})))) {
errors <- c(errors, "If one link has a weight, all links must have a weight")
}
}
Expand Down
15 changes: 8 additions & 7 deletions R/class-Node.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,25 @@ check_node_list <- function(object) {

errors <- character()

# If one node has a color, all must have colors
if (any(unlist(lapply(object, function(x) {!is.null(color(x))})))) {
if (all(unlist(lapply(object, function(x) {!is.null(color(x))})))) {
# If one node has a color, all must have colors
if (!all(unlist(lapply(object, function(x) {!is.null(color(x))})))) {
errors <- c(errors, "If one node has a color, all nodes must have a color")
}

# Node colors must be all the same class
if (length(unique(unlist(lapply(object, function(x) {class(color(x))})))) > 1) {
errors <- c(errors, "Node colors must be all the same class")
}
}

# If one node has a weight, all must have weights
if (any(unlist(lapply(object, function(x) {!is.null(weight(x))})))) {
if (all(unlist(lapply(object, function(x) {!is.null(weight(x))})))) {
if (!all(unlist(lapply(object, function(x) {!is.null(weight(x))})))) {
errors <- c(errors, "If one node has a weight, all nodes must have a weight")
}
}

# Node colors must be all the same class
if (unique(unlist(lapply(object, function(x) {class(color(x))})) > 1)) {
errors <- c(errors, "Node colors must be all the same class")
}

return(if (length(errors) == 0) TRUE else errors)
}
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ test_that("Node methods work", {
id = 'A'
)
expect_equal(id(nodeA), 'A')
expect_equal(color(nodeA), character())
expect_equal(weight(nodeA), numeric())
expect_equal(color(nodeA), NULL)
expect_equal(weight(nodeA), NULL)

nodeB <- Node(
id = 'B',
Expand Down Expand Up @@ -35,8 +35,8 @@ test_that("NodeList methods work", {
nodeList <- NodeList(S4Vectors::SimpleList(c(nodeA, nodeB, nodeC)))
expect_equal(length(nodeList), 3)
expect_equal(getNodeIds(nodeList), c('A', 'B', 'C'))
expect_equal(getWeights(nodeList), c(numeric(), numeric(), numeric()))
expect_equal(getColors(nodeList), c(character(), character(), character()))
expect_equal(getWeights(nodeList), c(NULL, NULL, NULL))
expect_equal(getColors(nodeList), c(NULL, NULL, NULL))


# Create more interesting nodes
Expand Down

0 comments on commit 74b9ac7

Please sign in to comment.