Exemplo n.º 1
0
 def test_gen_digits(self):
     g = GrammarWorker("foo")
     g.parse_digits("1234")
     self.assertEqual(g.digits[str(1234)], 1)
     g.parse_digits("foo1234!4321")
     self.assertEqual(g.digits[str(1234)], 2)
     self.assertEqual(g.digits[str(4321)], 1)
Exemplo n.º 2
0
 def test_log(self):
   g = GrammarWorker("foo")
   g.parse("foo1234")
   gr = GrammarManager(worker=g)
   gr.calculate()
   self.assertEqual(len(gr.worker_log), 0)
   g.parse("foo")
   gr.new_worker(g)
   self.assertEqual(len(gr.worker_log), 1)
   self.assertTrue('foo' in gr.worker_log)
   self.assertTrue(gr.worker_log['foo'][0].micro['LLL'] == 1)
Exemplo n.º 3
0
 def test_digits(self):
   g = GrammarWorker("foo")
   gr = GrammarManager()
   g.parse("foo1234")
   gr.new_worker(g)
   gr.calculate()
   self.assertEqual(gr.digits['1234'], 1.0)
   g.parse("foo1234!4321")
   gr.new_worker(g)
   gr.calculate()
   self.assertEqual(gr.digits['4321'], 0.3333333333333333)
   self.assertTrue(gr.digits['1234'] < 1.0)
Exemplo n.º 4
0
 def test_gen_specials(self):
     g = GrammarWorker("foo")
     g.parse_specials("$$$$!!!!")
     self.assertEqual(g.specials["$$$$!!!!"], 1)
     g.parse_specials("...afaf,,,")
     self.assertEqual(g.specials[",,,"], 1)
     self.assertEqual(g.specials["..."], 1)
     g.parse_specials("...foo,,,bar$$$$!!!!baz")
     self.assertEqual(g.specials[",,,"], 2)
     self.assertEqual(g.specials["..."], 2)
     self.assertEqual(g.specials["$$$$!!!!"], 2)
Exemplo n.º 5
0
  def test_append_grammar(self):  
    g = GrammarWorker("foo")
    g.parse("foo1234")
    gr = GrammarManager(worker=g)
    gr.calculate()

    g.parse("foo")
    gr.new_worker(g)
    gr.calculate()
    self.assertEqual(gr.grammar["LLLDDDD"], 0.3333333333333333)
    self.assertEqual(gr.grammar["LLL"], 0.3333333333333333)
    self.assertEqual(len(gr.grammar), 2)

    g.parse('bazbiff')
    gr.new_worker(g)
    gr.calculate()
    self.assertEqual(gr.grammar["LLLLLLL"], 0.2)
    self.assertFalse(gr.grammar["LLL"] == 0.3)
    self.assertEqual(len(gr.grammar), 3)
Exemplo n.º 6
0
 def test_create(self):
   g = GrammarWorker("foo")
   g.parse("foo1234")
   gr = GrammarManager(worker=g)
   gr.calculate()
   self.assertEqual(gr.grammar["LLLDDDD"], 1.0)
Exemplo n.º 7
0
 def test_parse(self):
     g = GrammarWorker("foo")
     g.parse("foo1234!")
     self.assertEqual(g.digits[str(1234)], 1)
     self.assertEqual(g.specials["!"], 1)
     self.assertEqual(g.micro["LLLDDDDS"], 1)
Exemplo n.º 8
0
 def test_gen_macro(self):
     g = GrammarWorker("foo")
     g.parse_macro("foo12344")
     self.assertEqual(g.macro["fo1234"], 1)
Exemplo n.º 9
0
 def test_gen_micro(self):
     g = GrammarWorker("foo")
     g.parse_micro("foo!1bar")
     self.assertEqual(g.micro["LLLSDLLL"], 1)
     g.parse_micro("bar1!foo")
     self.assertEqual(g.micro["LLLDSLLL"], 1)