Пример #1
0
 def test_two_token2(self):
     ''' Test that a two tokens or works '''
     c = Comparitor('a|b')
     self.assertEqual('False: (a | b)', str(c))
     self.assertFalse(c.check([]))
     self.assertTrue(c.check(['b']))
     self.assertEqual('True: (a | b+)+', str(c))
     self.assertTrue(c.check(['b']))
     self.assertEqual('True: (a | b+)+', str(c))
     self.assertTrue(c.check(['a']))
     # Not a+ because shortcuts once true
     self.assertEqual('True: (a | b+)+', str(c))
     self.assertTrue(c.check([]))
     c.clear()
     self.assertEqual('False: (a | b)', str(c))
     self.assertFalse(c.check([]))
     self.assertTrue(c.check(['a']))
     self.assertEqual('True: (a+ | b)+', str(c))
     self.assertTrue(c.check(['a']))
     self.assertEqual('True: (a+ | b)+', str(c))
     self.assertTrue(c.check(['b']))
     # Not b+ because shortcuts once true
     self.assertEqual('True: (a+ | b)+', str(c))
     self.assertTrue(c.check([]))
     
     c.clear()
     self.assertEqual('False: (a | b)', str(c))
     self.assertFalse(c.check([]))
     self.assertFalse(c.check(['c', 'd', 'ef']))
     self.assertTrue(c.check(['a', 'b']))
     self.assertTrue(c.in_comparison('a'))
     self.assertTrue(c.in_comparison('b'))
     self.assertFalse(c.in_comparison('c'))
     return
Пример #2
0
 def test_single_token5(self):
     ''' Test that a single token and with itself and parenthesis and spacing works '''
     c = Comparitor('  (  ( abc)  & (abc )          )       ')
     self.assertEqual('False: (abc & abc)', str(c))
     self.assertFalse(c.check([]))
     self.assertTrue(c.check(['abc']))
     self.assertEqual('True: (abc+ & abc+)+', str(c))
     self.assertTrue(c.check([]))
     c.clear()
     self.assertEqual('False: (abc & abc)', str(c))
     self.assertFalse(c.check([]))
     self.assertFalse(c.check(['ab', 'bd', 'ef']))
     self.assertTrue(c.check(['ab', 'bd', 'abc']))
     self.assertTrue(c.in_comparison('abc'))
     self.assertFalse(c.in_comparison('ac'))
     return
Пример #3
0
 def test_single_token2(self):
     ''' Test that a single token in parenthesis works '''
     c = Comparitor('(abc)')
     self.assertEqual('False: abc', str(c))
     self.assertFalse(c.check([]))
     self.assertTrue(c.check(['abc']))
     self.assertEqual('True: abc+', str(c))
     self.assertTrue(c.check([]))
     c.clear()
     self.assertEqual('False: abc', str(c))
     self.assertFalse(c.check([]))
     self.assertFalse(c.check(['ab', 'bd', 'ef']))
     self.assertTrue(c.check(['ab', 'bd', 'abc']))
     self.assertTrue(c.in_comparison('abc'))
     self.assertFalse(c.in_comparison('ac'))
     return
Пример #4
0
 def test_complex1(self):
     ''' Test that first complex example works '''
     c = Comparitor('a|b & (c) | b|d&e&f')
     self.assertEqual('False: ((((a | b) & c) | b | d) & e & f)', str(c))
     self.assertFalse(c.check([]))
     self.assertFalse(c.check(['b']))
     self.assertEqual('False: ((((a | b+)+ & c) | b+ | d)+ & e & f)', str(c))
     self.assertFalse(c.check(['b']))
     self.assertEqual('False: ((((a | b+)+ & c) | b+ | d)+ & e & f)', str(c))
     self.assertFalse(c.check(['a']))
     self.assertTrue(c.check(['e', 'f']))
     self.assertEqual('True: ((((a+ | b+)+ & c) | b+ | d)+ & e+ & f+)+', str(c))
     c.clear()
     self.assertEqual('False: ((((a | b) & c) | b | d) & e & f)', str(c))
     self.assertFalse(c.check([]))
     self.assertTrue(c.check(['d','e','f']))
     self.assertEqual('True: ((((a | b) & c) | b | d+)+ & e+ & f+)+', str(c))
     self.assertTrue(c.in_comparison('a'))
     self.assertTrue(c.in_comparison('e'))
     self.assertFalse(c.in_comparison('k'))
     return
Пример #5
0
 def test_two_token1(self):
     ''' Test that a two tokens and works '''
     c = Comparitor('  (  ( a)  & (b))       ')
     self.assertEqual('False: (a & b)', str(c))
     self.assertFalse(c.check([]))
     self.assertFalse(c.check(['b']))
     self.assertEqual('False: (a & b+)', str(c))
     self.assertFalse(c.check(['b']))
     self.assertEqual('False: (a & b+)', str(c))
     self.assertTrue(c.check(['a']))
     self.assertEqual('True: (a+ & b+)+', str(c))
     self.assertTrue(c.check([]))
     c.clear()
     self.assertEqual('False: (a & b)', str(c))
     self.assertFalse(c.check([]))
     self.assertFalse(c.check(['c', 'd', 'ef']))
     self.assertTrue(c.check(['a', 'b']))
     self.assertTrue(c.in_comparison('a'))
     self.assertTrue(c.in_comparison('b'))
     self.assertFalse(c.in_comparison('c'))
     return