Skip to content

Commit

Permalink
get toJSON tests passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
d-callan committed Jan 30, 2024
1 parent 7d3caec commit 06ffea1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/methods-KPartiteNetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ toJSONGeneric <- getGeneric("toJSON", package = "veupathUtils")
#' @export
setMethod(toJSONGeneric, "Partitions", function(object, named = c(TRUE, FALSE)) {
named <- veupathUtils::matchArg(named)
tmp <- veupathUtils::S4SimpleListToJSON(object, FALSE)
tmp <- veupathUtils::S4SimpleListToJSON(object, TRUE)

if (named) tmp <- paste0('{"partitions":', tmp, "}")

Expand All @@ -39,7 +39,7 @@ setMethod(toJSONGeneric, "KPartiteNetwork", function(object, named = c(TRUE, FAL

nodes_json <- veupathUtils::toJSON(object@nodes, named = FALSE)
links_json <- veupathUtils::toJSON(object@links, named = FALSE)
partitions_json <- veupathUtils::toJSON(object@partitions, named = TRUE)
partitions_json <- veupathUtils::toJSON(object@partitions, named = FALSE)

# TODO this doesnt conform to the api in the data service, bc there we explicitly have a bipartite network and not a kpartite
# we have `columns1NodeIds` and `columns2NodeIds` instead of `partitions`. i think this is better though.
Expand Down
2 changes: 1 addition & 1 deletion R/methods-Nodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ setMethod(toJSONGeneric, signature("NodeIdList"), function(object, named = c(TRU
if (named) tmp <- paste0('{"nodeIds":', tmp, "}")

return(tmp)
})
})
12 changes: 6 additions & 6 deletions tests/testthat/test-kpartite-network.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ test_that("toJSON works for k-partite networks", {
)
json <- veupathUtils::toJSON(net)
jsonList <- jsonlite::fromJSON(json)
expect_equal(jsonList$network$data$links$source, c('A','B','C'))
expect_equal(jsonList$network$data$links$target, c('B','A','D'))
expect_equal(jsonList$network$data$links$weight, c(10,20,30))
expect_equal(jsonList$network$data$nodes$id, c('A','B','C','D'))
expect_equal(list(jsonList$network$data$partitions[1,],jsonList$network$data$partitions[2,]), list(c('A','C'), c('B','D')))
expect_equal(length(jsonList$network$config$variables), 0)
expect_equal(jsonList$bipartitenetwork$data$links$source, c('A','B','C'))
expect_equal(jsonList$bipartitenetwork$data$links$target, c('B','A','D'))
expect_equal(jsonList$bipartitenetwork$data$links$weight, c(10,20,30))
expect_equal(jsonList$bipartitenetwork$data$nodes$id, c('A','B','C','D'))
expect_equal(jsonList$bipartitenetwork$data$partitions$nodeIds, list(c('A','C'), c('B','D')))
expect_equal(length(jsonList$bipartitenetwork$config$variables), 0)
})

test_that("we can build a KPartiteNetwork from an edgeList data.frame", {
Expand Down

0 comments on commit 06ffea1

Please sign in to comment.