(self)
| 1913 | self.assertEqual(id(dc), id(d)) |
| 1914 | |
| 1915 | def test_hash_method(self): |
| 1916 | |
| 1917 | Decimal = self.decimal.Decimal |
| 1918 | localcontext = self.decimal.localcontext |
| 1919 | |
| 1920 | def hashit(d): |
| 1921 | a = hash(d) |
| 1922 | b = d.__hash__() |
| 1923 | self.assertEqual(a, b) |
| 1924 | return a |
| 1925 | |
| 1926 | #just that it's hashable |
| 1927 | hashit(Decimal(23)) |
| 1928 | hashit(Decimal('Infinity')) |
| 1929 | hashit(Decimal('-Infinity')) |
| 1930 | hashit(Decimal('nan123')) |
| 1931 | hashit(Decimal('-NaN')) |
| 1932 | |
| 1933 | test_values = [Decimal(sign*(2**m + n)) |
| 1934 | for m in [0, 14, 15, 16, 17, 30, 31, |
| 1935 | 32, 33, 61, 62, 63, 64, 65, 66] |
| 1936 | for n in range(-10, 10) |
| 1937 | for sign in [-1, 1]] |
| 1938 | test_values.extend([ |
| 1939 | Decimal("-1"), # ==> -2 |
| 1940 | Decimal("-0"), # zeros |
| 1941 | Decimal("0.00"), |
| 1942 | Decimal("-0.000"), |
| 1943 | Decimal("0E10"), |
| 1944 | Decimal("-0E12"), |
| 1945 | Decimal("10.0"), # negative exponent |
| 1946 | Decimal("-23.00000"), |
| 1947 | Decimal("1230E100"), # positive exponent |
| 1948 | Decimal("-4.5678E50"), |
| 1949 | # a value for which hash(n) != hash(n % (2**64-1)) |
| 1950 | # in Python pre-2.6 |
| 1951 | Decimal(2**64 + 2**32 - 1), |
| 1952 | # selection of values which fail with the old (before |
| 1953 | # version 2.6) long.__hash__ |
| 1954 | Decimal("1.634E100"), |
| 1955 | Decimal("90.697E100"), |
| 1956 | Decimal("188.83E100"), |
| 1957 | Decimal("1652.9E100"), |
| 1958 | Decimal("56531E100"), |
| 1959 | ]) |
| 1960 | |
| 1961 | # check that hash(d) == hash(int(d)) for integral values |
| 1962 | for value in test_values: |
| 1963 | self.assertEqual(hashit(value), hash(int(value))) |
| 1964 | |
| 1965 | # check that the hashes of a Decimal float match when they |
| 1966 | # represent exactly the same values |
| 1967 | test_strings = ['inf', '-Inf', '0.0', '-.0e1', |
| 1968 | '34.0', '2.5', '112390.625', '-0.515625'] |
| 1969 | for s in test_strings: |
| 1970 | f = float(s) |
| 1971 | d = Decimal(s) |
| 1972 | self.assertEqual(hashit(d), hash(f)) |
nothing calls this directly
no test coverage detected