From 355760654a820c3ff7ac02b99393ac2f43664ec0 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Wed, 18 Dec 2024 15:43:02 +0000 Subject: [PATCH] Expand testing --- R/dsl-differentiate-expr.R | 2 +- tests/testthat/test-dsl-differentiation.R | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/R/dsl-differentiate-expr.R b/R/dsl-differentiate-expr.R index 2810b912..32d0debc 100644 --- a/R/dsl-differentiate-expr.R +++ b/R/dsl-differentiate-expr.R @@ -164,7 +164,7 @@ derivative <- list( } ## Have to resort to some actual calculation here, sadly: - call("if", fold("&&", i[!j]), 1, 0) + call("if", maths$fold("&&", i[!j]), 1, 0) }, exp = function(expr, name) { a <- maths$rewrite(expr[[2]]) diff --git a/tests/testthat/test-dsl-differentiation.R b/tests/testthat/test-dsl-differentiation.R index f527a7fa..bd870cd3 100644 --- a/tests/testthat/test-dsl-differentiation.R +++ b/tests/testthat/test-dsl-differentiation.R @@ -461,6 +461,9 @@ test_that("differentiate expressions with arrays", { expect_equal(differentiate(quote((x[i] - x[i + 1])^2), "x"), quote(2 * (x[i] - x[1 + i]))) expect_equal(differentiate(quote(x[i] - x[i + 1]), "x"), 1) + + expect_equal(differentiate(quote(3 * (x[2] - x[i])), "x"), + quote(3 * ((if (2 == i) 1 else 0) - 1))) })