library(testthat) test_that("strings", { q <- mathml("text") expect_equal(q, "text") }) test_that("atoms", { q <- mathml(as.symbol("atom")) expect_equal(q, "atom") }) test_that("greek", { q <- mathml(as.symbol("pi")) expect_equal(q, "π") }) test_that("calligraphy", { q <- mathml(quote(K %in% cal(K))) expect_equal(q, "KK") }) test_that("calligraphy", { q <- mathml(call("%in%", as.symbol("K"), call("cal", as.symbol("K")))) expect_equal(q, "KK") }) test_that("absx", { q <- mathml(quote(abs(x))) expect_equal(q, "|x|") }) test_that("absgreek", { q <- mathml(quote(abs(alpha))) expect_equal(q, "|α|") }) test_that("signx", { q <- mathml(quote(sign(x))) expect_equal(q, "sgnx") }) test_that("signgreek", { q <- mathml(quote(sign(alpha))) expect_equal(q, "sgnα") }) test_that("sqrtnum", { q <- mathml(quote(sqrt(2L))) expect_equal(q, "2") }) test_that("sqrtalpha", { q <- mathml(quote(sqrt(alpha))) expect_equal(q, "α") }) test_that("sin(pi/2)", { q <- mathml(quote(sin(pi/2L))) expect_equal(q, "sin(π/2)") }) test_that("cos(pi/2)", { q <- mathml(quote(cos(pi/2L))) expect_equal(q, "cos(π/2)") }) test_that("tan(pi/2)", { q <- mathml(quote(tan(pi/2L))) expect_equal(q, "tan(π/2)") }) test_that("asin(1/2*sqrt2)", { q <- mathml(quote(asin(1L/2L * sqrt(2L)))) expect_equal(q, "sin-1(1/22)") }) test_that("acos(1/2*sqrt2)", { q <- mathml(quote(acos(1L/2L * sqrt(2L)))) expect_equal(q, "cos-1(1/22)") }) test_that("atan(1/2*sqrt2)", { q <- mathml(quote(atan(1L/2L * sqrt(2L)))) expect_equal(q, "tan-1(1/22)") }) test_that("atan(1/2*sqrt3)", { q <- mathml(quote(atan(1L/2L * sqrt(3L)))) expect_equal(q, "tan-1(1/23)") }) test_that("singreek(num)", { q <- mathml(quote(sinpi(2L))) expect_equal(q, "sin(2π)") }) test_that("cosgreek(num)", { q <- mathml(quote(cospi(2L))) expect_equal(q, "cos(2π)") }) test_that("tangreek(num)", { q <- mathml(quote(tanpi(2L))) expect_equal(q, "tan(2π)") }) test_that("sinhx", { q <- mathml(quote(sinh(x))) expect_equal(q, "sinhx") }) test_that("coshx", { q <- mathml(quote(cosh(x))) expect_equal(q, "coshx") }) test_that("tanhx", { q <- mathml(quote(tanh(x))) expect_equal(q, "tanhx") }) test_that("asinhx", { q <- mathml(quote(asinh(x))) expect_equal(q, "sinh-1x") }) test_that("acoshx", { q <- mathml(quote(acosh(x))) expect_equal(q, "cosh-1x") }) test_that("atanhx", { q <- mathml(quote(atanh(x))) expect_equal(q, "tanh-1x") }) test_that("allx", { q <- mathml(quote(all(x))) expect_equal(q, "x") }) test_that("anyx", { q <- mathml(quote(any(x))) expect_equal(q, "x") }) test_that("besselInu(x)", { q <- mathml(quote(besselI(x, nu))) expect_equal(q, "Iν(x)") }) test_that("besselKnu(x)", { q <- mathml(quote(besselK(x, nu))) expect_equal(q, "Kν(x)") }) test_that("besselKnu(x)", { q <- mathml(quote(besselK(x, nu))) expect_equal(q, "Kν(x)") }) test_that("besselJnu(x)", { q <- mathml(quote(besselJ(x, nu))) expect_equal(q, "Jν(x)") }) test_that("besselYnu(x)", { q <- mathml(quote(besselY(x, nu))) expect_equal(q, "Yν(x)") }) test_that("beta(a,b)", { q <- mathml(quote(beta(a, b))) expect_equal(q, "B(a,b)") }) test_that("lbeta(a,b)", { q <- mathml(quote(lbeta(a, b))) expect_equal(q, "logB(a,b)") }) test_that("gammax", { q <- mathml(quote(gamma(x))) expect_equal(q, "Γ(x)") }) test_that("lgammax", { q <- mathml(quote(lgamma(x))) expect_equal(q, "logΓ(x)") }) test_that("digammax", { q <- mathml(quote(digamma(x))) expect_equal(q, "ddxlogΓ(x)") }) test_that("psigammax", { q <- mathml(quote(psigamma(x, deriv=psi))) expect_equal(q, "d(deriv=ψ)+2(dx)(deriv=ψ)+2logΓ(x)") }) test_that("alogb", { q <- mathml(quote(a*log(b))) expect_equal(q, "alogb") }) test_that("bloga", { q <- mathml(quote(log(b)*a)) expect_equal(q, "logba") }) test_that("sumab", { q <- mathml(quote(a*sum(b))) expect_equal(q, "ab") }) test_that("sumba", { q <- mathml(quote(sum(b)*a)) expect_equal(q, "ba") }) test_that("digammax", { q <- mathml(quote(digamma(x))) expect_equal(q, "ddxlogΓ(x)") }) test_that("trigammax", { q <- mathml(quote(trigamma(x))) expect_equal(q, "d2(dx)2logΓ(x)") }) test_that("bincoef", { q <- mathml(quote(choose(n, k))) expect_equal(q, "(nk)") }) test_that("BinCoef", { q <- mathml(quote(choose(k=K, n=N))) expect_equal(q, "(k=Kn=N)") }) test_that("logbincoef", { q <- mathml(quote(lchoose(n, k))) expect_equal(q, "log(nk)") }) test_that("factorial", { q <- mathml(quote(factorial(x))) expect_equal(q, "x!") }) test_that("lfactorial", { q <- mathml(quote(lfactorial(x))) expect_equal(q, "logx!") }) test_that("AND", { q <- mathml(quote(A & B)) expect_equal(q, "AB") }) test_that("OR", { q <- mathml(quote(A | B)) expect_equal(q, "AB") }) test_that("!A", { q <- mathml(quote(!A)) expect_equal(q, "¬A") }) test_that("xor", { q <- mathml(quote(xor(A, B))) expect_equal(q, "AB") }) test_that("expnumgreeki", { q <- mathml(quote(exp(2L*pi*i))) expect_equal(q, "exp(2πi)") }) test_that("expm1numgreeki", { q <- mathml(quote(expm1(2L*pi*i))) expect_equal(q, "exp(2πi)-1") }) test_that("logx", { q <- mathml(quote(log(x))) expect_equal(q, "logx") }) test_that("log10x", { q <- mathml(quote(log10(x))) expect_equal(q, "log10x") }) test_that("log2x", { q <- mathml(quote(log2(x))) expect_equal(q, "log2x") }) test_that("logex", { q <- mathml(quote(logb(x, e))) expect_equal(q, "logex") }) test_that("log1px", { q <- mathml(quote(log1p(x))) expect_equal(q, "log(1+x)") }) test_that("ceilingpi", { q <- mathml(quote(ceiling(pi))) expect_equal(q, "π") }) test_that("floorpi", { q <- mathml(quote(floor(pi))) expect_equal(q, "π") }) f <- as.function(alist(a=, b=2, a+b)) test_that("function", { q <- mathml(canonical(f)) expect_equal(q, "a+b") }) f <- function(x) sin(x) test_that("functionsin", { q <- mathml(canonical(f)) expect_equal(q,"sinx") }) f <- function(x) { sin(x) ; tan(x)} test_that("functionsintan", { q <- mathml(canonical(f)) expect_equal(q,"{sinxtanx") }) f <- function(x) {sin(x) ; cos(x)} test_that("functionsincos", { q <- mathml(canonical(f)) expect_equal(q,"{sinxcosx") }) test_that("identical", { q <- mathml(quote(identical(1L, 2L))) expect_equal(q,"1=2") }) test_that("ifelse", { q <- mathml(quote(ifelse(a > b, a, b))) expect_equal(q,"{aifa>bbotherwise") }) test_that("in", { q <- mathml(quote(a %in% A)) expect_equal(q,"aA") }) test_that("intersect", { q <- mathml(quote(intersect(A, B))) expect_equal(q,"AB") }) test_that("union", { q <- mathml(quote(union(A, B))) expect_equal(q,"AB") }) test_that("null", { q <- mathml(quote(is.null(intersect(A, B)))) expect_equal(q,"AB=") }) test_that("column", { q <- mathml(quote(a:b)) expect_equal(q,"a:b") }) test_that("diff", { q <- mathml(quote(setdiff(A, B))) expect_equal(q,"A-B") }) test_that("x", { q <- mathml(quote(X %x% Y)) expect_equal(q,"XY") }) test_that("expr", { q <- mathml(quote(a*b + c/d - e %*% f)) expect_equal(q,"ab+c/d-e×f") }) test_that("crossprod", { q <- mathml(quote(crossprod(A, B))) expect_equal(q,"AT×B") }) test_that("tcrossprod", { q <- mathml(quote(tcrossprod(A, B))) expect_equal(q, "A×BT") }) test_that("tilde", { q <- mathml(quote(A ~ B)) expect_equal(q,"AB") }) test_that("expx", { q <- mathml(quote(exp(x))) expect_equal(q,"expx") }) test_that("expm1x", { q <- mathml(quote(expm1(x))) expect_equal(q,"expx-1") }) test_that("dbinom", { q <- mathml(quote(dbinom(k, N, pi))) expect_equal(q,"PBi(X=k;N,π)") }) test_that("pbinom", { q <- mathml(quote(pbinom(k, N, pi))) expect_equal(q,"PBi(Xk;N,π)") }) test_that("qbinom", { q <- mathml(quote(qbinom(k, N, pi))) expect_equal(q,"argmink[PBi(Xk;N,π)>k]") }) test_that("dpois", { q <- mathml(quote(dpois(k, lambda))) expect_equal(q,"PPo(X=k;λ)") }) test_that("ppois", { q <- mathml(quote(ppois(k, lambda))) expect_equal(q,"PPo(Xk;λ)") }) test_that("qpois", { q <- mathml(quote(qpois(k, lambda))) expect_equal(q,"argmaxk[PPo(Xk;λ)>k]") }) test_that("dexp", { q <- mathml(quote(dexp(x, lambda))) expect_equal(q,"fExp(x;λ)") }) test_that("pexp", { q <- mathml(quote(pexp(x, lambda))) expect_equal(q,"FExp(x;λ)") }) test_that("qexp", { q <- mathml(quote(qexp(x, lambda))) expect_equal(q,"FExp-1(x;λ)") }) test_that("dnorm", { q <- mathml(quote(dnorm(x, mu, sigma))) expect_equal(q,"φ(x;μ,σ)") }) test_that("pnorm", { q <- mathml(quote(pnorm(x, mu, sigma))) expect_equal(q,"Φ(x;μ,σ)") }) test_that("qnorm", { q <- mathml(quote(qnorm(alpha/2))) expect_equal(q, sprintf("Φ-1(α/%s)", format(2, nsmall=getOption("digits")))) }) test_that("1mpchisq", { q <- mathml(quote(1 - pchisq(x, 1))) expect_equal(q, sprintf("%s-Fχ2(%sdf)(x)", format(1, nsmall=getOption("digits")), format(1, nsmall=getOption("digits")))) }) test_that("pchisq1malpha", { q <- mathml(quote(qchisq(1 - alpha, 1))) expect_equal(q, sprintf("Fχ2(%sdf)-1(%s-α)", format(1, nsmall=getOption("digits")), format(1, nsmall=getOption("digits")))) }) test_that("ptnm1", { q <- mathml(quote(pt(t, N - 1))) expect_equal(q, sprintf("P(Tt;N-%sdf)", format(1, nsmall=getOption("digits")))) }) test_that("qtalpha2nm1", { q <- mathml(quote(qt(alpha/2, N - 1))) expect_equal(q, sprintf("Tα/%s(N-%sdf)", format(2, nsmall=getOption("digits")), format(1, nsmall=getOption("digits")))) }) test_that("AXB", { q <- mathml(quote(A %*% B)) expect_equal(q, "A×B") }) test_that("AdotB", { q <- mathml(quote(A %.% B)) expect_equal(q, "AB") }) test_that("AxB", { q <- mathml(quote(A %x% B)) expect_equal(q, "AB") }) test_that("A/B", { q <- mathml(quote(A %/% B)) expect_equal(q, "A/B") }) test_that("A mod B", { q <- mathml(quote(A %% B)) expect_equal(q, "mod(A,B)") }) test_that("A&B", { q <- mathml(quote(A & B)) expect_equal(q, "AB") }) test_that("AvelB", { q <- mathml(quote(A | B)) expect_equal(q, "AB") }) test_that("AeqeqB", { q <- mathml(quote(A == B)) expect_equal(q, "A=B") }) test_that("AarroweqB", { q <- mathml(quote(A <- B)) expect_equal(q, "A=B") }) test_that("AdiffB", { q <- mathml(quote(A != B)) expect_equal(q, "AB") }) test_that("AtildetildeB", { q <- mathml(quote(A %~~% B)) expect_equal(q, "AB") }) test_that("AequivB", { q <- mathml(quote(A %==% B)) expect_equal(q, "AB") }) test_that("AcongB", { q <- mathml(quote(A %=~% B)) expect_equal(q, "AB") }) test_that("ApropB", { q <- mathml(quote(A %prop% B)) expect_equal(q, "AB") }) test_that("AisinB", { q <- mathml(quote(A %in% B)) expect_equal(q, "AB") }) test_that("AlrarrowB", { q <- mathml(quote(A %<->% B)) expect_equal(q, "AB") }) test_that("ArarrowB", { q <- mathml(quote(A %->% B)) expect_equal(q, "AB") }) test_that("AlarrowB", { q <- mathml(quote(A %<-% B)) expect_equal(q, "AB") }) test_that("AuparrowB", { q <- mathml(quote(A %up% B)) expect_equal(q, "AB") }) test_that("AdownarrowB", { q <- mathml(quote(A %down% B)) expect_equal(q, "AB") }) test_that("AlrdoublearrowB", { q <- mathml(quote(A %<=>% B)) expect_equal(q, "AB") }) test_that("AldoublearrowB", { q <- mathml(quote(A %<=% B)) expect_equal(q, "AB") }) test_that("ArdoublearrowB", { q <- mathml(quote(A %=>% B)) expect_equal(q, "AB") }) test_that("AupdoublearrowB", { q <- mathml(quote(A %dblup% B)) expect_equal(q, "AB") }) test_that("AdowndoublearrowB", { q <- mathml(quote(A %dbldown% B)) expect_equal(q, "AB") }) test_that("meanx", { q <- mathml(quote(mean(X))) expect_equal(q, "X¯") }) test_that("AplusminusB", { q <- mathml(quote(A %+-% B)) expect_equal(q, "A±B") }) f <- function(x) { if(x == 0L) return(0L) if(x < 0L) return(-1L) if(x > 0L) return(1L) } test_that("functionifelse", { q <- mathml(canonical(f)) expect_equal(q,"{0,ifx=0-1,ifx<01,ifx>0") }) test_that("integrate", { q <- mathml(canonical(integrate(lower=0L, upper=2L*pi, sin))) expect_equal(q, sprintf("value-%sabs.error-%ssubdivisions-1message-OKcall-integrate(f=sin,lower=0,upper=2π)", format(0, nsmall=getOption("digits")), format(0, nsmall=getOption("digits")))) }) v <- 1:3 test_that("vector", { q <- mathml(call("t", v)) expect_equal(q, "(123)T") }) A <- matrix(data=11:16, nrow=2, ncol=3) B <- matrix(data=21:26, nrow=2, ncol=3) test_that("summatrix", { q <- mathml(call("+", A, B)) expect_equal(q, "(111315121416)+(212325222426)") }) z <- function(m, s, n, tau, c, mu_A, sigma_A, mu_B, sigma_B, mu_M) dfrac(m - denote(E, ET(tau, c, mu_A, sigma_A, mu_B, sigma_B, mu_M), "the expected mean response time"), s / sqrt(n)) test_that("denoting", { q <- mathml(call("=", quote(z[tau]), z)) expect_equal(q, "zτ=m-Es/n, with E=ET(τ,c,mu_A,sigma_A,mu_B,sigma_B,mu_M) denoting the expected mean response time") }) term <- quote(dot(a, b) + frac(1L, nodot(c, d + e)) + dfrac(1L, times(g, h))) test_that("expressionmolt", { q <- mathml(term) expect_equal(q, "ab+1c(d+e)+1g×h") }) t <- quote(omit_left(a + b)) test_that("omitleft", { q <- mathml(t) expect_equal(q, "a+b") }) t <- quote(omit_right(a + b)) test_that("omitright", { q <- mathml(t) expect_equal(q, "a+b") }) t <- list(quote(a), quote(b), quote(omit(c))) test_that("omit", { q <- mathml(t) expect_equal(q, "abc") }) t <- quote(add_left(a + b)) test_that("addleft", { q <- mathml(t) expect_equal(q, "a+b") }) t <- quote(add_right(a + b)) test_that("addright", { q <- mathml(t) expect_equal(q, "a+b") }) t <- list(quote(a), quote(b), quote(add(c))) test_that("add", { q <- mathml(t) expect_equal(q, "abc") }) t <- quote(instead(a, b) + c) test_that("instead", { q <- mathml(t) expect_equal(q, "ainsteadofb+c") }) test_that("Tdiamond", { q <- mathml(quote(T^diamond)) expect_equal(q, "T") }) test_that("digits", { q <- mathml(quote(3.14159265), flags=list(quote(digits(4L)))) expect_equal(q, "3.1416") })