예제 #1
0
 def test_parse_number_exp(self):
     self.assertEqual(parse_number(None, '1e2', 0), (100., 3))
     self.assertEqual(parse_number(None, '1e-2', 0), (.01, 4))
     self.assertEqual(parse_number(None, '1E2', 0), (100., 3))
     self.assertEqual(parse_number(None, '1e', 0), (1, 1))
     self.assertEqual(parse_number(None, '1e+2', 0), (100, 4))
     self.assertEqual(parse_number(None, '1.23e2', 0), (123, 6))
     self.assertEqual(parse_number(None, '2341.23e2', 3), (123, 9))
예제 #2
0
 def test_parse_number_float(self):
     self.assertEqual(parse_number(None, '234.', 0), (234, 4))
     self.assertEqual(parse_number(None, '2343780.4', 6), (.4, 9))
     self.assertEqual(parse_number(None, '-234.', 0), (-234, 5))
     self.assertEqual(parse_number(None, '0.100', 3), (0, 4))
     self.assertEqual(parse_number(None, '0.100', 0), (.1, 5))
     self.assertEqual(parse_number(None, '0.1234.45', 0), (.1234, 6))
     self.assertEqual(parse_number(None, '02.34', 0), (0, 1))
     self.assertEqual(parse_number(None, '-02.4', 0), NORES)
     self.assertEqual(parse_number(None, 'a.234', 0), NORES)
     self.assertEqual(parse_number(None, '-a.bc', 0), NORES)
     self.assertEqual(parse_number(None, '-.234', 0), NORES)
     self.assertEqual(parse_number(None, '.234', 0), NORES)
예제 #3
0
 def test_parse_number_float_const(self):
     x, i = parse_number(None, 'nan', 0)
     self.assertEqual((str(x), i), ('nan', 3))
     x, i = parse_number(None, 'Nan', 0)
     self.assertEqual((str(x), i), ('nan', 3))
     x, i = parse_number(None, 'nAN', 0)
     self.assertEqual((str(x), i), ('nan', 3))
     x, i = parse_number(None, 'abcnandef', 3)
     self.assertEqual((str(x), i), ('nan', 6))
     self.assertEqual(parse_number(None, '-nan', 0), NORES)
     inf = float('inf')
     self.assertEqual(parse_number(None, 'inf', 0), (inf, 3))
     self.assertEqual(parse_number(None, '-inf', 0), (-inf, 4))
     self.assertEqual(parse_number(None, 'INf', 0), (inf, 3))
     self.assertEqual(parse_number(None, 'inFIniTY', 0), (inf, 8))
     self.assertEqual(parse_number(None, '-infINIty', 0), (-inf, 9))
     self.assertEqual(parse_number(None, 'qxzinfygh', 3), (inf, 6))
     self.assertEqual(parse_number(None, '-infini', 0), (-inf, 4))
예제 #4
0
 def test_parse_number_int(self):
     self.assertEqual(parse_number(None, '234', 0), (234, 3))
     self.assertEqual(parse_number(None, '234234234', 6), (234, 9))
     self.assertEqual(parse_number(None, '-234', 0), (-234, 4))
     self.assertEqual(parse_number(None, '-234', 1), (234, 4))
     self.assertEqual(parse_number(None, '345-234', 3), (-234, 7))
     self.assertEqual(parse_number(None, '234abc', 0), (234, 3))
     self.assertEqual(parse_number(None, '0', 0), (0, 1))
     self.assertEqual(parse_number(None, '0234', 0), (0, 1))
     self.assertEqual(parse_number(None, '-0234', 0), NORES)
     self.assertEqual(parse_number(None, 'abc', 0), NORES)
     self.assertEqual(parse_number(None, '-abc', 0), NORES)