From 00d45a74e8fb5944d6fb870c19c31dede13cf92e Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Wed, 18 Dec 2024 17:25:17 +0000 Subject: [PATCH] Fix tests --- R/dsl-differentiate-expr.R | 2 +- tests/testthat/test-dsl-differentiation.R | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/R/dsl-differentiate-expr.R b/R/dsl-differentiate-expr.R index 32d0debc..780a2e0b 100644 --- a/R/dsl-differentiate-expr.R +++ b/R/dsl-differentiate-expr.R @@ -288,7 +288,7 @@ maths <- local({ fn == "[" || (length(except) > 0 && fn %in% except) || "unary_minus" %in% except && .is_unary_minus(x) - if (pass) { + if (fn != "if" && pass) { return(x) } call("(", x) diff --git a/tests/testthat/test-dsl-differentiation.R b/tests/testthat/test-dsl-differentiation.R index bd870cd3..03c4786b 100644 --- a/tests/testthat/test-dsl-differentiation.R +++ b/tests/testthat/test-dsl-differentiation.R @@ -454,22 +454,21 @@ test_that("can diferentiate basic trig functions", { test_that("differentiate expressions with arrays", { - expect_equal(differentiate(quote(x[i] + y[i]), "x"), 1) - expect_equal(differentiate(quote(x[i] + y[i]), "z"), 0) - expect_equal(differentiate(quote(x[i]^2), "x"), quote(2 * x[i])) + expect_identical(differentiate(quote(x[i] + y[i]), "x"), 1) + expect_identical(differentiate(quote(x[i] + y[i]), "z"), 0) + expect_identical(differentiate(quote(x[i]^2), "x"), quote(2 * x[i])) - 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))) + expect_identical(differentiate(quote((x[i] - x[i + 1])^2), "x"), + quote(2 * (x[i] - x[1 + i]))) + expect_identical(differentiate(quote(x[i] - x[i + 1]), "x"), 1) + expect_identical(differentiate(quote(3 * (x[i] - x[2])), "x"), + quote(3 * (1 - (if (2 == i) 1 else 0)))) }) test_that("differentiate expressions with arrays", { - expect_equal(differentiate(quote(sum(x)), "x"), 1) - expect_equal(differentiate(quote(sum(x)), "y"), 0) + expect_identical(differentiate(quote(sum(x)), "x"), 1) + expect_identical(differentiate(quote(sum(x)), "y"), 0) })