Skip to content

Commit b97cc52

Browse files
author
cafreeman
committed
Add checkStructField utility
Makes it easier to check StructFields
1 parent 3381e5c commit b97cc52

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

R/pkg/inst/tests/test_sparkSQL.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ library(testthat)
1919

2020
context("SparkSQL functions")
2121

22+
# Utility function for easily checking the values of a StructField
23+
checkStructField <- function(actual, expectedName, expectedType, expectedNullable) {
24+
expect_equal(class(actual), "structField")
25+
expect_equal(actual$name(), expectedName)
26+
expect_equal(actual$dataType.toString(), expectedType)
27+
expect_equal(actual$nullable(), expectedNullable)
28+
}
29+
2230
# Tests for SparkSQL functions in SparkR
2331

2432
sc <- sparkR.init()
@@ -54,11 +62,8 @@ test_that("infer types", {
5462
list(type = 'array', elementType = "integer", containsNull = TRUE))
5563
testStruct <- infer_type(list(a = 1L, b = "2"))
5664
expect_true(class(testStruct) == "structType")
57-
expect_true(length(testStruct$fields()) == 2)
58-
testSF <- testStruct$fields()[[1]]
59-
expect_true(class(testSF) == "structField")
60-
expect_true(testSF$name() == "a")
61-
expect_true(testSF$dataType.toString() == "IntegerType")
65+
checkStructField(testStruct$fields()[[1]], "a", "IntegerType", TRUE)
66+
checkStructField(testStruct$fields()[[2]], "b", "StringType", TRUE)
6267
e <- new.env()
6368
assign("a", 1L, envir = e)
6469
expect_equal(infer_type(e),

0 commit comments

Comments
 (0)