test_that("Read normal metadata", {
meta.dir <- tempdir()
info <- list(
id = "test",
name = "test metadata",
clusters = c(0, 0, 1),
clusterName = c("Unassigned", "A"),
clusterLength = c(2, 1),
type = "category",
history = list(CreateCommit())
)
jsonlite::write_json(info, file.path(meta.dir, "test.json"), auto_unbox=TRUE)
jsonlite::write_json(list(
content = list(test = info),
version = 1,
default = 'test'
), file.path(meta.dir, "metalist.json"), auto_unbox=TRUE)
meta <- Metadata$new(meta.dir, JSONFile)
data <- meta$get("test")
expect_equal(length(data), 3)
expect_equal(length(levels(data)), 2)
})
test_that("Read old metadata", {
meta.dir <- tempdir()
info <- list(
id = "test",
name = "test metadata",
clusters = c(0, 0, 1),
clusterName = c("Unassigned", "A"),
clusterLength = c(2, 1),
type = "category",
history = list(CreateCommit())
)
jsonlite::write_json(info, file.path(meta.dir, "test.json"), auto_unbox=TRUE)
jsonlite::write_json(list(test = info), file.path(meta.dir, "metalist.json"), auto_unbox=TRUE)
meta <- Metadata$new(meta.dir, JSONFile)
data <- meta$get("test")
expect_equal(length(data), 3)
expect_equal(length(levels(data)), 2)
})
test_that("Read data no type", {
meta.dir <- tempdir()
info <- list(
id = "test",
name = "test metadata",
clusters = c(0, 0, 1),
clusterName = c("Unassigned", "A"),
clusterLength = c(2, 1),
history = list(CreateCommit())
)
jsonlite::write_json(info, file.path(meta.dir, "test.json"), auto_unbox=TRUE)
jsonlite::write_json(list(
content = list(test = info),
version = 1,
default = 'test'
), file.path(meta.dir, "metalist.json"), auto_unbox=TRUE)
meta <- Metadata$new(meta.dir, JSONFile)
data <- meta$get("test")
expect_equal(length(data), 3)
expect_equal(length(levels(data)), 2)
})
test_that("Read data no id", {
meta.dir <- tempdir()
info <- list(
name = "test metadata",
clusters = c(0, 0, 1),
clusterName = c("Unassigned", "A"),
clusterLength = c(2, 1),
history = list(CreateCommit())
)
jsonlite::write_json(info, file.path(meta.dir, "test.json"), auto_unbox=TRUE)
jsonlite::write_json(list(
content = list(test = info),
version = 1,
default = 'test'
), file.path(meta.dir, "metalist.json"), auto_unbox=TRUE)
meta <- Metadata$new(meta.dir, JSONFile)
data <- meta$get("test")
expect_equal(length(data), 3)
expect_equal(length(levels(data)), 2)
})
test_that("Read data no info", {
meta.dir <- tempdir()
info <- list(
name = "test metadata",
clusters = c(0, 0, 1),
clusterName = c("Unassigned", "A"),
clusterLength = c(2, 1),
history = list(CreateCommit())
)
jsonlite::write_json(info$clusters, file.path(meta.dir, "test.json"), auto_unbox=TRUE)
jsonlite::write_json(list(test = info), file.path(meta.dir, "metalist.json"), auto_unbox=TRUE)
meta <- Metadata$new(meta.dir, JSONFile)
data <- meta$get("test")
expect_equal(length(data), 3)
expect_equal(length(levels(data)), 2)
})
test_that("Duplicates in metadata", {
meta.dir <- tempdir()
metalist <- file.path(meta.dir, "metalist.json")
if (file.exists(metalist)) file.remove(metalist)
meta <- Metadata$new(meta.dir, JSONFile)
id <- meta$add(c("a", "Unassigned ", NA), "test")
data.r <- meta$get(id)
expect_equal(length(levels(data.r)), 2)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.