def test_isValid(self): """Enumeration isValid should return True for valid sequence""" a = Enumeration('bca') self.assertEqual(a.isValid(''), True) self.assertEqual(a.isValid('bbb'), True) self.assertEqual(a.isValid('bbbaac'), True) self.assertEqual(a.isValid('bbd'), False) self.assertEqual(a.isValid('d'), False) self.assertEqual(a.isValid(['a', 'b']), True) self.assertEqual(a.isValid(['a', None]), False)
def test_mul(self): """Enumeration mul should produce correct JointEnumeration""" a = DnaBases * RnaBases self.assertEqual(len(a), 16) self.assertEqual(a[0], ('T','U')) self.assertEqual(a[-1], ('G','G')) #check that it works with gaps a = Enumeration('ab-','-') b = Enumeration('xz','z') x = a*b self.assertEqual(x.Gap, ('-','z')) self.assertEqual(x.GapIndex, 5) self.assertEqual(len(x), 6) self.assertEqual(x, (('a','x'),('a','z'),('b','x'),('b','z'),('-','x'),\ ('-','z'))) #check that it doesn't work when only one seq has gaps c = Enumeration('c') x = a*c self.assertEqual(x.Gap, None)
def test_pow(self): """Enumeration pow should produce JointEnumeration with n copies""" a = AminoAcids**3 self.assertEqual(a[0], (AminoAcids[0],)*3) self.assertEqual(a[-1], (AminoAcids[-1],)*3) self.assertEqual(len(a), len(AminoAcids)**3) self.assertEqual(a.ArrayType, uint16) #check that it works with gaps a = Enumeration('a-b', '-') b = a**3 self.assertEqual(len(b), 27) self.assertEqual(b.Gap, ('-','-','-')) self.assertEqual(b.GapIndex, 13) self.assertEqual(b.ArrayType, uint8) #check that array type is set correctly if needed b = a**6 #too big to fit in char self.assertEqual(b.ArrayType, uint16)
def test_index(self): """Enumeration index should return first index of item""" a = Enumeration('bca') self.assertEqual(a.index('b'), 0) self.assertEqual(a.index('c'), 1) self.assertEqual(a.index('a'), 2)
def test_init(self): """Enumeration init should work from any sequence""" a = Enumeration('abc') self.assertEqual(a.index('a'), 0) self.assertEqual(a.index('b'), 1) self.assertEqual(a.index('c'), 2) self.assertEqual(a[0], 'a') self.assertEqual(a[1], 'b') self.assertEqual(a[2], 'c') self.assertEqual(a.ArrayType, uint8) a = Enumeration('bca') self.assertEqual(a.index('b'), 0) self.assertEqual(a.index('c'), 1) self.assertEqual(a.index('a'), 2) self.assertEqual(a[0], 'b') self.assertEqual(a[1], 'c') self.assertEqual(a[2], 'a') a = Enumeration([1,'2']) self.assertEqual(a.index(1), 0) self.assertEqual(a.index('2'), 1) self.assertRaises(KeyError, a.index, '1') #check that it works with gaps a = Enumeration('ab-', '-') self.assertEqual(a.Gap, '-') self.assertEqual(a.GapIndex, 2) a = Enumeration(range(257)) #too big to fit in uint8 self.assertEqual(a.ArrayType, uint16)
def test_fromIndices(self): """Enumeration fromIndices should return elements from indices""" a = Enumeration('bca') self.assertEqual(a.fromIndices([]), []) self.assertEqual(a.fromIndices([1,1,2,0,2,1]), list('ccabac'))
def test_toIndices(self): """Enumeration toIndices should return indices from elements""" a = Enumeration('bca') self.assertEqual(a.toIndices(''), []) self.assertEqual(a.toIndices('ccabac'), [1,1,2,0,2,1])
def test_getitem(self): """Enumeration[i] should return character at i""" a = Enumeration('bca') self.assertEqual(a[0], 'b') self.assertEqual(a[1], 'c') self.assertEqual(a[2], 'a')