Exemplo n.º 1
0
    def test_number_matcher_not_equal(self):
        '''Test NumberMatcher class for contrived not equal, ie !=0'''

        nm = NumberMatcher('!=0', False)
        self.assertFalse(nm.match('0'))
        self.assertTrue(nm.match('1'))
        self.assertTrue(nm.match('-1'))

        nm = NumberMatcher('!=-20', False)
        self.assertFalse(nm.match('-20'))
        self.assertTrue(nm.match('1'))
        self.assertTrue(nm.match('-1'))
Exemplo n.º 2
0
    def test_number_matcher_equal(self):
        '''Test NumberMatcher class for equality, ie ==0'''

        nm = NumberMatcher('==0', False)
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))

        nm = NumberMatcher('==-20', False)
        self.assertTrue(nm.match('-20'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 3
0
    def test_number_matcher_contrived_equal(self):
        '''Test NumberMatcher class for contrived equality, ie 0 instead of ==0'''

        nm = NumberMatcher('0', False)
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))

        nm = NumberMatcher('-20', False)
        self.assertTrue(nm.match('-20'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 4
0
    def test_number_matcher_greater_than(self):
        '''Test NumberMatcher class for greater than, ie >0'''

        nm = NumberMatcher('>0', True)
        self.assertTrue(nm.match('1'))
        self.assertFalse(nm.match('0'))
        self.assertFalse(nm.match('-1'))

        nm = NumberMatcher('>-20', False)
        self.assertTrue(nm.match('-19'))
        self.assertTrue(nm.match('20'))
        self.assertFalse(nm.match('-20'))
        self.assertFalse(nm.match('-21'))
Exemplo n.º 5
0
    def test_number_matcher_less_than_equal(self):
        '''Test NumberMatcher class for less than or equal to, ie <=0'''

        nm = NumberMatcher('<=0', False)
        self.assertTrue(nm.match('-1'))
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('1'))

        nm = NumberMatcher('<=-20', False)
        self.assertTrue(nm.match('-21'))
        self.assertTrue(nm.match('-20'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 6
0
    def test_number_matcher_greater_than_equal(self):
        '''Test NumberMatcher class for greater than or equal to, ie >=0'''

        nm = NumberMatcher('>=0', False)
        self.assertTrue(nm.match('1'))
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('-1'))

        # hex handling
        nm = NumberMatcher('>=-0x20', True)
        self.assertTrue(nm.match('-0x19'))
        self.assertTrue(nm.match('0x20'))
        self.assertTrue(nm.match('-0x20'))
        self.assertFalse(nm.match('-0x21'))
Exemplo n.º 7
0
    def test_number_matcher_less_than(self):
        '''Test NumberMatcher class for less than, ie <0'''

        nm = NumberMatcher('<0', False)
        self.assertTrue(nm.match('-1'))
        self.assertFalse(nm.match('0'))
        self.assertFalse(nm.match('1'))

        nm = NumberMatcher('<-20', True)
        self.assertTrue(nm.match('-21'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 8
0
    def test_number_matcher_invalid_operators(self):
        '''Test NumberMatcher class for bad number strings'''

        with self.assertRaises(ValueError):
            NumberMatcher('', False)

        with self.assertRaises(ValueError):
            NumberMatcher('lkshfskljdhhf', False)

        with self.assertRaises(ValueError):
            NumberMatcher('=)', False)

        with self.assertRaises(ValueError):
            NumberMatcher('#=', False)

        # no numbers
        with self.assertRaises(ValueError):
            NumberMatcher('==', False)
Exemplo n.º 9
0
    def test_number_matcher_not_equal(self):
        '''Test NumberMatcher class for contrived not equal, ie !=0'''

        nm = NumberMatcher('!=0', False)
        self.assertFalse(nm.match('0'))
        self.assertTrue(nm.match('1'))
        self.assertTrue(nm.match('-1'))

        nm = NumberMatcher('!=-20', False)
        self.assertFalse(nm.match('-20'))
        self.assertTrue(nm.match('1'))
        self.assertTrue(nm.match('-1'))
Exemplo n.º 10
0
    def test_number_matcher_equal(self):
        '''Test NumberMatcher class for equality, ie ==0'''

        nm = NumberMatcher('==0', False)
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))

        nm = NumberMatcher('==-20', False)
        self.assertTrue(nm.match('-20'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 11
0
    def test_number_matcher_contrived_equal(self):
        '''Test NumberMatcher class for contrived equality, ie 0 instead of ==0'''

        nm = NumberMatcher('0', False)
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))

        nm = NumberMatcher('-20', False)
        self.assertTrue(nm.match('-20'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 12
0
    def test_number_matcher_greater_than(self):
        '''Test NumberMatcher class for greater than, ie >0'''

        nm = NumberMatcher('>0', True)
        self.assertTrue(nm.match('1'))
        self.assertFalse(nm.match('0'))
        self.assertFalse(nm.match('-1'))

        nm = NumberMatcher('>-20', False)
        self.assertTrue(nm.match('-19'))
        self.assertTrue(nm.match('20'))
        self.assertFalse(nm.match('-20'))
        self.assertFalse(nm.match('-21'))
Exemplo n.º 13
0
    def test_number_matcher_less_than_equal(self):
        '''Test NumberMatcher class for less than or equal to, ie <=0'''

        nm = NumberMatcher('<=0', False)
        self.assertTrue(nm.match('-1'))
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('1'))

        nm = NumberMatcher('<=-20', False)
        self.assertTrue(nm.match('-21'))
        self.assertTrue(nm.match('-20'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))
Exemplo n.º 14
0
    def test_number_matcher_greater_than_equal(self):
        '''Test NumberMatcher class for greater than or equal to, ie >=0'''

        nm = NumberMatcher('>=0', False)
        self.assertTrue(nm.match('1'))
        self.assertTrue(nm.match('0'))
        self.assertFalse(nm.match('-1'))

        # hex handling
        nm = NumberMatcher('>=-0x20', True)
        self.assertTrue(nm.match('-0x19'))
        self.assertTrue(nm.match('0x20'))
        self.assertTrue(nm.match('-0x20'))
        self.assertFalse(nm.match('-0x21'))
Exemplo n.º 15
0
    def test_number_matcher_less_than(self):
        '''Test NumberMatcher class for less than, ie <0'''

        nm = NumberMatcher('<0', False)
        self.assertTrue(nm.match('-1'))
        self.assertFalse(nm.match('0'))
        self.assertFalse(nm.match('1'))

        nm = NumberMatcher('<-20', True)
        self.assertTrue(nm.match('-21'))
        self.assertFalse(nm.match('1'))
        self.assertFalse(nm.match('-1'))