Пример #1
0
 def testCheckGe(self):
     check.Ge(2, 1, 'foo')
     check.Ge(1, 1, 'foo')
     with self.assertRaisesRegexp(ValueError, 'bar'):
         check.Ge(0, 1, 'bar')
     with self.assertRaisesRegexp(RuntimeError, 'baz'):
         check.Ge(-1, 1, 'baz', RuntimeError)
Пример #2
0
 def ratio(numerator, denominator):
   check.Ge(numerator, 0)
   check.Ge(denominator, 0)
   if denominator > 0:
     return numerator / denominator
   elif numerator == 0:
     return 0.0  # map 0/0 to 0
   else:
     return float('inf')  # map x/0 to inf
Пример #3
0
 def token_span(token):
   check.Ge(token.end, token.start)
   return (token.start, token.end)