Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import unittest
- import sys
- import os
- import traceback
- import coverage
- import pprint
- # import specific package modules
- #sys.path.insert(0,"../")
- from Egramgen import Gramgen
- class TestSequenceClient(unittest.TestCase ):
- def setUp(self):
- self.pp = pprint.PrettyPrinter(indent=4)
- pass
- def tearDown(self):
- pass
- def testA1Gramgen(self):
- maxlen=4
- S="S"
- Vn=["S","A","B"] # non terminal
- Vt=["a","b"] # terminal
- R=[("S","aB"), ("A","a"),("A","aS"),("A","bAA"),
- ("S","bA"),("B","b"),("B","bS"),("B","aBB")]
- #Na(P) =Nb(P)
- Lg=Gramgen(Vn,Vt,R,S,maxlen)
- Lg.gen()
- Lg.L
- L=Lg.L
- L.sort()
- # creating what should be obtained
- # langage with n=word-length <=maxlen
- LL=list()
- import itertools as IT
- for n in range(2,maxlen+2,2):
- positions=range(n)
- combinations=list(IT.combinations(positions,n/2))
- for a_positions in combinations:
- word=["a" if i in a_positions else "b" for i in positions]
- LL.append(word)
- LL=[''.join(s) for s in LL]
- LL.sort()
- self.assertEqual(L,LL,"result Na(P)=Nb(P) not ok")
- def testA2Gramgen(self):
- #L={"a"*n"b"*n"c"*n|n is integer}
- maxn=3
- maxlen=3*maxn
- S="S"
- Vn=["S","X","Y"] # non terminal
- Vt=["a","b","c"] # terminal
- R=[("S","abc"), ("S","aXbc"),("Xb","bX"),("Xc","Ybcc"),
- ("bY","Yb"),("aY","aaX"),("aY","aa")]
- Lg=Gramgen(Vn,Vt,R,S,maxlen)
- Lg.gen()
- Lg.L
- L=Lg.L
- L.sort()
- # creating what should be obtained
- # langage with n=word-length <=maxlen
- LL=list()
- import itertools as IT
- for n in range(1,maxn+1):
- word="a"*n+"b"*n+"c"*n
- LL.append(word)
- LL=[''.join(s) for s in LL]
- LL.sort()
- #print L
- #print LL
- self.assertEqual(L,LL,'result "a"*n"b"*n"c"*n not ok')
- def testA3Gramgen(self):
- '''
- L={ a^n n integer }
- '''
- maxlen=20
- S="S"
- Vn=["S","A"] # non terminal
- Vt=["a",] # terminal
- print Vn,Vt
- L=list()
- R=[("S","a"),
- ("S","Aa"),
- ("A","a"),
- ("A","Aa")
- ]
- Lg=Gramgen(Vn,Vt,R,S,maxlen)
- Lg.gen()
- Lg.L.sort()
- LL=list()
- for i in xrange(1,21):
- LL.append("a"*i)
- LL.sort()
- print "Lg.l\n", Lg.L
- print "LL \n",LL
- self.assertEqual(Lg.L,LL,"result 'a'*n not ok")
- '''
- def testA3arangements_ie(self):
- a=CT.arangements_ie(10,4,3)
- self.assertEqual(a,25200,"resultnot ok: com (%i,%i,%i)<>%i" %(10,4,3,a))
- self.assertRaises(CT.CountingValueError,CT.arangements_ie,10,4,7)
- '''
- try:
- suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceClient)
- global cov
- cov=coverage.coverage(cover_pylib=False,timid=True,source=['Egramgen'])
- cov.start()
- unittest.TextTestRunner(verbosity=2).run(suite)
- cov.stop()
- cov.html_report(directory="./coverage")
- #cov.report()
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement