1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

hash.fnv1a: add fnv1a.sum64_bytes and fnv1a.sum32_bytes, add doc comments and tests

This commit is contained in:
Delyan Angelov
2021-12-29 11:27:26 +02:00
parent 9b8cf1ad37
commit 7c78bf9466
2 changed files with 55 additions and 7 deletions

View File

@@ -1,12 +1,29 @@
import hash.fnv1a
fn test_fnv1a() {
fn test_fnv1a_sum32() {
$if windows {
return
}
ahash := '10bc2abf'
a := 'apple'
b := fnv1a.sum32_string(a)
c := fnv1a.sum32(a.bytes())
d := unsafe { fnv1a.sum32_bytes(a.str, a.len) }
assert b.hex() == ahash
assert c.hex() == ahash
assert d.hex() == ahash
}
fn test_fnv1a_sum64() {
$if windows {
return
}
a := 'apple'
ahash := 'f74a62a458befdbf'
b := fnv1a.sum64_string(a)
c := fnv1a.sum64(a.bytes())
assert b.hex() == 'f74a62a458befdbf'
assert c.hex() == 'f74a62a458befdbf'
d := unsafe { fnv1a.sum64_bytes(a.str, a.len) }
assert b.hex() == ahash
assert c.hex() == ahash
assert d.hex() == ahash
}