UNB/ CS/ David Bremner/ teaching/ cs2613/ tests/ q3-tests.py
def zero(i,j):
    return 0
def test_zero():
    M=Matrix(3,3, zero)
    assert M[0] == [0,0,0] and M[1] == [0,0,0] and M[2] == [0,0,0]

def row(i,j):
    return i+1
def test_row():
    M=Matrix(3,3, row)
    assert M[0] == [1,1,1] and M[1] == [2,2,2] and M[2] == [3,3,3]

def eye(i,j):
    return (1 if i==j else 0)
def test_eye():
    M=Matrix(3,3, eye)
    assert M[0] == [1,0,0] and  M[1] == [0,1,0] and  M[2] == [0,0,1]

def plus(i,j):
    return i+j
def test_big():
    M=Matrix(100,100, plus)
    expected = []; out = []
    for i in range(100):
        out.append(M[i])
        expected.append(list(range(i,100+i)))
    assert expected == out

def test_iter1():
    M=Matrix(3,3, row)
    assert list(M) == [[1,2,3], [1,2,3], [1,2,3]]

def test_iter_twice():
    M=Matrix(3,3, row)
    assert list(M) == [[1,2,3], [1,2,3], [1,2,3]]
    assert list(M) == [[1,2,3], [1,2,3], [1,2,3]]
    
def colfun(i,j):
    return j
def test_iter_big():
    rows=40
    cols=30
    M=Matrix(rows,cols, colfun)
    out = []
    for col in M:
        out.append(col)
    assert [ list(j for i in range(rows)) for j in range(cols) ] == out