Esempio n. 1
0
 def test_time_hashing_rationals_gmpy(self):
     """
     Check that hashes of fractions and gmpy mpqs match for some
     reasonable rational numbers.
     """
     if gmpy is None: raise SkipTest
     pi = "3.141592"
     hashfn = numbergen.Hash("test", input_count=1)
     self.assertEqual(hashfn(0.5), hashfn(gmpy.mpq(0.5)))
     self.assertEqual(hashfn(pi), hashfn(gmpy.mpq(3.141592)))
Esempio n. 2
0
 def test_time_hashing_rationals(self):
     """
     Check that hashes fractions and strings match for some
     reasonable rational numbers.
     """
     hashfn = numbergen.Hash("test", input_count=1)
     pi = "3.141592"
     half = fractions.Fraction(0.5)
     self.assertEqual(hashfn(0.5), hashfn(half))
     self.assertEqual(hashfn(pi), hashfn(fractions.Fraction(pi)))
Esempio n. 3
0
 def test_time_hashing_rationals(self):
     """
     Check that hashes fractions and strings match for some
     reasonable rational numbers.
     """
     hashfn = numbergen.Hash("test", input_count=1)
     pi = "3.141592"
     # Before Python 2.7, fractions.Fraction cannot be initialized with a float
     half = fractions.Fraction(1,
                               2) if pybefore27 else fractions.Fraction(0.5)
     self.assertEqual(hashfn(0.5), hashfn(half))
     self.assertEqual(hashfn(pi), hashfn(fractions.Fraction(pi)))
Esempio n. 4
0
    def test_time_hashing_integers_gmpy(self):
        """
        Check that hashes for gmpy values at the integers also matches
        those of ints, fractions and strings.
        """
        if gmpy is None: raise SkipTest
        hashfn = numbergen.Hash("test", input_count=1)
        hash_1 = hashfn(1)
        hash_42 = hashfn(42)

        self.assertEqual(hash_1, hashfn(gmpy.mpq(1)))
        self.assertEqual(hash_1, hashfn(1))

        self.assertEqual(hash_42, hashfn(gmpy.mpq(42)))
        self.assertEqual(hash_42, hashfn(42))
Esempio n. 5
0
    def test_time_hashing_integers(self):
        """
        Check that ints, fractions and strings hash to the same value
        for integer values.
        """
        hashfn = numbergen.Hash("test", input_count=1)
        hash_1 = hashfn(1)
        hash_42 = hashfn(42)
        hash_200001 = hashfn(200001)

        self.assertEqual(hash_1, hashfn(fractions.Fraction(1)))
        self.assertEqual(hash_1, hashfn("1"))

        self.assertEqual(hash_42, hashfn(fractions.Fraction(42)))
        self.assertEqual(hash_42, hashfn("42"))

        self.assertEqual(hash_200001, hashfn(fractions.Fraction(200001)))
        self.assertEqual(hash_200001, hashfn("200001"))