# Cubic Spline/1002/test_lu.py

```import unittest
from Numeric import *
from Matrix import *
from LuDecomposition import *

class TestLuDecomposition(unittest.TestCase):
def setUp(self):
self.a = [[1.0,2.0,3.0],[4.0,5.0,6.0],[7.0,8.0,9.0]]
self.matrixA = Matrix(array(self.a))

def testLwrite(self):
ld = LuDecomposition(self.a)
col = 0
ld._writeL(col)
self.assertEquals(ld._getL(), [[1,0,0],[4,0,0],[7,0,0]])

def testUwrite(self):
ld = LuDecomposition(self.a)
col = 0
ld._writeL(col)
row = 0
ld._writeU(row)
self.assertEquals(ld._getU(), [[1,2.0,3.0],[0,1,0], [0,0,1]])

def testLuDecMore(self):
ld = LuDecomposition(self.a)
ld._writeL(0)
ld._writeU(0)
self.assertEquals(ld._getL(), [[1,0,0],[4,0,0],[7,0,0]])
self.assertEquals(ld._getU(), [[1,2,3],[0,1,0], [0,0,1]])
ld._writeL(1)
ld._writeU(1)
self.assertEquals(ld._getL(), [[1,0,0],[4,-3,0],[7,-6,0]])
self.assertEquals(ld._getU(), [[1,2,3],[0,1,2], [0,0,1]])
ld._writeL(2)
ld._writeU(2)
self.assertEquals(ld._getL(), [[1,0,0],[4,-3,0],[7,-6,0]])
self.assertEquals(ld._getU(), [[1,2,3],[0,1,2], [0,0,1]])

def testLuDecomposition(self):
l, u = LuDecomposition(self.a).perform()
matrixL = Matrix(array(l))
matrixU = Matrix(array(u))
actual = matrixL * matrixU
self.assertEquals(str(actual), str(self.matrixA))

if __name__=="__main__":
unittest.main()
```