Ejemplo n.º 1
0
 def testBadSeed(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("abcdefghijklmnopq")
     dp.order=5
     try:
         dp.seed="xxxx"
         raise unittest.AssertionError
     except RuntimeError:
         pass
Ejemplo n.º 2
0
 def testPrefer1(self):
     dp = DissociatedPress("tests/data/abc2.sqlite")
     preferLogger = logging.getLogger("dissociatedpress.prefer")
     preferLogger.setLevel(logging.INFO)
     try:
         dp.analyze("abababababababab", 0)
     except Warning:
         pass
     try:
         dp.analyze("acacacacacacacac", 1)
     except Warning:
         pass
     dp.order = 1
     Bs = 0
     Cs = 0
     line = ""
     dp.prefer = 1
     for i in xrange(100):
         n = dp.next()
         line += n
         if n == 'b':
             Bs += 1
         elif n == 'c':
             Cs += 1
     preferLogger.info(line)
     self.assertTrue(Bs + 10 < Cs + 10)
Ejemplo n.º 3
0
 def testIncreaseOrderContinuity2(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("0123456789")
     dp.order = 5
     dp.seed = "01234"
     self.assertEquals(dp.next(),"5")
     dp.order = 10
     self.assertEquals(dp.next(),"6")
     self.assertEquals(dp.next(),"7")
     self.assertEquals(dp.next(),"8")
     self.assertEquals(dp.next(),"9")
     self.assertEquals(dp.next(),"0")
     self.assertEquals(dp.next(),"1")
Ejemplo n.º 4
0
 def testChangeOrderReadOrder2(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("0123456789")
     dp.order = 10
     dp.seed = "0123456789"
     self.assertEquals(dp.next(),"0")
     dp.order = 3
     for i in xrange(7):
         dp.next()
     self.assertEquals(dp.order,3)
Ejemplo n.º 5
0
 def testPrefer1(self):
     dp = DissociatedPress("tests/data/abc2.sqlite")
     preferLogger = logging.getLogger("dissociatedpress.prefer")
     preferLogger.setLevel(logging.INFO)
     try:
         dp.analyze("abababababababab",0)
     except Warning:
         pass
     try:
         dp.analyze("acacacacacacacac",1)
     except Warning:
         pass
     dp.order = 1
     Bs = 0
     Cs = 0
     line = ""
     dp.prefer = 1
     for i in xrange(100):
         n = dp.next()
         line += n
         if n == 'b':
             Bs += 1
         elif n == 'c':
             Cs += 1
     preferLogger.info(line)
     self.assertTrue(Bs + 10 < Cs + 10)
Ejemplo n.º 6
0
 def testDecreaseOrderContinuity(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("0123456789")
     dp.order = 5
     dp.seed = "01234"
     self.assertEquals(dp.next(),"5")
     dp.order = 4
     self.assertEquals(dp.next(),"6")
Ejemplo n.º 7
0
    def testDefaultFilter(self):
        input = """abc ab
abc ab
 
 ab         """
        res = DissociatedPress.defaultFilter(input)
        self.assertEquals(res, "abc ab abc ab ab ")
Ejemplo n.º 8
0
    def testDefaultFilter(self):
        input = """abc ab
abc ab
 
 ab         """
        res = DissociatedPress.defaultFilter(input)
        self.assertEquals(res,"abc ab abc ab ab ")
Ejemplo n.º 9
0
 def testCyclic2(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("asdglkuzcgvhje")
     dp.order=5
     dp.seed="kuzcg"
     for i in range(100):
         dp.next()
Ejemplo n.º 10
0
 def testDreadedUnicode(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze(u"ÄbcdeXabcdeYabcdeZüxxxxxxxxxxxxxxx")
     dp.order=5
     dp.seed=u"Yabcd"
     for i in range(100):
         dp.next()
Ejemplo n.º 11
0
 def testNextNext(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("abcdefghijklmnopq")
     dp.order=5
     dp.seed="abcde"
     self.assertEquals(dp.next(),"f")
     self.assertEquals(dp.next(),"g")
Ejemplo n.º 12
0
 def testRandomNext(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("abcdeXabcdeYabcdeZxxxxxxxxxxxxxxxx")
     dp.order=5
     res = set()
     for i in range(1000):
         dp.seed="abcde"
         res.add(dp.next())
     self.assertEquals(len(res),3)
Ejemplo n.º 13
0
 def testCyclicNext(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("abcdefabcd")
     dp.order=5
     dp.seed="abcde"
     res=""
     for i in range(100):
         res+=dp.next()
     self.assertEquals(res,"fabcdabcde"*10)
Ejemplo n.º 14
0
 def testAnalyze1(self):
     dp = DissociatedPress("tests/nonexistant")
     dp.analyze("abcabcabcabc")
Ejemplo n.º 15
0
 def testCreate(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.analyze("abcdefghijk")
Ejemplo n.º 16
0
 def testSetOrderEarly(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     dp.order = 4
Ejemplo n.º 17
0
 def testAnalyze2(self):
     dp = DissociatedPress("tests/data/abc.sqlite")
     self.assertRaises(Warning, dp.analyze, "abcabcabcabc")
Ejemplo n.º 18
0
 def testAnalyze1(self):
     dp = DissociatedPress("tests/nonexistant")
     dp.analyze("abcabcabcabc")
Ejemplo n.º 19
0
 def testManyTextIds(self):
     dp = DissociatedPress("tests/data/abc2.sqlite")
     preferLogger = logging.getLogger("dissociatedpress.prefer")
     preferLogger.setLevel(logging.INFO)
     try:
         dp.analyze("00abababababababab", 0)
     except Warning:
         pass
     try:
         dp.analyze("11acacacacacacacac", 1)
     except Warning:
         pass
     try:
         dp.analyze("22adadadadadadadad", 2)
     except Warning:
         pass
     try:
         dp.analyze("33aeaeaeaeaeaeaeae", 3)
     except Warning:
         pass
     dp.order = 1
     line = ""
     for i in xrange(100):
         dp.prefer = i / 5 % 4
         preferLogger.info("set prefer: %s" % dp.prefer)
         n = dp.next()
         line += n
     preferLogger.info(line)
Ejemplo n.º 20
0
 def testManyTextIds(self):
     dp = DissociatedPress("tests/data/abc2.sqlite")
     preferLogger = logging.getLogger("dissociatedpress.prefer")
     preferLogger.setLevel(logging.INFO)
     try:
         dp.analyze("00abababababababab",0)
     except Warning:
         pass
     try:
         dp.analyze("11acacacacacacacac",1)
     except Warning:
         pass
     try:
         dp.analyze("22adadadadadadadad",2)
     except Warning:
         pass
     try:
         dp.analyze("33aeaeaeaeaeaeaeae",3)
     except Warning:
         pass
     dp.order = 1
     line = ""
     for i in xrange(100):
         dp.prefer = i / 5 % 4
         preferLogger.info("set prefer: %s" % dp.prefer)
         n = dp.next()
         line += n
     preferLogger.info(line)
Ejemplo n.º 21
0
 def NOTtestAnalyzeFile(self):
     dp = DissociatedPress("tests/data/test.sqlite")
     contents = file("tests/data/die-linke.txt").read().decode("utf-8")
     dp.analyze(contents)
     for i in range(100):
         dp.next()