#format python """Unit Test for nussinov""" import unittest from nussinov import NussinovMatrix, Nussinov sample = 'GGGAAAUCC' class TestDataStructure(unittest.TestCase): def testStack(self): mystack = [1,2,3,4,5] mystack.pop() mystack.append('push') self.assertEqual(mystack, [1,2,3,4,'push']) class TestNussinovMatrix(unittest.TestCase): def testInitialNussinovMatrix(self): matrix = NussinovMatrix(sample) initialMatrix = [[ 0,'n','n','n','n','n','n','n','n'], [ 0, 0,'n','n','n','n','n','n','n'], ['n', 0, 0,'n','n','n','n','n','n'], ['n','n', 0, 0,'n','n','n','n','n'], ['n','n','n', 0, 0,'n','n','n','n'], ['n','n','n','n', 0, 0,'n','n','n'], ['n','n','n','n','n', 0, 0,'n','n'], ['n','n','n','n','n','n', 0, 0,'n'], ['n','n','n','n','n','n','n', 0, 0]] self.assertEqual(matrix.getInitialMatrix(), initialMatrix) def testScorePair(self): matrix = NussinovMatrix(sample) self.assertEqual(matrix.score(1, 9), 1) def testScoreNonPair(self): matrix = NussinovMatrix(sample) self.assertEqual(matrix.score(1, 2), 0) def testFinalNussinovMatrix(self): finalMatrix = [[ 0, 0, 0, 0, 0, 0, 1, 2, 3], [ 0, 0, 0, 0, 0, 0, 1, 2, 3], ['n', 0, 0, 0, 0, 0, 1, 2, 2], ['n','n', 0, 0, 0, 0, 1, 1, 1], ['n','n','n', 0, 0, 0, 1, 1, 1], ['n','n','n','n', 0, 0, 1, 1, 1], ['n','n','n','n','n', 0, 0, 0, 0], ['n','n','n','n','n','n', 0, 0, 0], ['n','n','n','n','n','n','n', 0, 0]] matrix = NussinovMatrix(sample) self.assertEqual(matrix.getFinalMatrix(), finalMatrix) class TestNussinovTraceback(unittest.TestCase): def testStackRecursion(self): matrix = [[ 0, 0, 0, 0, 0, 0, 1, 2, 3], [ 0, 0, 0, 0, 0, 0, 1, 2, 3], ['n', 0, 0, 0, 0, 0, 1, 2, 2], ['n','n', 0, 0, 0, 0, 1, 1, 1], ['n','n','n', 0, 0, 0, 1, 1, 1], ['n','n','n','n', 0, 0, 1, 1, 1], ['n','n','n','n','n', 0, 0, 0, 0], ['n','n','n','n','n','n', 0, 0, 0], ['n','n','n','n','n','n','n', 0, 0]] mystack = Nussinov(sample) basepair = [(2,9),(3,8),(4,7)] self.assertEqual(mystack.getBasePair(), basepair) if __name__=='__main__': unittest.main(argv=('','-v'))