Пример #1
0
def test_hash_from_dict():
    dicts = [{}, {0: 0}, {0: 1}, {1: 0}, {1: 1},
             {0: (0,)}, {0: [1]},
             {0: (0, 1)}, {0: [1, 0]},
         ]
    hashs = []
    for idx, d in enumerate(dicts):
        h = hash_from_dict(d)
        assert h not in hashs
        hashs.append(h)

    # List are not hashable. So they are transformed into tuple.
    assert hash_from_dict({0: (0,)}) == hash_from_dict({0: [0]})
Пример #2
0
def test_hash_from_dict():
    dicts = [
        {},
        {
            0: 0
        },
        {
            0: 1
        },
        {
            1: 0
        },
        {
            1: 1
        },
        {
            0: (0, )
        },
        {
            0: [1]
        },
        {
            0: (0, 1)
        },
        {
            0: [1, 0]
        },
    ]
    hashs = []
    for idx, d in enumerate(dicts):
        h = hash_from_dict(d)
        assert h not in hashs
        hashs.append(h)

    # List are not hashable. So they are transformed into tuple.
    assert hash_from_dict({0: (0, )}) == hash_from_dict({0: [0]})
Пример #3
0
 def __hash__(self):
     return (hash(type(self)) ^ hash(self.scalar_op)
             ^ hash_from_dict(self.inplace_pattern))
Пример #4
0
 def __hash__(self):
     return (hash(type(self)) ^ hash(self.scalar_op) ^
             hash_from_dict(self.inplace_pattern))