test_py32_hash.txt
1 Test hash() behavior 2 ==================== 3 4 This test is only applicable for Python 3.2 and later. 5 6 >>> import gmpy2 7 >>> from gmpy2 import mpz, mpq, mpfr 8 >>> from decimal import Decimal 9 >>> gmpy2.set_context(gmpy2.context()) 10 11 12 >>> hash(mpfr('123.456')) == hash(float('123.456')) 13 True 14 >>> hash(mpfr('123.5')) == hash(float('123.5')) 15 True 16 >>> hash(mpfr('0')) == hash(float('0')) 17 True 18 >>> hash(mpfr('1')) == hash(float('1')) 19 True 20 >>> hash(mpfr('2')) == hash(float('2')) 21 True 22 >>> hash(mpfr('-1')) == hash(float('-1')) 23 True 24 >>> hash(mpfr('Inf')) == hash(float('Inf')) 25 True 26 >>> hash(mpfr('-Inf')) == hash(float('-Inf')) 27 True 28 >>> hash(mpfr('-0')) == hash(float('-0')) 29 True 30 >>> hash(mpfr('NaN')) == hash(float('NaN')) 31 True 32 >>> hash(mpfr('123.456')) == hash(Decimal('123.456')) 33 False 34 >>> hash(mpfr('123.5')) == hash(Decimal('123.5')) 35 True 36 >>> hash(mpq(123456,1000)) == hash(Decimal('123.456')) 37 True 38 >>> hash(mpz(123)) == hash(Decimal(123)) 39 True 40