Esempio n. 1
0
 def testNormalizesFloats(self):
   pb1 = compare_test_pb2.Large()
   pb1.float_ = 1.2314352351231
   pb2 = compare_test_pb2.Large()
   pb2.float_ = 1.231435
   self.assertNotEqual(pb1.float_, pb2.float_)
   compare.NormalizeNumberFields(pb1)
   compare.NormalizeNumberFields(pb2)
   self.assertEqual(pb1.float_, pb2.float_)
Esempio n. 2
0
 def testNormalizesDoubles(self):
   pb1 = compare_test_pb2.Large()
   pb1.double_ = 1.2314352351231
   pb2 = compare_test_pb2.Large()
   pb2.double_ = 1.2314352
   self.assertNotEqual(pb1.double_, pb2.double_)
   compare.NormalizeNumberFields(pb1)
   compare.NormalizeNumberFields(pb2)
   self.assertEqual(pb1.double_, pb2.double_)
Esempio n. 3
0
  def testNormalizesInts(self):
    pb = compare_test_pb2.Large()
    pb.int64_ = 4
    compare.NormalizeNumberFields(pb)
    self.assertTrue(isinstance(pb.int64_, six.integer_types))

    pb.int64_ = 4
    compare.NormalizeNumberFields(pb)
    self.assertTrue(isinstance(pb.int64_, six.integer_types))

    pb.int64_ = 9999999999999999
    compare.NormalizeNumberFields(pb)
    self.assertTrue(isinstance(pb.int64_, six.integer_types))
Esempio n. 4
0
    def testNormalizesInts(self):
        pb = compare_test_pb2.Large()
        pb.int64_ = 4
        compare.NormalizeNumberFields(pb)
        self.assertTrue(isinstance(pb.int64_, long))

        pb.int64_ = 4L
        compare.NormalizeNumberFields(pb)
        self.assertTrue(isinstance(pb.int64_, long))

        pb.int64_ = 9999999999999999L
        compare.NormalizeNumberFields(pb)
        self.assertTrue(isinstance(pb.int64_, long))
Esempio n. 5
0
 def testNormalizesRepeatedInts(self):
   pb = compare_test_pb2.Large()
   pb.int64s.extend([1, 400, 999999999999999])
   compare.NormalizeNumberFields(pb)
   self.assertTrue(isinstance(pb.int64s[0], six.integer_types))
   self.assertTrue(isinstance(pb.int64s[1], six.integer_types))
   self.assertTrue(isinstance(pb.int64s[2], six.integer_types))
Esempio n. 6
0
 def testNormalizesMaps(self):
   pb = compare_test_pb2.WithMap()
   pb.value_message[4].strings.extend(['a', 'b', 'c'])
   pb.value_string['d'] = 'e'
   compare.NormalizeNumberFields(pb)
Esempio n. 7
0
 def testNormalizesRepeatedFloats(self):
   pb = compare_test_pb2.Large()
   pb.medium.floats.extend([0.111111111, 0.111111])
   compare.NormalizeNumberFields(pb)
   for value in pb.medium.floats:
     self.assertAlmostEqual(0.111111, value)
Esempio n. 8
0
 def __init__(self, wrapped: statistics_pb2.DatasetFeatureStatistics):
     self._wrapped = wrapped
     self._normalized = statistics_pb2.DatasetFeatureStatistics()
     self._normalized.MergeFrom(wrapped)
     compare.NormalizeNumberFields(self._normalized)