Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3ceb99
commit 2d527d9
Showing
29 changed files
with
272 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
context("flatten") | ||
|
||
|
||
test_that("flattening", { | ||
x <- list(test = data.frame(foo=1:3)) | ||
x$test$bar <- data.frame(x=5:3, y=7:9) | ||
expect_that(x, equals(fromJSON(toJSON(x), flatten = FALSE))); | ||
expect_that(names(fromJSON(toJSON(x), flatten = TRUE)$test), equals(c("foo", "bar.x", "bar.y"))) | ||
expect_equal(x, fromJSON(toJSON(x), flatten = FALSE)); | ||
expect_equal(names(fromJSON(toJSON(x), flatten = TRUE)$test), c("foo", "bar.x", "bar.y")); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
context("fromJSON Array") | ||
|
||
|
||
test_that("fromJSON Array, row major", { | ||
|
||
# test high dimensional arrays | ||
lapply(2:5, function(n){ | ||
object <- array(1:prod(n), dim=1:n) | ||
newobject <- fromJSON(toJSON(object)); | ||
expect_that(object, equals(newobject)); | ||
expect_equal(object, newobject); | ||
}); | ||
|
||
# adding some flat dimensions | ||
lapply(1:5, function(n){ | ||
object <- array(1:prod(n), dim=c(1:n, 1)) | ||
newobject <- fromJSON(toJSON(object)); | ||
expect_that(object, equals(newobject)); | ||
}); | ||
expect_equal(object, newobject); | ||
}); | ||
}); | ||
|
||
test_that("fromJSON Array, column major", { | ||
|
||
# test high dimensional arrays | ||
lapply(2:5, function(n){ | ||
object <- array(1:prod(n), dim=1:n) | ||
newobject <- fromJSON(toJSON(object, matrix="columnmajor"), columnmajor=TRUE); | ||
expect_that(object, equals(newobject)); | ||
expect_equal(object, newobject); | ||
}); | ||
|
||
# adding some flat dimensions | ||
lapply(1:5, function(n){ | ||
object <- array(1:prod(n), dim=c(1:n, 1)) | ||
newobject <- fromJSON(toJSON(object, matrix="columnmajor"), columnmajor=TRUE); | ||
expect_that(object, equals(newobject)); | ||
}); | ||
expect_equal(object, newobject); | ||
}); | ||
}); | ||
|
||
|
||
test_that("fromJSON Array, character strings", { | ||
|
||
# test high dimensional arrays | ||
lapply(2:5, function(n){ | ||
object <- array(paste("cell", 1:prod(n)), dim=1:n) | ||
newobject <- fromJSON(toJSON(object, matrix="columnmajor"), columnmajor=TRUE); | ||
expect_that(object, equals(newobject)); | ||
expect_equal(object, newobject); | ||
}); | ||
|
||
# adding some flat dimensions | ||
lapply(1:5, function(n){ | ||
object <- array(paste("cell", 1:prod(n)), dim=c(1:n, 1)) | ||
newobject <- fromJSON(toJSON(object, matrix="columnmajor"), columnmajor=TRUE); | ||
expect_that(object, equals(newobject)); | ||
}); | ||
expect_equal(object, newobject); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
context("fromJSON datasets") | ||
|
||
|
||
# Note about numeric precision | ||
# In the unit tests we use digits=10. Lowever values will result in problems for some datasets | ||
test_that("fromJSON datasets", { | ||
objects <- Filter(is.data.frame, lapply(ls("package:datasets"), get)); | ||
|
||
#data frames are never identical because: | ||
# - attributes | ||
# - attributes | ||
# - factors, times, dates turn into strings | ||
# - integers turn into numeric | ||
lapply(objects, function(object){ | ||
newobject <- fromJSON(toJSON(object)) | ||
expect_that(newobject, is_a("data.frame")); | ||
expect_that(names(object), is_identical_to(names(newobject))); | ||
expect_that(nrow(object), is_identical_to(nrow(newobject))) | ||
expect_s3_class(newobject, "data.frame"); | ||
expect_identical(names(object), names(newobject)); | ||
expect_identical(nrow(object), nrow(newobject)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
context("libjson Large strings") | ||
|
||
|
||
test_that("escaping and parsing of special characters", { | ||
|
||
#create random strings | ||
mychars <- c('a', 'b', " ", '"', "\\", "\t", "\n", "'", "/", "#", "$"); | ||
createstring <- function(length){ | ||
paste(mychars[ceiling(runif(length, 0, length(mychars)))], collapse="") | ||
} | ||
} | ||
|
||
#try some very long strings | ||
for(i in 1:10){ | ||
zz <- list(foo=createstring(1e5)) | ||
expect_that(zz, equals(fromJSON(toJSON(zz)))); | ||
expect_equal(zz, fromJSON(toJSON(zz))); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
context("libjson Validator") | ||
|
||
|
||
test_that("test that the validator properly deals with escaped characters", { | ||
|
||
|
Oops, something went wrong.