Skip to content

Commit

Permalink
fix: ensure conversion is unsigned (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Apr 4, 2023
1 parent d6a1d73 commit 7389859
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
exclude = docs
max-line-length = 88
max-line-length = 188
2 changes: 1 addition & 1 deletion src/fnv_hash_fast/_fnv_impl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cython


cdef extern from "fnv_wrapper.h":
int _cpp_fnv1a_32(string data)
cython.uint _cpp_fnv1a_32(string data)

def _fnv1a_32(data: bytes) -> int:
return _cpp_fnv1a_32(data)
30 changes: 30 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,33 @@ def test_fnvhash_fnv1a_32():
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
)

0 comments on commit 7389859

Please sign in to comment.