use super::stable_hash::{hash_edge_id, hash_id, hash_id_bytes, FNV_OFFSET_BASIS};
#[test]
fn test_hash_id_bytes_agrees_with_hash_id_on_ascii() {
assert_eq!(hash_id_bytes(b""), hash_id(""));
assert_eq!(hash_id_bytes(b"a"), hash_id("a"));
assert_eq!(hash_id_bytes(b"tenant:acme"), hash_id("tenant:acme"));
}
#[test]
fn test_hash_id_bytes_agrees_with_hash_id_on_multi_byte_utf8() {
for input in ["café", "日本語", "emoji:🚀", "mixed-Ünïcödé-42"] {
assert_eq!(
hash_id_bytes(input.as_bytes()),
hash_id(input),
"hash_id_bytes/hash_id disagree for {input:?}"
);
}
}
#[test]
fn test_hash_id_bytes_hashes_non_utf8_bytes() {
let bytes = [0xFFu8, 0x00, 0x89, 0x50, 0x4E, 0x47];
assert_eq!(hash_id_bytes(&bytes), hash_id_bytes(&bytes));
assert_ne!(hash_id_bytes(&bytes), hash_id_bytes(&bytes[1..]));
}
#[test]
fn test_hash_id_empty_equals_offset_basis() {
assert_eq!(hash_id(""), FNV_OFFSET_BASIS);
assert_eq!(hash_id(""), 0xcbf2_9ce4_8422_2325);
}
#[test]
fn test_hash_id_single_char_matches_reference() {
assert_eq!(hash_id("a"), 0xaf63_dc4c_8601_ec8c);
}
#[test]
fn test_hash_id_word_matches_reference() {
assert_eq!(hash_id("foobar"), 0x8594_4171_f739_67e8);
}
#[test]
fn test_hash_id_prefixed_key_matches_reference() {
assert_eq!(hash_id("tenant:acme"), 0x434a_088f_8b77_5207);
}
#[test]
fn test_hash_edge_id_zero_triple_matches_reference() {
assert_eq!(hash_edge_id(0, 0, ""), 0x8820_1fb9_60ff_6465);
}
#[test]
fn test_hash_edge_id_labeled_edge_matches_reference() {
assert_eq!(hash_edge_id(1, 2, "knows"), 0x083a_4358_f694_89c6);
}
#[test]
fn test_hash_edge_id_second_labeled_edge_matches_reference() {
assert_eq!(hash_edge_id(42, 7, "follows"), 0xca14_ae35_d9c6_9a62);
}
#[test]
fn test_hash_edge_id_is_order_sensitive() {
assert_ne!(hash_edge_id(1, 2, "knows"), hash_edge_id(2, 1, "knows"));
}
#[test]
fn test_hash_edge_id_label_affects_output() {
assert_ne!(hash_edge_id(1, 2, "knows"), hash_edge_id(1, 2, "likes"));
}