
def test01():
    __cdbkernel__=create_scope()
    \delta{#}::KroneckerDelta.
    obj1:= 2*a*\delta^{i1 j1 i2 j2};
    expand_delta(_)
    distribute(_)
    tst1:= a*\delta^{i1 j1}\delta^{i2 j2}-a*\delta^{i2 j1}\delta^{i1 j2}-@(obj1);
    assert(tst1==0)
    print('Test 01 passed')

test01()
    
def test02():
    __cdbkernel__=create_scope()
    \delta{#}::KroneckerDelta.
    n::Integer(0..d).
    obj2:= a*\delta_{n n};
    eliminate_kronecker(_)
    tst2:= a*(d+1) - @(obj2);
    assert(tst2==0)
    print('Test 02 passed')

test02()

def test03():
    __cdbkernel__=create_scope()
    \delta{#}::KroneckerDelta.
    ex:= \delta_{m?}_{-n?} \delta^{\mu\nu};
    eliminate_kronecker(_)
    tst:= \delta_{m?}_{-n?} \delta^{\mu\nu} - @(ex);
    assert(tst==0)
    print('Test 03 passed')

test03()

def test04():
    __cdbkernel__=create_scope()
    {A,B}::Weight(label=field);
    C::Weight(label=field, value=2);
    ex:=A B B + A A A + A B + A C + B;
    drop_weight(_, $field=3$)
    tst:= A B + B - @(ex);
    assert(tst==0)
    print("Test 04 passed")

test04()

def test05():
    __cdbkernel__=create_scope()
    \delta{#}::KroneckerDelta;
    {r,s,t}::Indices(position=fixed);
    \partial{#}::PartialDerivative;
    ex:=\partial^{r}{a} \partial_{r}{a};
    substitute(ex, $\partial^{r}{a} = \delta^{r}_{0} \partial^{0}{a}, \partial_{r}{a} = \delta_{r}^{0} \partial_{0}{a}$)
    eliminate_kronecker(ex)
    tst:= \partial^{0}{a} \partial_{0}{a} - @(ex);
    assert(tst==0)
    print("Test 05 passed")

test05()

def test06():        
    __cdbkernel__=create_scope()
    {a,b,c}::Indices(name=A, position=free);
    {m,n,p}::Indices(name=B, position=fixed);
    ex:=A_{a b 3 m} B^{a b m};
    lower_free_indices(_)
    tst:=A_{a b 3 m} B_{a b}^{m} - @(ex);
    assert(tst==0)
    print("Test 06a passed")
    raise_free_indices(ex)
    tst:=A^{a b}_{3 m} B^{a b m} - @(ex);
    assert(tst==0)
    print("Test 06b passed")

test06()
        
# \delta{#}::KroneckerDelta.
# \eps_{#}::EpsilonTensor(delta=\delta).
# F_{q r s a b c}::TableauSymmetry(shape={1,1}, indices={0,1}, shape={1,1,1}, indices={3,4,5}).
# obj6:= \eps_{m n q} \eps_{r s t} F_{b1 b2 b3 m n q};
# epsilon_to_delta(_);
# expand_delta(_);

def test07():
    __cdbkernel__=create_scope() 
    {a,b,c,d,e,f,g,h#}::Indices.
    x::Coordinate;
    {A^{a},B^{a}}::Weight(label=eps,value=0).
    B{#}::Depends(x);
    ex:=B^{a};
    keep_weight(_, $eps=1$)
    assert(ex==0)

test07()
        

def test08():
    __cdbkernel__=create_scope() 
    ex:= A_{m} A_{m};
    einsteinify(_)
    tst:= A^{m} A_{m} - @(ex);
    assert(tst==0)
    print("Test 08a passed")        
    ex:= A^{m} A^{m};
    einsteinify(_)
    tst:= A_{m} A^{m} - @(ex);
    assert(tst==0)
    print("Test 08b passed")        
    {m,n,p,q}::Indices.
    ex:= A_{m} A_{m};
    einsteinify(_, $\eta$)
    tst:= A_{m} A_{n} \eta^{m n} - @(ex);
    assert(tst==0)
    print("Test 08c passed")        
    ex:= A^{m} A^{m};
    einsteinify(_, $\eta$)
    tst:= A_{m} A_{n} \eta^{m n} - @(ex);
    assert(tst==0)
    print("Test 08d passed")        
    ex:= A_{m n} A_{m n};
    einsteinify(_, $\eta$)
    tst:= A_{m n} A_{p q} \eta^{m p} \eta^{n q} - @(ex);
    assert(tst==0)
    print("Test 08e passed")        

test08()

def test09():
    __cdbkernel__=create_scope() 
    N::Integer;
    {i,j}::Indices(vector);
    {i,j}::Integer(1..N);
    g_{i j}::Metric;
    g^{i j}::InverseMetric;
    g_{i}^{j}::KroneckerDelta;
    ex:= g_{i}^{i}:
    eliminate_kronecker(_)
    tst:= N - @(ex);
    assert(tst==0)
    print("Test 09a passed")        
    ex:= N = g_{i}^{i};
    eliminate_kronecker(_)
    tst:= (N = N) - @(ex);
    assert(tst==$0=0$)
    print("Test 09b passed")

test09()

def test10():
    __cdbkernel__=create_scope()
    {i,j,k,l}::Indices(vector);
    {i,j,k,l}::Integer(1..3);
    \delta{#}::KroneckerDelta;
    \epsilon_{i j k}::EpsilonTensor(delta=\delta);
    ex:= \epsilon_{i j j} \epsilon_{i k l} + \epsilon_{i j k} \epsilon_{i j l};
    epsilon_to_delta(_)
    expand_delta(_)
    tst:= 2 \delta_{k l} - @(ex);
    assert(tst==0)
    print("Test 10 passed")

test10()

def test11():
    __cdbkernel__=create_scope()
    {a,b,c,d,e}::Indices(vector1);
    {a,b,c,d,e}::Integer(1..3);
    {p,q,r,s,t}::Indices(vector2);
    {p,q,r,s,t}::Integer(1..3);
    \delta{#}::KroneckerDelta;
    \epsilon_{a b c}::EpsilonTensor(delta=\delta);
    E_{p q r}::EpsilonTensor(delta=\delta);
    ex:= \epsilon_{a b c} E_{p q r} \epsilon_{a d e};
    epsilon_to_delta(_)
    tst:= 2 E_{p q r} \delta_{b d c e} - @(ex);
    assert(tst==0)
    print("Test 11 passed")

test11()

def test12():
    {a,b,c,d,e,j}::Indices;
    {a,b,c,d,e,j}::Integer(1..3);
    {d{#}}::KroneckerDelta;
    {e_{a b c}}::EpsilonTensor(delta=d);
    ex :=  e_{a j b} e_{j 3 c};
    epsilon_to_delta(_)
    tst:= -2 d_{a 3 b c} - @(ex);
    assert(tst==0)
    print("Test 12 passed")

test12()
        
def test13():
    {a,b,c,i,j,k}::Indices;
    {a,b,c,i,j,k}::Integer(1..3);
    {d{#}}::KroneckerDelta;
    {e_{a b c}}::EpsilonTensor(delta=d);
    ex := e_{a j 3} e_{a k 3} n_{j} n_{k};
    epsilon_to_delta(_)
    tst:= 2 d_{j k 3 3} n_{j} n_{k} - @(ex);
    assert(tst==0)
    print("Test 13a passed")
    expand_delta(ex)
    distribute(ex)
    eliminate_kronecker(ex)
    tst:= n_{k} n_{k} - n_{3} n_{3} - @(ex);
    assert(tst==0)
    print("Test 13b passed")
    
test13()

        
