Skip to content

Commit 6c05404

Browse files
committed
Update runit.sugar.var.R
(Feature) Add tests for complex variance computation (unimplemented in R -- thus, comparing against known synthetic cases). (Refactoring) Introduce names in test cases replacing magic numbers (improves Travis CI reports readability), apply DRY to test data, robustify.
1 parent e5584aa commit 6c05404

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

inst/unitTests/runit.sugar.var.R

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@
2323
if (.runThisTest) {
2424

2525
test.Sugar.var <- function() {
26-
f1 <- Rcpp::cppFunction('double myVar(NumericVector x) { return(var(x)); }')
27-
f2 <- Rcpp::cppFunction('double myVar(IntegerVector x) { return(var(x)); }')
28-
f3 <- Rcpp::cppFunction('double myVar(ComplexVector x) { return(var(x)); }')
29-
f4 <- Rcpp::cppFunction('double myVar(LogicalVector x) { return(var(x)); }')
30-
checkEquals(f1((1:10) * 1.1), var((1:10) * 1.1))
31-
checkEquals(f2(1:10), var(1:10))
32-
checkEquals(f3(1:10 + (1 + 1i)), var(1:10 + (1 + 1i)))
33-
checkEquals(f4(c(T, F, T, F, T)), var(c(T, F, T, F, T)))
26+
fNumeric <- Rcpp::cppFunction('double myVar(NumericVector x) { return(var(x)); }')
27+
fInteger <- Rcpp::cppFunction('double myVar(IntegerVector x) { return(var(x)); }')
28+
fComplex <- Rcpp::cppFunction('double myVar(ComplexVector x) { return(var(x)); }')
29+
fLogical <- Rcpp::cppFunction('double myVar(LogicalVector x) { return(var(x)); }')
30+
test_data_real <- 1:10
31+
checkEquals(fNumeric(test_data_real * 1.1), var(test_data_real * 1.1))
32+
checkEquals(fInteger(test_data_real), var(test_data_real))
33+
test_data_complex_1 <- complex(real = 5:1, imag = 2:6)
34+
test_data_complex_2 <- complex(real = 1:5, imag = 6:10)
35+
test_data_complex_1_known_var <- 5
36+
test_data_complex_2_known_var <- 5
37+
checkEquals(fComplex(test_data_complex_1), test_data_complex_1_known_var)
38+
checkEquals(fComplex(test_data_complex_2), test_data_complex_2_known_var)
39+
test_data_logical <- c(TRUE, FALSE, TRUE, FALSE, TRUE)
40+
checkEquals(fLogical(test_data_logical), var(test_data_logical))
3441
}
3542

3643
}

0 commit comments

Comments
 (0)