Skip to content

Commit

Permalink
Add tests on character relational operations
Browse files Browse the repository at this point in the history
The Ops tests now cover the majority of the happy path cases.

Fixes #295.
  • Loading branch information
joshuaulrich committed May 12, 2019
1 parent 6a2eb5d commit 842d6c2
Showing 1 changed file with 54 additions and 19 deletions.
73 changes: 54 additions & 19 deletions inst/unitTests/runit.Ops.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
numeric.modes <- c("double", "integer", "logical")#, "complex")
all.modes <- c("double", "integer", "logical", "character")
ops.math <- c("+", "-", "*", "/", "^", "%%", "%/%")
ops.logic <- c("&", "|", ">", ">=", "==", "!=", "<=", "<")
ops.relation <- c(">", ">=", "==", "!=", "<=", "<")
ops.logic <- c("&", "|", ops.relation)
all.ops <- c(ops.math, ops.logic)

ops_numeric_tester <-
Expand All @@ -20,7 +21,9 @@ test.ops_xts2d_matrix2d_dimnames <- function() {
colnames(M2) <- rev(colnames(M2))

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -47,7 +50,9 @@ test.ops_xts2d_matrix2d_only_colnames <- function() {
colnames(M2) <- rev(colnames(M2))

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand Down Expand Up @@ -75,7 +80,9 @@ test.ops_xts2d_matrix2d_only_rownames <- function() {
colnames(M2) <- rev(colnames(M2))

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -99,7 +106,9 @@ test.ops_xts2d_matrix2d_no_dimnames <- function() {
M1 <- coredata(X1) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -126,7 +135,9 @@ test.ops_xts1d_matrix1d_dimnames <- function() {
colnames(M2) <- "y"

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -152,7 +163,9 @@ test.ops_xts1d_matrix1d_only_colnames <- function() {
colnames(M2) <- "y"

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -178,7 +191,9 @@ test.ops_xts1d_matrix1d_only_rownames <- function() {
rownames(M1) <- format(.POSIXct(1:3))

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -202,7 +217,9 @@ test.ops_xts1d_matrix1d_no_dimnames <- function() {
M1 <- coredata(X1) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, M1, m, o)
E <- X1
Expand All @@ -224,7 +241,9 @@ test.ops_xts1d_xts1d <- function() {
X1 <- .xts(1:3, 1:3, dimnames = list(NULL, "x"))

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next
e <- ops_numeric_tester(X1, X1, m, o)
E <- X1
E[] <- ops_numeric_tester(coredata(X1), coredata(X1), m, o)
Expand All @@ -239,7 +258,9 @@ test.ops_xts1d_xts1d_different_index <- function() {
X2 <- .xts(2:4, 2:4, dimnames = list(NULL, "y"))

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, X2, m, o)
E <- X1[2:3,]
Expand All @@ -264,7 +285,9 @@ test.ops_xts2d_vector_no_names <- function() {
V1 <- as.vector(coredata(X1[,1L])) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, V1, m, o)
E <- X1
Expand All @@ -287,7 +310,9 @@ test.ops_xts2d_vector_names <- function() {
V1 <- setNames(as.vector(X1[,1L]), index(X1)) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, V1, m, o)
E <- X1
Expand All @@ -310,7 +335,9 @@ test.ops_xts1d_vector_no_names <- function() {
V1 <- as.vector(coredata(X1[,1L])) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, V1, m, o)
E <- X1
Expand All @@ -333,7 +360,9 @@ test.ops_xts1d_vector_names <- function() {
V1 <- setNames(as.vector(X1[,1L]), index(X1)) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(X1, V1, m, o)
E <- X1
Expand All @@ -359,7 +388,9 @@ test.ops_xts_no_dim_matrix1d <- function() {
M1 <- coredata(X1) * 5

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(Xv, M1, m, o)
E <- X1
Expand All @@ -384,7 +415,9 @@ test.ops_xts_no_dim_matrix2d <- function() {
M2 <- coredata(X2)

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(Xv, M2, m, o)
E <- X2
Expand All @@ -410,7 +443,9 @@ test.ops_xts_no_dim_vector <- function() {
V1 <- 4:6

for (o in all.ops) {
for (m in numeric.modes) {
for (m in all.modes) {
if ("character" == m && !(o %in% ops.relation))
next

e <- ops_numeric_tester(Xv, V1, m, o)
E <- Xv
Expand Down

0 comments on commit 842d6c2

Please sign in to comment.