File: test_init.py

package info (click to toggle)
python-fnv-hash-fast 0.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: python: 101; ansic: 9; javascript: 8; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fnvhash import fnv1a_32 as fnvhash_fnv1a_32

from fnv_hash_fast import fnv1a_32


def test_fnv1a_32():
    assert fnv1a_32(b"hello") == 1335831723
    assert fnv1a_32(b"goodbye") == 1188507472
    assert fnv1a_32(b"goodbye" * 4096) == 386067909


def test_fnvhash_fnv1a_32():
    for test_data in (
        b"hello",
        b"goodbye",
        b"goodbye" * 4096,
    ):
        assert fnv1a_32(test_data) == fnvhash_fnv1a_32(test_data)


def test_ha_compat_hash_fnvhash():
    assert (
        fnvhash_fnv1a_32(
            b'{"action":"update","entity_id":"update.twizzy_software_update","changes":{"entity_category":"diagnostic","supported_features":4}}'
        )
        == 1724124935
    )
    assert (
        fnvhash_fnv1a_32(
            b'{"domain":"input_text","service":"set_value","service_data":{"value":1680573390.26158,"entity_id":["input_text.last_motion_in_house"]}}'
        )
        == 2209002508
    )


def test_ha_compat_hash():
    assert (
        fnv1a_32(
            b'{"action":"update","entity_id":"update.twizzy_software_update","changes":{"entity_category":"diagnostic","supported_features":4}}'
        )
        == 1724124935
    )
    assert (
        fnv1a_32(
            b'{"domain":"input_text","service":"set_value","service_data":{"value":1680573390.26158,"entity_id":["input_text.last_motion_in_house"]}}'
        )
        == 2209002508
    )