from nose.tools import raises
from csympy.lib.csympy_wrapper import (densematrix, Symbol, Integer,
    function_symbol, I)

def test_get():
    A = densematrix(2, 2, [1, 2, 3, 4])

    assert A.get(0, 0) == 1
    assert A.get(0, 1) == 2
    assert A.get(1, 1) == 4

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = densematrix(2, 2, [a, b, c, d])

    assert A.get(0, 0) == a
    assert A.get(1, 0) == c
    assert A.get(1, 1) == d

def test_set():
    i7 = Integer(7)
    y = Symbol("y")
    g = function_symbol("g", y)
    c = 2*I + 3
    A = densematrix(2, 2,
        [Integer(5), Symbol("x"), function_symbol("f", Symbol("x")), 1 + I])

    A.set(0, 0, i7)
    assert A.get(0, 0) == i7
    A.set(0, 1, y)
    assert A.get(0, 1) == y
    A.set(1, 0, g)
    assert A.get(1, 0) == g
    A.set(1, 1, c)
    A.get(1, 1) == c

def test_det():
    A = densematrix(2, 2, [1, 2, 3, 4])
    assert A.det() == -2

    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")
    d = Symbol("d")
    A = densematrix(2, 2, [a, b, c, d])
    assert A.det() == a*d - b*c

@@ -1091,8 +1091,969 @@
 d - b*c%0A
+%0Adef test_inv():%0A    A = densematrix(2, 2, %5B1, 0, 0, 1%5D)%0A    assert A.inv() == A%0A%0A    A = densematrix(2, 2, %5B1, 2, 2, 3%5D)%0A    assert A.inv() == densematrix(2, 2, %5B-3, 2, 2, -1%5D)%0A%0Adef test_add_matrix():%0A    A = densematrix(2, 2, %5B1, 2, 3, 4%5D)%0A    B = densematrix(2, 2, %5B1, 0, 0, 1%5D)%0A%0A    assert A.add_matrix(B) == densematrix(2, 2, %5B2, 2, 3, 5%5D)%0A%0A    a = Symbol(%22a%22)%0A    b = Symbol(%22b%22)%0A    c = Symbol(%22c%22)%0A    d = Symbol(%22d%22)%0A    A = densematrix(2, 2, %5Ba + b, a - b, a, b%5D)%0A    B = densematrix(2, 2, %5Ba - b, a + b, -a, b%5D)%0A%0A    assert A.add_matrix(B) == densematrix(2, 2, %5B2*a, 2*a, 0, 2*b%5D)%0A%0Adef test_mul_matrix():%0A    A = densematrix(2, 2, %5B1, 2, 3, 4%5D)%0A    B = densematrix(2, 2, %5B1, 0, 0, 1%5D)%0A%0A    assert A.mul_matrix(B) == A%0A%0A    a = Symbol(%22a%22)%0A    b = Symbol(%22b%22)%0A    c = Symbol(%22c%22)%0A    d = Symbol(%22d%22)%0A    A = densematrix(2, 2, %5Ba, b, c, d%5D)%0A    B = densematrix(2, 2, %5B1, 0, 1, 0%5D)%0A%0A    assert A.mul_matrix(B) == densematrix(2, 2, %5Ba + b, 0, c + d, 0%5D)%0A

Add tests