
# Tests for the connection to a Mathematica kernel.

def test01():
    ex:= \alpha \beta \cos{\gamma \Delta}:
    out=ex.mma_form()
    tst="α*β*Cos[γ*Δ]"
    assert(out==tst)
    print("Test 01a passed")
    out=ex.mma_form(unicode=False)
    tst="\[Alpha]*\[Beta]*Cos[\[Gamma]*\[CapitalDelta]]"
    assert(out==tst)
    print("Test 01b passed")
    out=ex.mma_form(unicode=True)
    tst="α*β*Cos[γ*Δ]"
    assert(out==tst)
    print("Test 01c passed")

test01()

def test02():
    ex:= \cos{\alpha}**2 + \sin{2 \alpha}**2;
    map_mma(ex)
    tst:= \cos{\alpha}**2 + \sin{2 \alpha}**2 - @(ex);
    assert(tst==0)
    print("Test 02a passed")
    ex:= \cos{x}**2 + \sin{x}**2;
    map_mma(ex, "FullSimplify")
    tst:=1 - @(ex);
    assert(tst==0)
    print("Test 02b passed")
#ex:=Integrate( \sin{x} + x**2, {x,0,\pi} );
#map_mma(ex);

test02()

def test03():
    __cdbkernel__=create_scope()
    r::Coordinate;
    \partial{#}::PartialDerivative;
    ex:= \partial_{r}{ r**2 + \sin{r} };
    map_mma(ex, "FullSimplify")
    tst:= 2 r + \cos{r} - @(ex);
    assert(tst==0)
    print("Test 03 passed")

test03()
#ex:= (a*\cos{\theta})**2;
#map_mma(ex);

def test04():
    __cdbkernel__=create_scope()
    kernel(scalar_backend="mathematica")
    ex:=\sin(x)**2 + \cos(x)**2;
    simplify(_)
    assert(ex==1)
    print("Test 04 passed")

test04()

def test05():
    kernel(scalar_backend="mathematica")
    {r,t}::Coordinate;
    {a,b,c,d,e}::Indices(values={r,t});
    \partial{#}::PartialDerivative;
    f::Depends(r,t);
    rl:= { g_{r r} = f r**2 };
    ex:= \Gamma_{a b c} = \partial_{a}{ g_{b c} };
    evaluate(ex, rl, rhsonly=True)
    c1=ex[1][3][1][1]
    tst:=@(c1) - r (r\partial_{r}{f} + 2 f);
    distribute(tst)
    assert(tst==0)
    print("Test 05a passed")
    c2=ex[1][3][0][1]
    tst:=@(c2) - r**2 \partial_{t}{f};
    distribute(tst)
    assert(tst==0)
    print("Test 05b passed")

test05()
    

    
