Skip to content

Commit

Permalink
Expand testing
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Dec 18, 2024
1 parent c2f1cf1 commit 3557606
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/dsl-differentiate-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-dsl-differentiation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})


Expand Down

0 comments on commit 3557606

Please sign in to comment.