MCPcopy Create free account
hub / github.com/RustPython/RustPython / test_ndarray_hash

Method test_ndarray_hash

Lib/test/test_buffer.py:2097–2132  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2095 self.assertTrue(cmp_contig(b'\x01', x))
2096
2097 def test_ndarray_hash(self):
2098
2099 a = array.array('L', [1,2,3])
2100 nd = ndarray(a)
2101 self.assertRaises(ValueError, hash, nd)
2102
2103 # one-dimensional
2104 b = bytes(list(range(12)))
2105
2106 nd = ndarray(list(range(12)), shape=[12])
2107 self.assertEqual(hash(nd), hash(b))
2108
2109 # C-contiguous
2110 nd = ndarray(list(range(12)), shape=[3,4])
2111 self.assertEqual(hash(nd), hash(b))
2112
2113 nd = ndarray(list(range(12)), shape=[3,2,2])
2114 self.assertEqual(hash(nd), hash(b))
2115
2116 # Fortran contiguous
2117 b = bytes(transpose(list(range(12)), shape=[4,3]))
2118 nd = ndarray(list(range(12)), shape=[3,4], flags=ND_FORTRAN)
2119 self.assertEqual(hash(nd), hash(b))
2120
2121 b = bytes(transpose(list(range(12)), shape=[2,3,2]))
2122 nd = ndarray(list(range(12)), shape=[2,3,2], flags=ND_FORTRAN)
2123 self.assertEqual(hash(nd), hash(b))
2124
2125 # suboffsets
2126 b = bytes(list(range(12)))
2127 nd = ndarray(list(range(12)), shape=[2,2,3], flags=ND_PIL)
2128 self.assertEqual(hash(nd), hash(b))
2129
2130 # non-byte formats
2131 nd = ndarray(list(range(12)), shape=[2,2,3], format='L')
2132 self.assertEqual(hash(nd), hash(nd.tobytes()))
2133
2134 def test_py_buffer_to_contiguous(self):
2135

Callers

nothing calls this directly

Calls 6

listClass · 0.85
hashFunction · 0.85
transposeFunction · 0.85
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
tobytesMethod · 0.45

Tested by

no test coverage detected